-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[CSHARP][GENERICHOST] Fix JSON validation for non-required nullable reference types #23189
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,9 +276,18 @@ | |
| {{/allVars}} | ||
| {{#allVars}} | ||
| {{^isNullable}} | ||
| {{#required}} | ||
| if ({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.IsSet && {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.Value == null) | ||
| throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}), "Property is not nullable for class {{classname}}."); | ||
|
|
||
| {{/required}} | ||
| {{^required}} | ||
| {{^nrt}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want to use vendorExtensions.x-is-nullable-type which is true for any value type or if nrt is enabled. Also, should ^ be # instead? |
||
| if ({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.IsSet && {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.Value == null) | ||
| throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}), "Property is not nullable for class {{classname}}."); | ||
|
|
||
| {{/nrt}} | ||
| {{/required}} | ||
| {{/isNullable}} | ||
| {{/allVars}} | ||
| {{^vendorExtensions.x-duplicated-data-type}} | ||
|
|
@@ -430,9 +439,18 @@ | |
| {{^isDiscriminator}} | ||
| {{^isNullable}} | ||
| {{#vendorExtensions.x-is-reference-type}} | ||
| if ({{^required}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.IsSet && {{/required}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null) | ||
| {{#required}} | ||
| if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null) | ||
| throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}), "Property is required for class {{classname}}."); | ||
|
|
||
| {{/required}} | ||
| {{^required}} | ||
| {{^nrt}} | ||
| if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.IsSet && {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null) | ||
| throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}), "Property is required for class {{classname}}."); | ||
|
|
||
| {{/nrt}} | ||
| {{/required}} | ||
| {{/vendorExtensions.x-is-reference-type}} | ||
| {{/isNullable}} | ||
| {{/isDiscriminator}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,26 @@ else | |
| writer.WriteNull("{{baseName}}"); | ||
| {{/isNullable}} | ||
| {{^isNullable}} | ||
| {{^required}} | ||
| {{#nrt}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace nrt and x-is-value-type with vendorExtensions.x-is-nullable-type |
||
| {{#vendorExtensions.x-is-value-type}} | ||
| if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value != null) | ||
| {{#lambda.paste}}{{/lambda.paste}} | ||
| else | ||
| writer.WriteNull("{{baseName}}"); | ||
| {{/vendorExtensions.x-is-value-type}} | ||
| {{^vendorExtensions.x-is-value-type}} | ||
| {{#lambda.paste}} | ||
| {{/lambda.paste}} | ||
| {{/vendorExtensions.x-is-value-type}} | ||
| {{/nrt}} | ||
| {{^nrt}} | ||
| {{#lambda.paste}} | ||
| {{/lambda.paste}} | ||
| {{/nrt}} | ||
| {{/required}} | ||
| {{#required}} | ||
| {{#lambda.paste}} | ||
| {{/lambda.paste}} | ||
| {{/required}} | ||
| {{/isNullable}} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If its required, I don't think it is an option, so the IsSet can go away. Curious that the samples could build.