Open OculiViridi opened 5 years ago
Did you switch from WebApiToSwaggerGenerator to AspNetCoreToSwaggerGenerator?
I think the option RequireParametersWithoutDefault is enabled and should be disabled to use ASP.NET Core's API explorer reported required info only...
I think the option RequireParametersWithoutDefault is enabled and should be disabled to use ASP.NET Core's API explorer reported required info only...
@RSuter Where this parameter is located? I've no option currently set on my code about it.
AddSwaggerDocument(settings => settings.RequireParametersWithoutDefault ...)
Questions:
- What .net core version are you using?
.NET Core 2.1 (2.1.6)
- Is compatibility set to 2.1 in startup.cs?
Yes, .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
- Is this openapi3 or swagger2?
Swagger 2. I'm using those methods:
services.AddSwaggerDocument()
,app.UseSwagger()
app.UseSwaggerUi3()
@RSuter Just to be more clear I'm pointing out what I exactly need from NSwag:
[ApiVersion("x.0")]
attribute on my controllers.https://api.mydomain.com/control/swagger
--> https://myservername:5001/swagger
So, I need to put together all the necessary configuration... I'm now trying to convert the old (v11.20.1) configuration into the new (v12.0.0) one, but it's not so straightforward... Maybe I can open a new Issue or post all the code here?
Nginx/reverse proxy users, please review: #2196
I have a similar issue using .NET Core 2.2 and NSwag 12.3.0:
In Startup, I call AddSwaggerDocument()
, (but also tried AddOpenAPIDocument()
).
My CompatibilityVersion
is set to 2.2, but setting it to 2.1 doesn't help either.
In my controller, I have the following code:
[HttpGet("{id?}")] public async Task<ActionResult<TEntityDto>> GetUpdateModel(int? id)
The generated Swagger.json defines the id
parameter as required, so obviously Swagger UI and the generated code think the parameter is required.
With GetUpdateModel(int? id)
I think the parameter is required but nullable...
I think you need to use GetUpdateModel(int? id = null)
so that it is reported as optional by the ASP.NET Core api explorer.
After updating NSwag from v11.20.1 to 12.0.0, optional method's parameters are now detected as required.
This is the same code for both versions:
This is what I get with v11.20.1 (correct)
This is what I get now with v12.0.0 (wrong)