Replies: 1 comment
-
Did you try either [BindRequired] or [Required] as outlined in https://stackoverflow.com/questions/43895485/required-query-string-parameter-in-asp-net-core? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are using NSwag to generate an OpenAPI.json file for our .NET 8 Minimal API. This file is then used by https://openapi-ts.dev/ (openapi-typescript) to generate a TypeScript definition.
Our issue is that the OpenAPI contract is marking all properties as optional, causing the TypeScript contract to mark them as allowing
undefined
(missing). We want the TypeScript contract to accurately reflect the .NET contract.Here is our setup:
Program.cs:
Api.csproj:
This is how the generated Api.json looks like:
In the current setup without the
required
property, this is the types that OpenAPI Typescript is generating (notice thatid?
andname?
is nullable):But if the required property is set, this is what we will get :
We believe this might be a bug in NSwag where the required property is not set. In .NET, optional properties can be null, but they are still present. Am I missing something?
Note that we use OpenApiGenerateDocumentsOnBuild in the .csproj file. If a NSwag configuration is needed, how can we use it with OpenApiGenerateDocumentsOnBuild?
Beta Was this translation helpful? Give feedback.
All reactions