Skip to content

Add feature to generate strict types (without useless undefined|null)#147

Open
ivan-luxoft wants to merge 4 commits intoLuxoft:masterfrom
ivan-luxoft:try-to-avoid-undefined
Open

Add feature to generate strict types (without useless undefined|null)#147
ivan-luxoft wants to merge 4 commits intoLuxoft:masterfrom
ivan-luxoft:try-to-avoid-undefined

Conversation

@ivan-luxoft
Copy link

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

// 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,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to fix, sometimes backend can mark as required nullable fields

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
image

may be it can be resolved by additional custom schema filter, but I'd like to avoid that.
Need an extra investigation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked a schema filter to exclude nullable from required, it have been worked
Luxoft/bss-platform#23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants