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 spec shows all fields for the models as nullable. #361

Open
JulesImmerzeel opened this issue Jan 4, 2023 · 3 comments
Open

OpenApi spec shows all fields for the models as nullable. #361

JulesImmerzeel opened this issue Jan 4, 2023 · 3 comments
Labels
documentation Documentation, comments, guides, info etc.

Comments

@JulesImmerzeel
Copy link

Hey all, I am new to this package. I like it, but there is one inconvience I have noticed so far.

image
All fields are marked as nullable as you can see in this screenshot (this is just one example it's for all). One way to resolve this is by adding the RequiredAttribute to the properties that are not nullable.

The reason why it might be important to fix this:

  • It gives better documentation about the models for frontend development.
  • In my particular case I am using a generator in the frontend to generate TypeScript classes based on the OpenApi file. So all my typescript classes would have nullable fields even though they should never be null.

Is there a reason why [Required] is not used or just something that was not taken into consideration?
If the later is the case I could have a look into it, as I am quiet familiar with WebAuthn specifications.

@abergs abergs added the documentation Documentation, comments, guides, info etc. label Jan 16, 2023
@abergs
Copy link
Collaborator

abergs commented Jan 16, 2023

Hey Jules,
Thanks for the issue. You're welcome to submit a PR adding the attribute 👍

@Regenhardt
Copy link
Contributor

Regenhardt commented Jan 27, 2023

Bit off-topic but: Do you really need typescript classes @JulesImmerzeel ? All these types are available as native browser interfaces already:
Overview: https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API
Page for PublicKeyCredentialRequestOptions (as an example): https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialRequestOptions

On-topic: Would be nice to have required properties on the OpenAPI spec of course.

@Regenhardt
Copy link
Contributor

Regenhardt commented Feb 6, 2023

Could also enable nullable references, letting swagger read those:
grafik

Edit: You can tell SwaggerGen to read nullable references by setting c.SchemaGeneratorOptions.SupportNonNullableReferenceTypes to true.

Edit2: Turns out this one was luck: It reads the properties in the screenshot as required because of the [JsonConstructor] offering those parameters. Others are still shown as nullable, but would show as required if the project were built with nullable references enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation, comments, guides, info etc.
Projects
None yet
Development

No branches or pull requests

3 participants