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

Explicit #nullable enable introduced v1.2.0 produces excessive warnings #451

Closed
christianhelle opened this issue Sep 2, 2024 Discussed in #449 · 0 comments · Fixed by #452
Closed

Explicit #nullable enable introduced v1.2.0 produces excessive warnings #451

christianhelle opened this issue Sep 2, 2024 Discussed in #449 · 0 comments · Fixed by #452
Assignees
Labels
bug Something isn't working

Comments

@christianhelle
Copy link
Owner

Discussed in #449

Originally posted by Jappinen August 29, 2024
Hello,

After updating from 1.1.3 to 1.2.0 my build output lit up like a Xmas tree with nullable property warnings. Take the simples possible Petstore sample for example (on fresh .NET 8 console project with everything as default as Rider sets them up):

{
  "openApiPath": "https://petstore3.swagger.io/api/v3/openapi.yaml"
}

petstore.g.cs(626,23): Warning CS8618 : Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

...and continues for 27 lines. The culprit is the new "#nullable enable" line after usings and before namespace that was previously behind a flag (b13015b).

After a little bit of digging I found you discussed this on #435 and as per the docs (the blue box at the end of chapter) for generated code you really need to have that pragma in place to get the benefits.

In order to tell the underlying NSwag that you want nullables you need to opt-in: RicoSuter/NSwag#2435 (comment)

And like magic all my problems went away with the this:

{
  "openApiPath": "https://petstore3.swagger.io/api/v3/openapi.yaml",
  "codeGeneratorSettings": {
    "generateNullableReferenceTypes": true
  }
}

So I guess what I'm trying to ask is shouldn't that be the default setting from now on or am I missing something blatantly obvious?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant