Add feature to generate strict types (without useless undefined|null)#147
Open
ivan-luxoft wants to merge 4 commits intoLuxoft:masterfrom
Open
Add feature to generate strict types (without useless undefined|null)#147ivan-luxoft wants to merge 4 commits intoLuxoft:masterfrom
ivan-luxoft wants to merge 4 commits intoLuxoft:masterfrom
Conversation
…atory, also remove partial/undefied from generated types
ivan-luxoft
commented
Mar 20, 2025
| // TODO: by design object model in strong typed (c#) languages can combine isRequired=true and isNullable=true, | ||
| // but it's a strange for UI contract, so any required field will count as Non-Nullable | ||
| isNullable: !param.isRequired && param.isNullable, | ||
| isOptional: !param.isRequired, |
Author
There was a problem hiding this comment.
need to fix, sometimes backend can mark as required nullable fields
Author
There was a problem hiding this comment.
There is a big problem, Swashbuckle can add required flag to non-nullable property (with the additional option), but it also use the same flag if property has required modifier (C#), even when that nullable.
So I have a case when nullable and non nullable property has required flag, and OpenApi spec doesnt have different between them:

may be it can be resolved by additional custom schema filter, but I'd like to avoid that.
Need an extra investigation
Author
There was a problem hiding this comment.
I've checked a schema filter to exclude nullable from required, it have been worked
Luxoft/bss-platform#23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Swashbuckle (SwaggerGenOptions) has option NonNullableReferenceTypesAsRequired (domaindrivendev/Swashbuckle.AspNetCore#2036) that mark all non-nullable fields as required, so gengen can use it information to build more typed model without redundant undefined/nullable