RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

Fix bug that C# property not nullable when specified via reference #1682

Closed markm77 closed 2 months ago

markm77 commented 5 months ago

This fixes a bug that has been found using both NSwag and NJsonSchema. Essentially when GenerateNullableReferenceTypes and GenerateOptionalPropertiesAsNullable are both true, these settings are not respected for an optional object property provided via a reference ($ref) and the resulting C# property is not optional.

I believe this may solve multiple issues raised in both NSwag and NJsonSchema repos, for example: https://github.com/RicoSuter/NJsonSchema/issues/1305 https://github.com/RicoSuter/NSwag/issues/4280 (maybe?)

I've added a test that reproduces the problem and passes with the fix.

markm77 commented 4 months ago

Hi @RicoSuter , is there anything I can do to get this fix into the repo? It's quite a pain to use a local version of NSwag every time to avoid this bug.

markm77 commented 2 months ago

Thanks for merging @RicoSuter !