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

feat: option to use c# 11 required keyword for required properties #1711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alpoi-x
Copy link

@alpoi-x alpoi-x commented Jun 30, 2024

This PR adds a UseRequiredKeyword option to the C# code generator. This will use the required modifier, added in C#11, for any properties that are required in the json schema.

@alpoi-x
Copy link
Author

alpoi-x commented Jul 29, 2024

@RicoSuter ping!

@amis92
Copy link

amis92 commented Jul 29, 2024

I'd love this feature!

I was just looking how to do that myself. I do have an additional require-ment (jk), namely I want nullable properties (both structs and NRTs) to not have that keyword. I see that there's already a similar setting GenerateOptionalPropertiesAsNullable - would it be possible to also have a SkipRequiredKeywordOnNullableProperties with preferably better name, or an opposite of it? Pretty pretty please...

@alpoi-x
Copy link
Author

alpoi-x commented Jul 29, 2024

@amis92 Isn't this already the case, given that a property is only treated as nullable if GenerateOptionalPropertiesAsNullable is enabled and the property is not required?

/// <summary>Gets a value indicating whether the property is nullable.</summary>
public override bool IsNullable => (_settings.GenerateOptionalPropertiesAsNullable && !_property.IsRequired) || base.IsNullable;

@amis92
Copy link

amis92 commented Jul 29, 2024

That, or the null is allowed by type JSON Schema keyword.

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