Template in ASP.NET Core results in wrong swagger
See original GitHub issueThis code, in different files
public class PagedResponse<T> : PagedResultBase
where T : class
{
public ICollection<T> Results { get; set; }
public PagedResponse()
{
Results = new List<T>();
}
}
public sealed class SingleResponse
{
Guid SomeInfo;
}
[HttpPost]
public Task<PagedResponse<SingleResponse>> Api([FromBody] PagedRequest request)
{
// return the Item ...
}
results in the following swagger
{
"x-generator": "NSwag v11.16.1.0 (NJsonSchema v9.10.41.0 (Newtonsoft.Json v9.0.0.0))",
"swagger": "2.0",
"info": {
"title": "My Title",
"version": "1.0.0"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/api/v0/my/api": {
"post": {
"tags": [
"My"
],
"operationId": "my_api",
"parameters": [
{
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PagedRequest"
},
"x-nullable": true
}
],
"responses": {
"200": {
"x-nullable": true,
"description": "",
"schema": {
"$ref": "#/definitions/PagedResponseOfSingleResponse"
}
}
}
}
}
},
"definitions": {
"PagedRequest": {
"type": "object",
"additionalProperties": false,
"required": [
"page",
"pageSize"
],
"properties": {
"id": {
"type": "string",
"format": "guid"
},
"page": {
"type": "integer",
"format": "int32"
},
"pageSize": {
"type": "integer",
"format": "int32"
}
}
},
"PagedResponseOfSingleResponse": {
"type": "object",
"additionalProperties": false,
"properties": {
"results": {
"type": "array",
"items": {
"$ref": "#/definitions/SingleResponse"
}
}
},
"allOf": [
{
"$ref": "#/definitions/PagedResultBase"
}
]
},
"SingleResponse": {
"type": "object",
"additionalProperties": false,
"required": [
"someInfo"
],
"properties": {
"someInfo": {
"type": "string",
"format": "guid"
}
}
},
"PagedResultBase": {
"type": "object",
"x-abstract": true,
"additionalProperties": false,
"required": [
"currentPage",
"pageSize"
],
"properties": {
"currentPage": {
"type": "integer",
"format": "int32"
},
"pageSize": {
"type": "integer",
"format": "int32"
}
}
}
}
}
The part of PagedResponseOfSingleResponse is wrong and results in an empty Model if parsed by the swagger parse (apart from objects from PagedResultBase) and should be:
"PagedResponseOfSingleResponse": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/PagedResultBase"
},
{
"additionalProperties": false,
"properties": {
"results": {
"type": "array",
"items": {
"$ref": "#/definitions/SingleResponse"
}
}
}
}
]
}
which results in a correct model
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
ASP.NET CORE Web API with Swagger produces wrong ...
This code snippets are showing a Brand from my Model. How can I fix it so that Swagger takes the property names as...
Read more >Handle errors in ASP.NET Core web APIs
Show 2 more. This article describes how to handle errors and customize error handling with ASP.NET Core web APIs.
Read more >Mastering Web APIs with Swagger, ApiExplorer and NSwag
Mastering External Web API's in ASP.Net Core and ABP with Swagger, ApiExplorer, and NSwag. How to expose a second Web API in Swagger...
Read more >Angular WebAPI Project using .NET Core gets '404 Not ...
NET Core gets '404 Not Found' or runs on wrong port. I've got an Angular application that runs using .NET Core in a...
Read more >Handling errors in ASP.NET Core Web API - DevTrends
Handling errors in an ASP.NET Core Web API. This post looks at the best ways to handle exceptions, validation and other invalid requests...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed in v11.20.0
Created a PR with current attempt to this: https://github.com/RSuter/NJsonSchema/pull/733