Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenApi generation creates NullableOf version of structs when null is allowed? #59056

Open
Markz878 opened this issue Nov 19, 2024 · 2 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi

Comments

@Markz878
Copy link

Markz878 commented Nov 19, 2024

Not sure if this is a question, bug report or API proposal, but I was pretty surprised when I tried to switch from Swagger to .NET 9 OpenApi generation, and saw that it generates these NullableOfXXX versions of structs if the API has any endpoints where the struct is nullable in input or output objects. What is the purpose of them?

This makes it harder to migrate from Swagger api generation to this, because we have auto-generated the Typescript schema objects and this would need a lot of changes in the app's TS signatures.

I'm not an OpenApi expert, but couldn't this be handled by using oneOf or anyOf?
Or can this be somehow disabled using the OpenApi configuration? This doesn't happen with classes, why are structs handled differently?

@Markz878 Markz878 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Nov 19, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Nov 19, 2024
@gfoidl gfoidl added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Nov 19, 2024
@Atulin
Copy link

Atulin commented Nov 21, 2024

I'm having the same issue. Switching from Swagger generated a bunch of NullableOf, IEnumerableOf, DictionaryOf and other types of this kind, instead of having them inlined. The worst offender are probably enums and collections of primitives. I really don't need NullableOfMyEnum and IEnumerableOfInt64 when just { "$ref": "#/components/schemas/MyEnum", "nullable": true } would suffice.

@ClementCHA
Copy link

I'm also having the same issue. Fun part is that, if a model is using nullable Propriety AND an other model using the same propriety but non nullable this time, it will add it twice in the json as NullableOfProperty & Property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi
Projects
None yet
Development

No branches or pull requests

4 participants