Open ddaspit opened 1 year ago
I can confirm this issue persists in version 13.20.0 (latest stable as of now) and would like to see it fixed.
I just encountered the same issue. It's a big deal, isn't it? You are entirely blocked by using NSwag when you have optional fields using [FromForm]
.
Parameters in a controller action that are marked with the attributes
[FromForm]
and[BindRequired]
are not properly generated in OpenAPI 3.0. The parameters should be added to therequired
section of the body schema. This works with Swagger 2.0.In addition, even if the parameters are marked correctly as required in OpenAPI 3.0, the C# client is not generated correctly when
generateOptionalParameters
is set totrue
. Required form parameters are treated as optional and assigned a default value.Steps to reproduce:
Setup NSwag to use OpenAPI 3.0 in Startup.cs:
Create a controller class with a required form parameter:
The generated OpenAPI spec is:
The expected spec is:
If you use the expected spec and generate a C# client using
generateOptionalParameters
, the generated code is:The expected code is: