[csharp][generichost] Implement not required nullable properties (#16810)

* init

* fixed read and write

* completed changes using latest-nrt sample

* fixed all samples

* add null check on write, change on exception

* resolved conflicts

* build samples

* added backing property for not required properties

* more not required and nullable hanlding improvements

* revert sample updates for a merge master

* revert sample updates for a merge master

* sample build is working, need to remove warnings

* fixed warnings in .net 7 with nrt

* fixed manual tests

* fixed all samples

* fix npe

* removed debugging lines

* revert changes to unused file

* removed unused lambdas

* fix a serialization bug

* make option a hidden property

* updated documentation

* improved parameter ordering
This commit is contained in:
devhl-labs 2023-11-12 21:16:35 -05:00 committed by GitHub
parent 2f655f1a9c
commit 7e529926a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
490 changed files with 46093 additions and 9072 deletions

View File

@ -418,11 +418,14 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
@Override @Override
protected ImmutableMap.Builder<String, Lambda> addMustacheLambdas() { protected ImmutableMap.Builder<String, Lambda> addMustacheLambdas() {
CopyLambda copyLambda = new CopyLambda();
return super.addMustacheLambdas() return super.addMustacheLambdas()
.put("camelcase_param", new CamelCaseLambda().generator(this).escapeAsParamName(true)) .put("camelcase_param", new CamelCaseLambda().generator(this).escapeAsParamName(true))
.put("required", new RequiredParameterLambda()) .put("required", new RequiredParameterLambda())
.put("optional", new OptionalParameterLambda().generator(this)) .put("optional", new OptionalParameterLambda().generator(this))
.put("joinWithComma", new JoinWithCommaLambda()) .put("joinWithComma", new JoinWithCommaLambda())
.put("joinWithAmpersand", new JoinWithCommaLambda(true, " ", " && "))
.put("joinLinesWithComma", new JoinWithCommaLambda(false, "\n", ",\n")) .put("joinLinesWithComma", new JoinWithCommaLambda(false, "\n", ",\n"))
.put("joinConditions", new JoinWithCommaLambda(true, " ", " && ")) .put("joinConditions", new JoinWithCommaLambda(true, " ", " && "))
.put("trimLineBreaks", new TrimLineBreaksLambda()) .put("trimLineBreaks", new TrimLineBreaksLambda())
@ -430,9 +433,13 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
.put("trimTrailing", new TrimTrailingWhiteSpaceLambda(false)) .put("trimTrailing", new TrimTrailingWhiteSpaceLambda(false))
.put("first", new FirstLambda(" ")) .put("first", new FirstLambda(" "))
.put("firstDot", new FirstLambda("\\.")) .put("firstDot", new FirstLambda("\\."))
.put("indent1", new IndentedLambda(4, " ", false, true))
.put("indent3", new IndentedLambda(12, " ", false, true)) .put("indent3", new IndentedLambda(12, " ", false, true))
.put("indent4", new IndentedLambda(16, " ", false, true)) .put("indent4", new IndentedLambda(16, " ", false, true))
.put("uniqueLinesWithNewLine", new UniqueLambda("\n", true)); .put("copy", copyLambda)
.put("paste", new PasteLambda(copyLambda, true, true, true, false))
.put("pasteOnce", new PasteLambda(copyLambda, true, true, true, true))
.put("pasteLine", new PasteLambda(copyLambda, true, true, false, false));
} }
@Override @Override

View File

@ -454,14 +454,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
Collections.sort(codegenModel.readWriteVars, propertyComparatorByName); Collections.sort(codegenModel.readWriteVars, propertyComparatorByName);
Collections.sort(codegenModel.parentVars, propertyComparatorByName); Collections.sort(codegenModel.parentVars, propertyComparatorByName);
Comparator<CodegenProperty> comparator = propertyComparatorByNullable.thenComparing(propertyComparatorByDefaultValue); Collections.sort(codegenModel.vars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.vars, comparator); Collections.sort(codegenModel.allVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.allVars, comparator); Collections.sort(codegenModel.requiredVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.requiredVars, comparator); Collections.sort(codegenModel.optionalVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.optionalVars, comparator); Collections.sort(codegenModel.readOnlyVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.readOnlyVars, comparator); Collections.sort(codegenModel.readWriteVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.readWriteVars, comparator); Collections.sort(codegenModel.parentVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.parentVars, comparator);
} }
return codegenModel; return codegenModel;
@ -474,24 +473,12 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
} }
}; };
public static Comparator<CodegenProperty> propertyComparatorByDefaultValue = new Comparator<CodegenProperty>() { public static Comparator<CodegenProperty> propertyComparatorByNotNullableRequiredNoDefault = new Comparator<CodegenProperty>() {
@Override @Override
public int compare(CodegenProperty one, CodegenProperty another) { public int compare(CodegenProperty one, CodegenProperty another) {
if ((one.defaultValue == null) == (another.defaultValue == null)) if (one.isNullable == another.isNullable && one.required == another.required && (one.defaultValue == null) == (another.defaultValue == null))
return 0; return 0;
else if (one.defaultValue == null) else if (!one.isNullable && one.required && one.defaultValue == null)
return -1;
else
return 1;
}
};
public static Comparator<CodegenProperty> propertyComparatorByNullable = new Comparator<CodegenProperty>() {
@Override
public int compare(CodegenProperty one, CodegenProperty another) {
if (one.isNullable == another.isNullable)
return 0;
else if (Boolean.FALSE.equals(one.isNullable))
return -1; return -1;
else else
return 1; return 1;

View File

@ -0,0 +1,48 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.templating.mustache;
import java.io.IOException;
import java.io.Writer;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template.Fragment;
/**
* Saves template text to be used later.
*
* Register:
* <pre>
* additionalProperties.put("copy", new CopyLambda());
* </pre>
*
* Use:
* <pre>
* {{#copy}}{{name}}{{/copy}}
* </pre>
*/
public class CopyLambda implements Mustache.Lambda {
public String savedContent;
public CopyLambda() {
}
@Override
public void execute(Fragment fragment, Writer writer) throws IOException {
savedContent = fragment.execute().stripTrailing();
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.templating.mustache;
import java.io.IOException;
import java.io.Writer;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template.Fragment;
/**
* Writes text that was previously saved.
*
* Register:
* <pre>
* additionalProperties.put("paste", new PasteLambda(copyLambda, true, true, true, false));
* </pre>
*
* Use:
* <pre>
* {{#paste}}{{/paste}}
* </pre>
*/
public class PasteLambda implements Mustache.Lambda {
private final CopyLambda copyLambda;
private final Boolean stripLeading;
private final Boolean stripTrailing;
private final Boolean endWithLineBreak;
private final Boolean clear;
public PasteLambda(CopyLambda copyLambda, Boolean stripLeading, Boolean stripTrailing, Boolean endWithLineBreak, boolean clear) {
this.copyLambda = copyLambda;
this.stripLeading = stripLeading;
this.stripTrailing = stripTrailing;
this.endWithLineBreak = endWithLineBreak;
this.clear = clear;
}
@Override
public void execute(Fragment fragment, Writer writer) throws IOException {
String content = this.copyLambda.savedContent;
if (content == null) {
return;
}
if (this.stripTrailing){
content = content.stripTrailing();
}
if (this.stripLeading) {
content = content.stripLeading();
}
if (this.endWithLineBreak && !content.endsWith("\n")){
content = content + "\n";
}
writer.write(content);
if (this.clear) {
this.copyLambda.savedContent = null;
}
}
}

View File

@ -1 +1 @@
{{#isNullable}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}{{/isNullable}} {{#lambda.first}}{{#isNullable}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{/required}}{{/lambda.first}}

View File

@ -38,7 +38,7 @@
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
{{#allVars}} {{#allVars}}
{{#isInnerEnum}}{{^isMap}}{{classname}}.{{/isMap}}{{/isInnerEnum}}{{{datatypeWithEnum}}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = default; Option<{{#isInnerEnum}}{{^isMap}}{{classname}}.{{/isMap}}{{/isInnerEnum}}{{{datatypeWithEnum}}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}> {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = default;
{{#-last}} {{#-last}}
{{/-last}} {{/-last}}
@ -167,39 +167,39 @@
{{^isMap}} {{^isMap}}
{{^isEnum}} {{^isEnum}}
{{^isUuid}} {{^isUuid}}
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.GetString(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.GetString(){{^isNullable}}{{nrt!}}{{/isNullable}});
{{/isUuid}} {{/isUuid}}
{{/isEnum}} {{/isEnum}}
{{/isMap}} {{/isMap}}
{{/isString}} {{/isString}}
{{#isBoolean}} {{#isBoolean}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.GetBoolean(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.GetBoolean());
{{/isBoolean}} {{/isBoolean}}
{{#isNumeric}} {{#isNumeric}}
{{^isEnum}} {{^isEnum}}
{{#isDouble}} {{#isDouble}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.GetDouble(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.GetDouble());
{{/isDouble}} {{/isDouble}}
{{#isDecimal}} {{#isDecimal}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.GetDecimal(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.GetDecimal());
{{/isDecimal}} {{/isDecimal}}
{{#isFloat}} {{#isFloat}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = (float)utf8JsonReader.GetDouble(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}(float)utf8JsonReader.GetDouble());
{{/isFloat}} {{/isFloat}}
{{#isLong}} {{#isLong}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int64(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int64());
{{/isLong}} {{/isLong}}
{{^isLong}} {{^isLong}}
{{^isFloat}} {{^isFloat}}
{{^isDecimal}} {{^isDecimal}}
{{^isDouble}} {{^isDouble}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32());
{{/isDouble}} {{/isDouble}}
{{/isDecimal}} {{/isDecimal}}
{{/isFloat}} {{/isFloat}}
@ -208,36 +208,34 @@
{{/isNumeric}} {{/isNumeric}}
{{#isDate}} {{#isDate}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
{{/isDate}} {{/isDate}}
{{#isDateTime}} {{#isDateTime}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
{{/isDateTime}} {{/isDateTime}}
{{#isEnum}} {{#isEnum}}
{{^isMap}} {{^isMap}}
{{#isNumeric}} {{#isNumeric}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = ({{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}})utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}({{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}})utf8JsonReader.Get{{#vendorExtensions.x-unsigned}}U{{/vendorExtensions.x-unsigned}}Int32());
{{/isNumeric}} {{/isNumeric}}
{{^isNumeric}} {{^isNumeric}}
string{{nrt?}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = utf8JsonReader.GetString(); string{{nrt?}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = utf8JsonReader.GetString();
{{^isInnerEnum}} {{^isInnerEnum}}
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue == null if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue != null)
? null {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}{{{datatypeWithEnum}}}ValueConverter.FromStringOrDefault({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue));
: {{{datatypeWithEnum}}}ValueConverter.FromStringOrDefault({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue);
{{/isInnerEnum}} {{/isInnerEnum}}
{{#isInnerEnum}} {{#isInnerEnum}}
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue == null if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue != null)
? null {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}{{classname}}.{{{datatypeWithEnum}}}FromStringOrDefault({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue));
: {{classname}}.{{{datatypeWithEnum}}}FromStringOrDefault({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue);
{{/isInnerEnum}} {{/isInnerEnum}}
{{/isNumeric}} {{/isNumeric}}
{{/isMap}} {{/isMap}}
{{/isEnum}} {{/isEnum}}
{{#isUuid}} {{#isUuid}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = utf8JsonReader.GetGuid(); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}utf8JsonReader.GetGuid());
{{/isUuid}} {{/isUuid}}
{{^isUuid}} {{^isUuid}}
{{^isEnum}} {{^isEnum}}
@ -247,7 +245,7 @@
{{^isDate}} {{^isDate}}
{{^isDateTime}} {{^isDateTime}}
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = JsonSerializer.Deserialize<{{{datatypeWithEnum}}}>(ref utf8JsonReader, jsonSerializerOptions); {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<{{{datatypeWithEnum}}}>(ref utf8JsonReader, jsonSerializerOptions){{^isNullable}}{{nrt!}}{{/isNullable}});
{{/isDateTime}} {{/isDateTime}}
{{/isDate}} {{/isDate}}
{{/isNumeric}} {{/isNumeric}}
@ -263,10 +261,17 @@
} }
} }
{{#allVars}}
{{#required}}
if (!{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}.IsSet)
throw new ArgumentException("Property is required for class {{classname}}.", nameof({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}));
{{/required}}
{{/allVars}}
{{#allVars}} {{#allVars}}
{{^isNullable}} {{^isNullable}}
if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} == null) if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}.IsSet && {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}.Value == null)
throw new ArgumentNullException(nameof({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}), "Property is required for class {{classname}}."); throw new ArgumentNullException(nameof({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}), "Property is not nullable for class {{classname}}.");
{{/isNullable}} {{/isNullable}}
{{/allVars}} {{/allVars}}
@ -275,7 +280,7 @@
{{#model.hasDiscriminatorWithNonEmptyMapping}} {{#model.hasDiscriminatorWithNonEmptyMapping}}
{{#mappedModels}} {{#mappedModels}}
if ({{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}} != null) if ({{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}} != null)
return new {{classname}}({{#lambda.joinWithComma}}{{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{#model.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/model.composedSchemas.anyOf}}{{#allVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/allVars}}{{/lambda.joinWithComma}}); return new {{classname}}({{#lambda.joinWithComma}}{{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{#model.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/model.composedSchemas.anyOf}}{{#allVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#required}}.Value{{nrt!}}{{^isNullable}}{{#vendorExtensions.x-is-value-type}}.Value{{/vendorExtensions.x-is-value-type}}{{/isNullable}}{{/required}} {{/allVars}}{{/lambda.joinWithComma}});
{{#-last}} {{#-last}}
throw new JsonException(); throw new JsonException();
@ -284,13 +289,23 @@
{{/model.hasDiscriminatorWithNonEmptyMapping}} {{/model.hasDiscriminatorWithNonEmptyMapping}}
{{/model.discriminator}} {{/model.discriminator}}
{{^composedSchemas.oneOf}} {{^composedSchemas.oneOf}}
return new {{classname}}({{#lambda.joinWithComma}}{{#model.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/model.composedSchemas.anyOf}}{{#allVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/allVars}}{{/lambda.joinWithComma}}); {{^required}}
{{#model.composedSchemas.anyOf}}
Option<{{baseType}}{{>NullConditionalProperty}}> {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}}ParsedValue = {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}} == null
? default
: new Option<{{baseType}}{{>NullConditionalProperty}}>({{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}});
{{/model.composedSchemas.anyOf}}
{{#-last}}
{{/-last}}
{{/required}}
return new {{classname}}({{#lambda.joinWithComma}}{{#model.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}}ParsedValue{{#required}}.Value{{^isNullable}}{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{nrt!}}{{/vendorExtensions.x-is-value-type}}{{/isNullable}}{{/required}} {{/model.composedSchemas.anyOf}}{{#allVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#required}}.Value{{nrt!}}{{^isNullable}}{{#vendorExtensions.x-is-value-type}}.Value{{nrt!}}{{/vendorExtensions.x-is-value-type}}{{/isNullable}}{{/required}} {{/allVars}}{{/lambda.joinWithComma}});
{{/composedSchemas.oneOf}} {{/composedSchemas.oneOf}}
{{^model.discriminator}} {{^model.discriminator}}
{{#composedSchemas}} {{#composedSchemas}}
{{#oneOf}} {{#oneOf}}
if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} != null) if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} != null)
return new {{classname}}({{#lambda.joinWithComma}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{#model.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/model.composedSchemas.anyOf}}{{#allVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/allVars}}{{/lambda.joinWithComma}}); return new {{classname}}({{#lambda.joinWithComma}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{#model.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#vendorExtensions.x-is-value-type}}{{^isNullable}}.Value{{/isNullable}}{{/vendorExtensions.x-is-value-type}} {{/model.composedSchemas.anyOf}}{{#allVars}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#required}}ParsedValue{{/required}} {{/allVars}}{{/lambda.joinWithComma}});
{{#-last}} {{#-last}}
throw new JsonException(); throw new JsonException();
@ -328,10 +343,10 @@
{{^model.discriminator}} {{^model.discriminator}}
{{#composedSchemas}} {{#composedSchemas}}
{{#anyOf}} {{#anyOf}}
if ({{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}} != null) if ({{#lambda.joinWithAmpersand}}{{^required}}{{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}}Option.IsSet {{/required}}{{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}}{{^required}}Option.Value{{/required}} != null{{/lambda.joinWithAmpersand}})
{ {
{{datatypeWithEnum}}JsonConverter {{datatypeWithEnum}}JsonConverter = ({{datatypeWithEnum}}JsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert({{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}}.GetType())); {{datatypeWithEnum}}JsonConverter {{datatypeWithEnum}}JsonConverter = ({{datatypeWithEnum}}JsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert({{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}}{{^required}}Option.Value{{/required}}.GetType()));
{{datatypeWithEnum}}JsonConverter.WriteProperties(ref writer, {{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}}, jsonSerializerOptions); {{datatypeWithEnum}}JsonConverter.WriteProperties(ref writer, {{#lambda.camelcase_param}}{{model.classname}}{{/lambda.camelcase_param}}.{{datatypeWithEnum}}{{^required}}Option.Value{{/required}}, jsonSerializerOptions);
} }
{{/anyOf}} {{/anyOf}}
@ -354,78 +369,76 @@
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#lambda.trimLineBreaks}} {{#lambda.trimLineBreaks}}
{{#allVars}} {{#allVars}}
{{^isNullable}}
{{#vendorExtensions.x-is-reference-type}}
if ({{^required}}{{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option.IsSet && {{/required}}{{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} == null)
throw new ArgumentNullException(nameof({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}), "Property is required for class {{classname}}.");
{{/vendorExtensions.x-is-reference-type}}
{{/isNullable}}
{{/allVars}}
{{#allVars}}
{{#isString}} {{#isString}}
{{^isMap}} {{^isMap}}
{{^isEnum}} {{^isEnum}}
{{^isUuid}} {{^isUuid}}
{{#lambda.copy}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}); writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}});
{{/lambda.copy}}
{{#lambda.indent3}}
{{>WriteProperty}}
{{/lambda.indent3}}
{{/isUuid}} {{/isUuid}}
{{/isEnum}} {{/isEnum}}
{{/isMap}} {{/isMap}}
{{/isString}} {{/isString}}
{{#isBoolean}} {{#isBoolean}}
{{#isNullable}} {{#lambda.copy}}
writer.WriteBoolean("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} != null) {{/lambda.copy}}
writer.WriteBoolean("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.Value); {{#lambda.indent3}}
else {{>WriteProperty}}
writer.WriteNull("{{baseName}}"); {{/lambda.indent3}}
{{/isNullable}}
{{^isNullable}}
writer.WriteBoolean("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}});
{{/isNullable}}
{{/isBoolean}} {{/isBoolean}}
{{^isEnum}} {{^isEnum}}
{{#isNumeric}} {{#isNumeric}}
{{#isNullable}} {{#lambda.copy}}
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} != null) {{/lambda.copy}}
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.Value); {{#lambda.indent3}}
else {{>WriteProperty}}
writer.WriteNull("{{baseName}}"); {{/lambda.indent3}}
{{/isNullable}}
{{^isNullable}}
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}});
{{/isNullable}}
{{/isNumeric}} {{/isNumeric}}
{{/isEnum}} {{/isEnum}}
{{#isDate}} {{#isDate}}
{{#isNullable}} {{#lambda.copy}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}.ToString({{name}}Format));
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} != null) {{/lambda.copy}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.Value.ToString({{name}}Format)); {{#lambda.indent3}}
else {{>WriteProperty}}
writer.WriteNull("{{baseName}}"); {{/lambda.indent3}}
{{/isNullable}}
{{^isNullable}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.ToString({{name}}Format));
{{/isNullable}}
{{/isDate}} {{/isDate}}
{{#isDateTime}} {{#isDateTime}}
{{#isNullable}} {{#lambda.copy}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}.ToString({{name}}Format));
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} != null) {{/lambda.copy}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.Value.ToString({{name}}Format)); {{#lambda.indent3}}
else {{>WriteProperty}}
writer.WriteNull("{{baseName}}"); {{/lambda.indent3}}
{{/isNullable}}
{{^isNullable}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.ToString({{name}}Format));
{{/isNullable}}
{{/isDateTime}} {{/isDateTime}}
{{#isEnum}} {{#isEnum}}
{{#isNumeric}} {{#isNumeric}}
writer.WriteNumber("{{baseName}}", {{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}})); {{#lambda.copy}}
writer.WriteNumber("{{baseName}}", {{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}));
{{/lambda.copy}}
{{#lambda.indent3}}
{{>WriteProperty}}
{{/lambda.indent3}}
{{/isNumeric}} {{/isNumeric}}
{{^isMap}} {{^isMap}}
{{^isNumeric}} {{^isNumeric}}
{{#isInnerEnum}} {{#isInnerEnum}}
var {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = {{classname}}.{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}{{nrt!}}.Value{{/isNullable}}{{/required}});
var {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = {{classname}}.{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}});
if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue != null) if ({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue != null)
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue); writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue);
else else
@ -433,18 +446,21 @@
{{/isInnerEnum}} {{/isInnerEnum}}
{{^isInnerEnum}} {{^isInnerEnum}}
{{#lambda.copy}}
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue
{{/lambda.copy}}
{{#required}}
{{#isNullable}} {{#isNullable}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} == null) if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} == null)
writer.WriteNull("{{baseName}}"); writer.WriteNull("{{baseName}}");
else else
{ {
var {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{#isNullable}}.Value{{/isNullable}}); var {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.Value);
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
{{#-first}} {{#-first}}
{{#isString}} {{#isString}}
if ({{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue != null){{! we cant use name here because enumVar also has a name property, so use the camel case variant only as a work around }} if ({{#lambda.pasteLine}}{{/lambda.pasteLine}} != null){{! we cant use name here because enumVar also has a name property, so use the paste lambda instead }}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue); writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue);
else else
writer.WriteNull("{{baseName}}"); writer.WriteNull("{{baseName}}");
@ -456,44 +472,53 @@
{{/enumVars}} {{/enumVars}}
{{/allowableValues}} {{/allowableValues}}
} }
{{/isNullable}} {{/isNullable}}
{{^isNullable}} {{^isNullable}}
var {{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{#isNullable}}.Value{{/isNullable}}); var {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}});
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
{{#-first}} {{#-first}}
{{#isString}} {{#isString}}
writer.WriteString("{{baseName}}", {{#lambda.pasteLine}}{{/lambda.pasteLine}});
if ({{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue != null)
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue);
else
writer.WriteNull("{{baseName}}");
{{/isString}} {{/isString}}
{{^isString}} {{^isString}}
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_param}}{{nameInCamelCase}}{{/lambda.camelcase_param}}RawValue); writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_param}}{{#lambda.pasteLine}}{{/lambda.pasteLine}}{{/lambda.camelcase_param}}RawValue);
{{/isString}} {{/isString}}
{{/-first}} {{/-first}}
{{/enumVars}} {{/enumVars}}
{{/allowableValues}} {{/allowableValues}}
{{/isNullable}} {{/isNullable}}
{{/required}}
{{^required}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option.IsSet)
{{#isNullable}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option{{nrt!}}.Value != null)
{
var {{#lambda.pasteLine}}{{/lambda.pasteLine}} = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option.Value{{nrt!}}.Value);
writer.{{#lambda.first}}{{#allowableValues}}{{#enumVars}}{{#isString}}WriteString {{/isString}}{{^isString}}WriteNumber {{/isString}}{{/enumVars}}{{/allowableValues}}{{/lambda.first}}("{{baseName}}", {{#lambda.pasteLine}}{{/lambda.pasteLine}});
}
else
writer.WriteNull("{{baseName}}");
{{/isNullable}}
{{^isNullable}}
{
var {{#lambda.pasteLine}}{{/lambda.pasteLine}} = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{nrt!}}.Value);
writer.{{#lambda.first}}{{#allowableValues}}{{#enumVars}}{{#isString}}WriteString {{/isString}}{{^isString}}WriteNumber {{/isString}}{{/enumVars}}{{/allowableValues}}{{/lambda.first}}("{{baseName}}", {{#lambda.pasteLine}}{{/lambda.pasteLine}});
}
{{/isNullable}}
{{/required}}
{{/isInnerEnum}} {{/isInnerEnum}}
{{/isNumeric}} {{/isNumeric}}
{{/isMap}} {{/isMap}}
{{/isEnum}} {{/isEnum}}
{{#isUuid}} {{#isUuid}}
{{^isNullable}} {{#lambda.copy}}
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}); writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
{{/isNullable}} {{/lambda.copy}}
{{#isNullable}} {{#lambda.indent3}}
{{>WriteProperty}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} == null) {{/lambda.indent3}}
writer.WriteNull("{{baseName}}");
else
writer.WriteString("{{baseName}}", {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}.Value);
{{/isNullable}}
{{/isUuid}} {{/isUuid}}
{{^isUuid}} {{^isUuid}}
{{^isEnum}} {{^isEnum}}
@ -502,8 +527,39 @@
{{^isNumeric}} {{^isNumeric}}
{{^isDate}} {{^isDate}}
{{^isDateTime}} {{^isDateTime}}
{{#required}}
{{#isNullable}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}} != null)
{
writer.WritePropertyName("{{baseName}}");
JsonSerializer.Serialize(writer, {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}, jsonSerializerOptions);
}
else
writer.WriteNull("{{baseName}}");
{{/isNullable}}
{{^isNullable}}
writer.WritePropertyName("{{baseName}}"); writer.WritePropertyName("{{baseName}}");
JsonSerializer.Serialize(writer, {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}, jsonSerializerOptions); JsonSerializer.Serialize(writer, {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}, jsonSerializerOptions);
{{/isNullable}}
{{/required}}
{{^required}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option.IsSet)
{{#isNullable}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option.Value != null)
{
writer.WritePropertyName("{{baseName}}");
JsonSerializer.Serialize(writer, {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}, jsonSerializerOptions);
}
else
writer.WriteNull("{{baseName}}");
{{/isNullable}}
{{^isNullable}}
{
writer.WritePropertyName("{{baseName}}");
JsonSerializer.Serialize(writer, {{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}, jsonSerializerOptions);
}
{{/isNullable}}
{{/required}}
{{/isDateTime}} {{/isDateTime}}
{{/isDate}} {{/isDate}}
{{/isNumeric}} {{/isNumeric}}

View File

@ -1 +1 @@
{{#parentModel.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{parent}}{{/lambda.camelcase_param}}.{{#lambda.titlecase}}{{baseType}}{{#isArray}}{{{dataFormat}}}{{/isArray}}{{/lambda.titlecase}} {{/parentModel.composedSchemas.anyOf}}{{#allVars}}{{#isInherited}}{{^isNew}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{/isNew}}{{#isNew}}{{#isEnum}}{{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}){{/isEnum}}{{^isEnum}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}.ToString(){{/isEnum}}{{/isNew}} {{/isInherited}}{{/allVars}} {{#parentModel.composedSchemas.anyOf}}{{#lambda.camelcase_param}}{{parent}}{{/lambda.camelcase_param}}.{{#lambda.titlecase}}{{baseType}}{{#isArray}}{{{dataFormat}}}{{/isArray}}{{/lambda.titlecase}} {{/parentModel.composedSchemas.anyOf}}{{#allVars}}{{#isInherited}}{{^isNew}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{/isNew}}{{#isNew}}{{#isEnum}}{{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{^required}}.Value{{/required}}){{/isEnum}}{{^isEnum}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}.ToString(){{/isEnum}}{{/isNew}} {{/isInherited}}{{/allVars}}

View File

@ -1 +1 @@
{{#model.allVars}}{{{datatypeWithEnum}}}{{>NullConditionalProperty}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#defaultValue}} = {{^isDateTime}}{{#isString}}{{^isEnum}}@{{/isEnum}}{{/isString}}{{{defaultValue}}}{{/isDateTime}}{{#isDateTime}}default{{/isDateTime}}{{/defaultValue}}{{^defaultValue}}{{#isNullable}} = default{{/isNullable}}{{/defaultValue}} {{/model.allVars}} {{#model.allVars}}{{^required}}Option<{{/required}}{{{datatypeWithEnum}}}{{>NullConditionalProperty}}{{^required}}>{{/required}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{#defaultValue}} = {{^required}}default{{/required}}{{#required}}{{^isDateTime}}{{#isString}}{{^isEnum}}@{{/isEnum}}{{/isString}}{{{.}}}{{/isDateTime}}{{#isDateTime}}default{{/isDateTime}}{{/required}}{{/defaultValue}}{{^defaultValue}}{{#lambda.first}}{{#isNullable}} = default {{/isNullable}}{{^required}} = default {{/required}}{{/lambda.first}}{{/defaultValue}} {{/model.allVars}}

View File

@ -31,5 +31,17 @@ namespace {{packageName}}.{{clientPackage}}
IsSet = true; IsSet = true;
Value = value; Value = value;
} }
/// <summary>
/// Implicitly converts this option to the contained type
/// </summary>
/// <param name="option"></param>
public static implicit operator TType(Option<TType> option) => option.Value;
/// <summary>
/// Implicitly converts the provided value to an Option
/// </summary>
/// <param name="value"></param>
public static implicit operator Option<TType>(TType value) => new Option<TType>(value);
} }
} }

View File

@ -0,0 +1 @@
new Option<{{#isInnerEnum}}{{^isMap}}{{classname}}.{{/isMap}}{{/isInnerEnum}}{{{datatypeWithEnum}}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}}>(

View File

@ -0,0 +1,7 @@
// {{{name}}} ({{{dataType}}}) pattern
Regex regex{{{name}}} = new Regex(@"{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
{{#lambda.copy}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null && {{/lambda.copy}}
if ({{#lambda.first}}{{^required}}{{#lambda.pasteLine}}{{/lambda.pasteLine}} {{/required}}{{#isNullable}}{{#lambda.pasteLine}}{{/lambda.pasteLine}}{{/isNullable}}{{/lambda.first}}!regex{{{name}}}.Match(this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}}{{#isUuid}}.ToString(){{#lambda.first}}{{^required}}{{nrt!}} {{/required}}{{#isNullable}}! {{/isNullable}}{{/lambda.first}}{{/isUuid}}).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of " + regex{{{name}}}, new [] { "{{{name}}}" });
}

View File

@ -0,0 +1,9 @@
{{#required}}
{{>WritePropertyHelper}}
{{/required}}
{{^required}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}Option.IsSet)
{{#lambda.indent1}}
{{>WritePropertyHelper}}
{{/lambda.indent1}}
{{/required}}

View File

@ -0,0 +1,9 @@
{{#isNullable}}
if ({{#lambda.camelcase_param}}{{classname}}{{/lambda.camelcase_param}}.{{name}}{{^required}}Option.Value{{/required}} != null)
{{#lambda.pasteLine}}{{/lambda.pasteLine}}
else
writer.WriteNull("{{baseName}}");
{{/isNullable}}
{{^isNullable}}
{{#lambda.pasteLine}}{{/lambda.pasteLine}}
{{/isNullable}}

View File

@ -26,8 +26,8 @@ using OpenAPIClientUtils = {{packageName}}.Client.ClientUtils;
{{#useGenericHost}} {{#useGenericHost}}
{{#useSourceGeneration}} {{#useSourceGeneration}}
using System.Text.Json.Serialization.Metadata; using System.Text.Json.Serialization.Metadata;
using {{packageName}}.{{clientPackage}};
{{/useSourceGeneration}} {{/useSourceGeneration}}
using {{packageName}}.{{clientPackage}};
{{/useGenericHost}} {{/useGenericHost}}
{{#models}} {{#models}}
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}

View File

@ -15,19 +15,19 @@
{{#allVars}} {{#allVars}}
/// <param name="{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}">{{description}}{{^description}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{/description}}{{#defaultValue}} (default to {{.}}){{/defaultValue}}</param> /// <param name="{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}">{{description}}{{^description}}{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}{{/description}}{{#defaultValue}} (default to {{.}}){{/defaultValue}}</param>
{{/allVars}} {{/allVars}}
{{#model.vendorExtensions.x-model-is-mutatable}}{{>visibility}}{{/model.vendorExtensions.x-model-is-mutatable}}{{^model.vendorExtensions.x-model-is-mutatable}}internal{{/model.vendorExtensions.x-model-is-mutatable}} {{classname}}({{#lambda.joinWithComma}}{{{dataType}}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} {{#model.composedSchemas.anyOf}}{{{dataType}}}{{>NullConditionalProperty}} {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}} {{/model.composedSchemas.anyOf}}{{>ModelSignature}}{{/lambda.joinWithComma}}){{#parent}} : base({{#lambda.joinWithComma}}{{#parentModel.composedSchemas.oneOf}}{{#lambda.camelcase_param}}{{parent}}{{/lambda.camelcase_param}}.{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} {{/parentModel.composedSchemas.oneOf}}{{>ModelBaseSignature}}{{/lambda.joinWithComma}}){{/parent}} {{#model.vendorExtensions.x-model-is-mutatable}}{{>visibility}}{{/model.vendorExtensions.x-model-is-mutatable}}{{^model.vendorExtensions.x-model-is-mutatable}}internal{{/model.vendorExtensions.x-model-is-mutatable}} {{classname}}({{#lambda.joinWithComma}}{{{dataType}}} {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} {{#model.composedSchemas.anyOf}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalProperty}}{{^required}}>{{/required}} {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}} {{/model.composedSchemas.anyOf}}{{>ModelSignature}}{{/lambda.joinWithComma}}){{#parent}} : base({{#lambda.joinWithComma}}{{#parentModel.composedSchemas.oneOf}}{{#lambda.camelcase_param}}{{parent}}{{/lambda.camelcase_param}}.{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} {{/parentModel.composedSchemas.oneOf}}{{>ModelBaseSignature}}{{/lambda.joinWithComma}}){{/parent}}
{ {
{{#composedSchemas.anyOf}} {{#composedSchemas.anyOf}}
{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} = {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}}; {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}{{^required}}Option{{/required}} = {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}};
{{/composedSchemas.anyOf}} {{/composedSchemas.anyOf}}
{{name}} = {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}}; {{name}} = {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}};
{{#allVars}} {{#allVars}}
{{^isInherited}} {{^isInherited}}
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{name}}{{^required}}Option{{/required}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isInherited}} {{/isInherited}}
{{#isInherited}} {{#isInherited}}
{{#isNew}} {{#isNew}}
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{name}}{{^required}}Option{{/required}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isNew}} {{/isNew}}
{{/isInherited}} {{/isInherited}}
{{/allVars}} {{/allVars}}
@ -49,18 +49,18 @@
{{^composedSchemas.anyOf}} {{^composedSchemas.anyOf}}
[JsonConstructor] [JsonConstructor]
{{/composedSchemas.anyOf}} {{/composedSchemas.anyOf}}
{{#model.vendorExtensions.x-model-is-mutatable}}{{>visibility}}{{/model.vendorExtensions.x-model-is-mutatable}}{{^model.vendorExtensions.x-model-is-mutatable}}internal{{/model.vendorExtensions.x-model-is-mutatable}} {{classname}}({{#lambda.joinWithComma}}{{#composedSchemas.anyOf}}{{{name}}}{{>NullConditionalProperty}} {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}} {{/composedSchemas.anyOf}}{{>ModelSignature}}{{/lambda.joinWithComma}}){{#parent}} : base({{#lambda.joinWithComma}}{{>ModelBaseSignature}}{{/lambda.joinWithComma}}){{/parent}} {{#model.vendorExtensions.x-model-is-mutatable}}{{>visibility}}{{/model.vendorExtensions.x-model-is-mutatable}}{{^model.vendorExtensions.x-model-is-mutatable}}internal{{/model.vendorExtensions.x-model-is-mutatable}} {{classname}}({{#lambda.joinWithComma}}{{#composedSchemas.anyOf}}{{^required}}Option<{{/required}}{{{name}}}{{>NullConditionalProperty}}{{^required}}>{{/required}} {{#lambda.camelcase_param}}{{baseType}}{{/lambda.camelcase_param}} {{/composedSchemas.anyOf}}{{>ModelSignature}}{{/lambda.joinWithComma}}){{#parent}} : base({{#lambda.joinWithComma}}{{>ModelBaseSignature}}{{/lambda.joinWithComma}}){{/parent}}
{ {
{{#composedSchemas.anyOf}} {{#composedSchemas.anyOf}}
{{#lambda.titlecase}}{{name}}{{/lambda.titlecase}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{#lambda.titlecase}}{{name}}{{/lambda.titlecase}}{{^required}}Option{{/required}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/composedSchemas.anyOf}} {{/composedSchemas.anyOf}}
{{#allVars}} {{#allVars}}
{{^isInherited}} {{^isInherited}}
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{name}}{{^required}}Option{{/required}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isInherited}} {{/isInherited}}
{{#isInherited}} {{#isInherited}}
{{#isNew}} {{#isNew}}
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}; {{name}}{{^required}}Option{{/required}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/isNew}} {{/isNew}}
{{/isInherited}} {{/isInherited}}
{{/allVars}} {{/allVars}}
@ -84,6 +84,15 @@
{{/complexType}} {{/complexType}}
{{/isEnum}} {{/isEnum}}
{{#isEnum}} {{#isEnum}}
{{^required}}
/// <summary>
/// Used to track the state of {{{name}}}
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public {{#isNew}}new {{/isNew}}Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}> {{name}}Option { get; {{^isReadOnly}}private set; {{/isReadOnly}}}
{{/required}}
/// <summary> /// <summary>
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}} /// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
/// </summary> /// </summary>
@ -97,12 +106,21 @@
{{#deprecated}} {{#deprecated}}
[Obsolete] [Obsolete]
{{/deprecated}} {{/deprecated}}
public {{#isNew}}new {{/isNew}}{{{datatypeWithEnum}}}{{>NullConditionalProperty}} {{name}} { get; {{^isReadOnly}}set; {{/isReadOnly}}} public {{#isNew}}new {{/isNew}}{{{datatypeWithEnum}}}{{#lambda.first}}{{#isNullable}}{{>NullConditionalProperty}} {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{/required}}{{/lambda.first}} {{name}} {{#required}}{ get; {{^isReadOnly}}set; {{/isReadOnly}}}{{/required}}{{^required}}{ get { return this.{{name}}Option; } {{^isReadOnly}}set { this.{{name}}Option = new{{^net70OrLater}} Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}>{{/net70OrLater}}(value); } {{/isReadOnly}}}{{/required}}
{{/isEnum}} {{/isEnum}}
{{/vars}} {{/vars}}
{{#composedSchemas.anyOf}} {{#composedSchemas.anyOf}}
{{^vendorExtensions.x-duplicated-data-type}} {{^vendorExtensions.x-duplicated-data-type}}
{{^required}}
/// <summary>
/// Used to track the state of {{{name}}}
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public {{#isNew}}new {{/isNew}}Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}> {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}Option { get; {{^isReadOnly}}private set; {{/isReadOnly}}}
{{/required}}
/// <summary> /// <summary>
/// {{description}}{{^description}}Gets or Sets {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}{{/description}} /// {{description}}{{^description}}Gets or Sets {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}{{/description}}
/// </summary>{{#description}} /// </summary>{{#description}}
@ -113,7 +131,7 @@
{{#deprecated}} {{#deprecated}}
[Obsolete] [Obsolete]
{{/deprecated}} {{/deprecated}}
public {{{dataType}}}{{>NullConditionalProperty}} {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} { get; {{^isReadOnly}}set; {{/isReadOnly}}} public {{{datatypeWithEnum}}}{{#lambda.first}}{{#isNullable}}{{>NullConditionalProperty}} {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{/required}}{{/lambda.first}} {{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}} {{#required}}{ get; {{^isReadOnly}}set; {{/isReadOnly}}}{{/required}}{{^required}}{ get { return this.{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}Option; } {{^isReadOnly}}set { this.{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}Option = new{{^net70OrLater}} Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}>{{/net70OrLater}}(value); } {{/isReadOnly}}}{{/required}}
{{/vendorExtensions.x-duplicated-data-type}} {{/vendorExtensions.x-duplicated-data-type}}
{{/composedSchemas.anyOf}} {{/composedSchemas.anyOf}}
@ -137,6 +155,15 @@
{{^isEnum}} {{^isEnum}}
{{#isInherited}} {{#isInherited}}
{{#isNew}} {{#isNew}}
{{^required}}
/// <summary>
/// Used to track the state of {{{name}}}
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public new Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}> {{name}}Option { get; {{^isReadOnly}}private set; {{/isReadOnly}}}
{{/required}}
/// <summary> /// <summary>
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}} /// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
/// </summary>{{#description}} /// </summary>{{#description}}
@ -148,11 +175,20 @@
{{#deprecated}} {{#deprecated}}
[Obsolete] [Obsolete]
{{/deprecated}} {{/deprecated}}
public new {{{datatypeWithEnum}}}{{>NullConditionalProperty}} {{name}} { get; {{^isReadOnly}}set; {{/isReadOnly}}} public new {{{datatypeWithEnum}}}{{#lambda.first}}{{#isNullable}}{{>NullConditionalProperty}} {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{/required}}{{/lambda.first}} {{name}} {{#required}}{ get; {{^isReadOnly}}set; {{/isReadOnly}}}{{/required}}{{^required}}{ get { return this.{{name}}Option } {{^isReadOnly}}set { this.{{name}}Option = new{{^net70OrLater}} Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}>{{/net70OrLater}}(value); } {{/isReadOnly}}}{{/required}}
{{/isNew}} {{/isNew}}
{{/isInherited}} {{/isInherited}}
{{^isInherited}} {{^isInherited}}
{{^required}}
/// <summary>
/// Used to track the state of {{{name}}}
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}> {{name}}Option { get; {{^isReadOnly}}private set; {{/isReadOnly}}}
{{/required}}
/// <summary> /// <summary>
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}} /// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
/// </summary>{{#description}} /// </summary>{{#description}}
@ -164,7 +200,7 @@
{{#deprecated}} {{#deprecated}}
[Obsolete] [Obsolete]
{{/deprecated}} {{/deprecated}}
public {{{datatypeWithEnum}}}{{>NullConditionalProperty}} {{name}} { get; {{^isReadOnly}}set; {{/isReadOnly}}} public {{{datatypeWithEnum}}}{{#lambda.first}}{{#isNullable}}{{>NullConditionalProperty}} {{/isNullable}}{{^required}}{{nrt?}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{/required}}{{/lambda.first}} {{name}} {{#required}}{ get; {{^isReadOnly}}set; {{/isReadOnly}}}{{/required}}{{^required}}{ get { return this. {{name}}Option; } {{^isReadOnly}}set { this.{{name}}Option = new{{^net70OrLater}} Option<{{{datatypeWithEnum}}}{{>NullConditionalProperty}}>{{/net70OrLater}}(value); } {{/isReadOnly}}}{{/required}}
{{/isInherited}} {{/isInherited}}
{{/isEnum}} {{/isEnum}}
@ -274,16 +310,24 @@
int hashCode = 41; int hashCode = 41;
{{/parent}} {{/parent}}
{{#readOnlyVars}} {{#readOnlyVars}}
{{#required}}
{{^isNullable}} {{^isNullable}}
hashCode = (hashCode * 59) + {{name}}.GetHashCode(); hashCode = (hashCode * 59) + {{name}}.GetHashCode();
{{/isNullable}} {{/isNullable}}
{{/required}}
{{/readOnlyVars}} {{/readOnlyVars}}
{{#readOnlyVars}} {{#readOnlyVars}}
{{#isNullable}} {{#lambda.copy}}
if ({{name}} != null) if ({{name}} != null)
hashCode = (hashCode * 59) + {{name}}.GetHashCode(); hashCode = (hashCode * 59) + {{name}}.GetHashCode();
{{/lambda.copy}}
{{#isNullable}}
{{#lambda.pasteOnce}}{{/lambda.pasteOnce}}
{{/isNullable}} {{/isNullable}}
{{^required}}
{{#lambda.pasteOnce}}{{/lambda.pasteOnce}}
{{/required}}
{{/readOnlyVars}} {{/readOnlyVars}}
{{#isAdditionalPropertiesTrue}} {{#isAdditionalPropertiesTrue}}
{{^parentModel}} {{^parentModel}}

View File

@ -74,7 +74,7 @@
{{#isString}} {{#isString}}
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
{{/isString}} {{/isString}}
public static {{>EnumValueDataType}}{{>NullConditionalProperty}} {{datatypeWithEnum}}ToJsonValue({{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}{{>NullConditionalProperty}} value) public static {{>EnumValueDataType}}{{#nrt}}{{#isString}}{{#isNullable}}{{nrt?}} {{^nrt}}{{#vendorExtensions.x-is-value-type}}? {{/vendorExtensions.x-is-value-type}}{{/nrt}}{{/isNullable}}{{/isString}}{{/nrt}} {{datatypeWithEnum}}ToJsonValue({{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}{{#isString}}{{>NullConditionalProperty}}{{/isString}} value)
{ {
{{^isString}} {{^isString}}
return ({{>EnumValueDataType}}) value; return ({{>EnumValueDataType}}) value;
@ -83,8 +83,8 @@
{{#isNullable}} {{#isNullable}}
if (value == null) if (value == null)
return null; return null;
{{/isNullable}}
{{/isNullable}}
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
if (value == {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.{{name}}) if (value == {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.{{name}})

View File

@ -78,7 +78,7 @@
{{/minLength}} {{/minLength}}
{{#maximum}} {{#maximum}}
// {{{name}}} ({{{dataType}}}) maximum // {{{name}}} ({{{dataType}}}) maximum
if (this.{{{name}}} > ({{{dataType}}}){{maximum}}) if ({{#useGenericHost}}{{^required}}this.{{{name}}}Option.IsSet && {{/required}}{{/useGenericHost}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} > ({{{dataType}}}){{maximum}})
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" });
} }
@ -86,7 +86,7 @@
{{/maximum}} {{/maximum}}
{{#minimum}} {{#minimum}}
// {{{name}}} ({{{dataType}}}) minimum // {{{name}}} ({{{dataType}}}) minimum
if (this.{{{name}}} < ({{{dataType}}}){{minimum}}) if ({{#useGenericHost}}{{^required}}this.{{{name}}}Option.IsSet && {{/required}}{{/useGenericHost}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} < ({{{dataType}}}){{minimum}})
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" });
} }
@ -96,7 +96,7 @@
{{^isByteArray}} {{^isByteArray}}
{{#vendorExtensions.x-is-value-type}} {{#vendorExtensions.x-is-value-type}}
{{#isNullable}} {{#isNullable}}
if (this.{{{name}}} != null){ if (this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null){
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#lambda.indent4}} {{#lambda.indent4}}
{{>ValidateRegex}} {{>ValidateRegex}}
@ -116,7 +116,7 @@
{{/isNullable}} {{/isNullable}}
{{/vendorExtensions.x-is-value-type}} {{/vendorExtensions.x-is-value-type}}
{{^vendorExtensions.x-is-value-type}} {{^vendorExtensions.x-is-value-type}}
if (this.{{{name}}} != null) { if (this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null) {
{{#lambda.trimTrailingWithNewLine}} {{#lambda.trimTrailingWithNewLine}}
{{#lambda.indent4}} {{#lambda.indent4}}
{{>ValidateRegex}} {{>ValidateRegex}}

View File

@ -1983,6 +1983,266 @@ components:
nullable: true nullable: true
type: string type: string
description: Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. description: Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model.
RequiredClass:
type: object
properties:
required_nullable_integer_prop:
type: integer
nullable: true
required_notnullableinteger_prop:
type: integer
nullable: false
not_required_nullable_integer_prop:
type: integer
nullable: true
not_required_notnullableinteger_prop:
type: integer
nullable: false
required_nullable_string_prop:
type: string
nullable: true
required_notnullable_string_prop:
type: string
nullable: false
notrequired_nullable_string_prop:
type: string
nullable: true
notrequired_notnullable_string_prop:
type: string
nullable: false
required_nullable_boolean_prop:
type: boolean
nullable: true
required_notnullable_boolean_prop:
type: boolean
nullable: false
notrequired_nullable_boolean_prop:
type: boolean
nullable: true
notrequired_notnullable_boolean_prop:
type: boolean
nullable: false
required_nullable_date_prop:
type: string
format: date
nullable: true
required_not_nullable_date_prop:
type: string
format: date
nullable: false
not_required_nullable_date_prop:
type: string
format: date
nullable: true
not_required_notnullable_date_prop:
type: string
format: date
nullable: false
required_notnullable_datetime_prop:
type: string
format: date-time
nullable: false
required_nullable_datetime_prop:
type: string
format: date-time
nullable: true
notrequired_nullable_datetime_prop:
type: string
format: date-time
nullable: true
notrequired_notnullable_datetime_prop:
type: string
format: date-time
nullable: false
required_nullable_enum_integer:
type: integer
format: int32
nullable: true
enum:
- 1
- -1
required_notnullable_enum_integer:
type: integer
format: int32
nullable: false
enum:
- 1
- -1
notrequired_nullable_enum_integer:
type: integer
format: int32
nullable: true
enum:
- 1
- -1
notrequired_notnullable_enum_integer:
type: integer
format: int32
nullable: false
enum:
- 1
- -1
required_nullable_enum_integer_only:
type: integer
nullable: true
enum:
- 2
- -2
required_notnullable_enum_integer_only:
type: integer
nullable: false
enum:
- 2
- -2
notrequired_nullable_enum_integer_only:
type: integer
nullable: true
enum:
- 2
- -2
notrequired_notnullable_enum_integer_only:
type: integer
nullable: false
enum:
- 2
- -2
required_notnullable_enum_string:
type: string
nullable: false
enum:
- UPPER
- lower
- ''
- "Value\twith tab"
- 'Value with " quote'
- 'Value with escaped \" quote'
- "Duplicate\nvalue"
- "Duplicate\r\nvalue"
required_nullable_enum_string:
type: string
nullable: true
enum:
- UPPER
- lower
- ''
- "Value\twith tab"
- 'Value with " quote'
- 'Value with escaped \" quote'
- "Duplicate\nvalue"
- "Duplicate\r\nvalue"
notrequired_nullable_enum_string:
type: string
nullable: true
enum:
- UPPER
- lower
- ''
- "Value\twith tab"
- 'Value with " quote'
- 'Value with escaped \" quote'
- "Duplicate\nvalue"
- "Duplicate\r\nvalue"
notrequired_notnullable_enum_string:
type: string
nullable: false
enum:
- UPPER
- lower
- ''
- "Value\twith tab"
- 'Value with " quote'
- 'Value with escaped \" quote'
- "Duplicate\nvalue"
- "Duplicate\r\nvalue"
required_nullable_outerEnumDefaultValue:
nullable: true
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
required_notnullable_outerEnumDefaultValue:
nullable: false
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
notrequired_nullable_outerEnumDefaultValue:
nullable: true
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
notrequired_notnullable_outerEnumDefaultValue:
nullable: false
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
required_nullable_uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
nullable: true
required_notnullable_uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
nullable: false
notrequired_nullable_uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
nullable: true
notrequired_notnullable_uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
nullable: false
required_nullable_array_of_string:
type: array
nullable: true
items:
type: string
required_notnullable_array_of_string:
type: array
nullable: false
items:
type: string
notrequired_nullable_array_of_string:
type: array
nullable: true
items:
type: string
notrequired_notnullable_array_of_string:
type: array
nullable: false
items:
type: string
required:
- required_nullable_boolean_prop
- required_notnullable_boolean_prop
- required_nullable_string_prop
- required_notnullable_string_prop
- required_nullable_integer_prop
- required_notnullableinteger_prop
- required_nullable_date_prop
- required_not_nullable_date_prop
- required_notnullable_datetime_prop
- required_nullable_datetime_prop
- required_nullable_enum_integer
- required_notnullable_enum_integer
- required_nullable_enum_integer_only
- required_notnullable_enum_integer_only
- required_notnullable_enum_string
- required_nullable_enum_string
- required_nullable_outerEnumDefaultValue
- required_notnullable_outerEnumDefaultValue
- required_nullable_uuid
- required_notnullable_uuid
- required_nullable_array_of_string
- required_notnullable_array_of_string
NullableClass: NullableClass:
type: object type: object
properties: properties:

View File

@ -77,6 +77,7 @@ docs/PolymorphicProperty.md
docs/Quadrilateral.md docs/Quadrilateral.md
docs/QuadrilateralInterface.md docs/QuadrilateralInterface.md
docs/ReadOnlyFirst.md docs/ReadOnlyFirst.md
docs/RequiredClass.md
docs/Return.md docs/Return.md
docs/RolesReportsHash.md docs/RolesReportsHash.md
docs/RolesReportsHashRole.md docs/RolesReportsHashRole.md
@ -198,6 +199,7 @@ src/Org.OpenAPITools/Model/PolymorphicProperty.cs
src/Org.OpenAPITools/Model/Quadrilateral.cs src/Org.OpenAPITools/Model/Quadrilateral.cs
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
src/Org.OpenAPITools/Model/RequiredClass.cs
src/Org.OpenAPITools/Model/Return.cs src/Org.OpenAPITools/Model/Return.cs
src/Org.OpenAPITools/Model/RolesReportsHash.cs src/Org.OpenAPITools/Model/RolesReportsHash.cs
src/Org.OpenAPITools/Model/RolesReportsHashRole.cs src/Org.OpenAPITools/Model/RolesReportsHashRole.cs

View File

@ -221,6 +221,7 @@ Class | Method | HTTP request | Description
- [Model.Quadrilateral](docs/Quadrilateral.md) - [Model.Quadrilateral](docs/Quadrilateral.md)
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md) - [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md) - [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [Model.RequiredClass](docs/RequiredClass.md)
- [Model.Return](docs/Return.md) - [Model.Return](docs/Return.md)
- [Model.RolesReportsHash](docs/RolesReportsHash.md) - [Model.RolesReportsHash](docs/RolesReportsHash.md)
- [Model.RolesReportsHashRole](docs/RolesReportsHashRole.md) - [Model.RolesReportsHashRole](docs/RolesReportsHashRole.md)

View File

@ -1946,6 +1946,264 @@ components:
nullable: true nullable: true
type: string type: string
type: object type: object
RequiredClass:
properties:
required_nullable_integer_prop:
nullable: true
type: integer
required_notnullableinteger_prop:
nullable: false
type: integer
not_required_nullable_integer_prop:
nullable: true
type: integer
not_required_notnullableinteger_prop:
nullable: false
type: integer
required_nullable_string_prop:
nullable: true
type: string
required_notnullable_string_prop:
nullable: false
type: string
notrequired_nullable_string_prop:
nullable: true
type: string
notrequired_notnullable_string_prop:
nullable: false
type: string
required_nullable_boolean_prop:
nullable: true
type: boolean
required_notnullable_boolean_prop:
nullable: false
type: boolean
notrequired_nullable_boolean_prop:
nullable: true
type: boolean
notrequired_notnullable_boolean_prop:
nullable: false
type: boolean
required_nullable_date_prop:
format: date
nullable: true
type: string
required_not_nullable_date_prop:
format: date
nullable: false
type: string
not_required_nullable_date_prop:
format: date
nullable: true
type: string
not_required_notnullable_date_prop:
format: date
nullable: false
type: string
required_notnullable_datetime_prop:
format: date-time
nullable: false
type: string
required_nullable_datetime_prop:
format: date-time
nullable: true
type: string
notrequired_nullable_datetime_prop:
format: date-time
nullable: true
type: string
notrequired_notnullable_datetime_prop:
format: date-time
nullable: false
type: string
required_nullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: true
type: integer
required_notnullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: false
type: integer
notrequired_nullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: true
type: integer
notrequired_notnullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: false
type: integer
required_nullable_enum_integer_only:
enum:
- 2
- -2
nullable: true
type: integer
required_notnullable_enum_integer_only:
enum:
- 2
- -2
nullable: false
type: integer
notrequired_nullable_enum_integer_only:
enum:
- 2
- -2
nullable: true
type: integer
notrequired_notnullable_enum_integer_only:
enum:
- 2
- -2
nullable: false
type: integer
required_notnullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: false
type: string
required_nullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: true
type: string
notrequired_nullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: true
type: string
notrequired_notnullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: false
type: string
required_nullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: true
required_notnullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: false
notrequired_nullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: true
notrequired_notnullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: false
required_nullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: true
type: string
required_notnullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: false
type: string
notrequired_nullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: true
type: string
notrequired_notnullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: false
type: string
required_nullable_array_of_string:
items:
type: string
nullable: true
type: array
required_notnullable_array_of_string:
items:
type: string
nullable: false
type: array
notrequired_nullable_array_of_string:
items:
type: string
nullable: true
type: array
notrequired_notnullable_array_of_string:
items:
type: string
nullable: false
type: array
required:
- required_not_nullable_date_prop
- required_notnullable_array_of_string
- required_notnullable_boolean_prop
- required_notnullable_datetime_prop
- required_notnullable_enum_integer
- required_notnullable_enum_integer_only
- required_notnullable_enum_string
- required_notnullable_outerEnumDefaultValue
- required_notnullable_string_prop
- required_notnullable_uuid
- required_notnullableinteger_prop
- required_nullable_array_of_string
- required_nullable_boolean_prop
- required_nullable_date_prop
- required_nullable_datetime_prop
- required_nullable_enum_integer
- required_nullable_enum_integer_only
- required_nullable_enum_string
- required_nullable_integer_prop
- required_nullable_outerEnumDefaultValue
- required_nullable_string_prop
- required_nullable_uuid
type: object
NullableClass: NullableClass:
additionalProperties: additionalProperties:
nullable: true nullable: true

View File

@ -0,0 +1,53 @@
# Org.OpenAPITools.Model.RequiredClass
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**RequiredNullableIntegerProp** | **int?** | |
**RequiredNotnullableintegerProp** | **int** | |
**NotRequiredNullableIntegerProp** | **int?** | | [optional]
**NotRequiredNotnullableintegerProp** | **int** | | [optional]
**RequiredNullableStringProp** | **string** | |
**RequiredNotnullableStringProp** | **string** | |
**NotrequiredNullableStringProp** | **string** | | [optional]
**NotrequiredNotnullableStringProp** | **string** | | [optional]
**RequiredNullableBooleanProp** | **bool?** | |
**RequiredNotnullableBooleanProp** | **bool** | |
**NotrequiredNullableBooleanProp** | **bool?** | | [optional]
**NotrequiredNotnullableBooleanProp** | **bool** | | [optional]
**RequiredNullableDateProp** | **DateTime?** | |
**RequiredNotNullableDateProp** | **DateTime** | |
**NotRequiredNullableDateProp** | **DateTime?** | | [optional]
**NotRequiredNotnullableDateProp** | **DateTime** | | [optional]
**RequiredNotnullableDatetimeProp** | **DateTime** | |
**RequiredNullableDatetimeProp** | **DateTime?** | |
**NotrequiredNullableDatetimeProp** | **DateTime?** | | [optional]
**NotrequiredNotnullableDatetimeProp** | **DateTime** | | [optional]
**RequiredNullableEnumInteger** | **int?** | |
**RequiredNotnullableEnumInteger** | **int** | |
**NotrequiredNullableEnumInteger** | **int?** | | [optional]
**NotrequiredNotnullableEnumInteger** | **int** | | [optional]
**RequiredNullableEnumIntegerOnly** | **int?** | |
**RequiredNotnullableEnumIntegerOnly** | **int** | |
**NotrequiredNullableEnumIntegerOnly** | **int?** | | [optional]
**NotrequiredNotnullableEnumIntegerOnly** | **int** | | [optional]
**RequiredNotnullableEnumString** | **string** | |
**RequiredNullableEnumString** | **string** | |
**NotrequiredNullableEnumString** | **string** | | [optional]
**NotrequiredNotnullableEnumString** | **string** | | [optional]
**RequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
**RequiredNotnullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
**NotrequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**NotrequiredNotnullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**RequiredNullableUuid** | **Guid?** | |
**RequiredNotnullableUuid** | **Guid** | |
**NotrequiredNullableUuid** | **Guid?** | | [optional]
**NotrequiredNotnullableUuid** | **Guid** | | [optional]
**RequiredNullableArrayOfString** | **List&lt;string&gt;** | |
**RequiredNotnullableArrayOfString** | **List&lt;string&gt;** | |
**NotrequiredNullableArrayOfString** | **List&lt;string&gt;** | | [optional]
**NotrequiredNotnullableArrayOfString** | **List&lt;string&gt;** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,453 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using Xunit;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;
namespace Org.OpenAPITools.Test.Model
{
/// <summary>
/// Class for testing RequiredClass
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
public class RequiredClassTests : IDisposable
{
// TODO uncomment below to declare an instance variable for RequiredClass
//private RequiredClass instance;
public RequiredClassTests()
{
// TODO uncomment below to create an instance of RequiredClass
//instance = new RequiredClass();
}
public void Dispose()
{
// Cleanup when everything is done.
}
/// <summary>
/// Test an instance of RequiredClass
/// </summary>
[Fact]
public void RequiredClassInstanceTest()
{
// TODO uncomment below to test "IsType" RequiredClass
//Assert.IsType<RequiredClass>(instance);
}
/// <summary>
/// Test the property 'RequiredNullableIntegerProp'
/// </summary>
[Fact]
public void RequiredNullableIntegerPropTest()
{
// TODO unit test for the property 'RequiredNullableIntegerProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableintegerProp'
/// </summary>
[Fact]
public void RequiredNotnullableintegerPropTest()
{
// TODO unit test for the property 'RequiredNotnullableintegerProp'
}
/// <summary>
/// Test the property 'NotRequiredNullableIntegerProp'
/// </summary>
[Fact]
public void NotRequiredNullableIntegerPropTest()
{
// TODO unit test for the property 'NotRequiredNullableIntegerProp'
}
/// <summary>
/// Test the property 'NotRequiredNotnullableintegerProp'
/// </summary>
[Fact]
public void NotRequiredNotnullableintegerPropTest()
{
// TODO unit test for the property 'NotRequiredNotnullableintegerProp'
}
/// <summary>
/// Test the property 'RequiredNullableStringProp'
/// </summary>
[Fact]
public void RequiredNullableStringPropTest()
{
// TODO unit test for the property 'RequiredNullableStringProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableStringProp'
/// </summary>
[Fact]
public void RequiredNotnullableStringPropTest()
{
// TODO unit test for the property 'RequiredNotnullableStringProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableStringProp'
/// </summary>
[Fact]
public void NotrequiredNullableStringPropTest()
{
// TODO unit test for the property 'NotrequiredNullableStringProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableStringProp'
/// </summary>
[Fact]
public void NotrequiredNotnullableStringPropTest()
{
// TODO unit test for the property 'NotrequiredNotnullableStringProp'
}
/// <summary>
/// Test the property 'RequiredNullableBooleanProp'
/// </summary>
[Fact]
public void RequiredNullableBooleanPropTest()
{
// TODO unit test for the property 'RequiredNullableBooleanProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableBooleanProp'
/// </summary>
[Fact]
public void RequiredNotnullableBooleanPropTest()
{
// TODO unit test for the property 'RequiredNotnullableBooleanProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableBooleanProp'
/// </summary>
[Fact]
public void NotrequiredNullableBooleanPropTest()
{
// TODO unit test for the property 'NotrequiredNullableBooleanProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableBooleanProp'
/// </summary>
[Fact]
public void NotrequiredNotnullableBooleanPropTest()
{
// TODO unit test for the property 'NotrequiredNotnullableBooleanProp'
}
/// <summary>
/// Test the property 'RequiredNullableDateProp'
/// </summary>
[Fact]
public void RequiredNullableDatePropTest()
{
// TODO unit test for the property 'RequiredNullableDateProp'
}
/// <summary>
/// Test the property 'RequiredNotNullableDateProp'
/// </summary>
[Fact]
public void RequiredNotNullableDatePropTest()
{
// TODO unit test for the property 'RequiredNotNullableDateProp'
}
/// <summary>
/// Test the property 'NotRequiredNullableDateProp'
/// </summary>
[Fact]
public void NotRequiredNullableDatePropTest()
{
// TODO unit test for the property 'NotRequiredNullableDateProp'
}
/// <summary>
/// Test the property 'NotRequiredNotnullableDateProp'
/// </summary>
[Fact]
public void NotRequiredNotnullableDatePropTest()
{
// TODO unit test for the property 'NotRequiredNotnullableDateProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableDatetimeProp'
/// </summary>
[Fact]
public void RequiredNotnullableDatetimePropTest()
{
// TODO unit test for the property 'RequiredNotnullableDatetimeProp'
}
/// <summary>
/// Test the property 'RequiredNullableDatetimeProp'
/// </summary>
[Fact]
public void RequiredNullableDatetimePropTest()
{
// TODO unit test for the property 'RequiredNullableDatetimeProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableDatetimeProp'
/// </summary>
[Fact]
public void NotrequiredNullableDatetimePropTest()
{
// TODO unit test for the property 'NotrequiredNullableDatetimeProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableDatetimeProp'
/// </summary>
[Fact]
public void NotrequiredNotnullableDatetimePropTest()
{
// TODO unit test for the property 'NotrequiredNotnullableDatetimeProp'
}
/// <summary>
/// Test the property 'RequiredNullableEnumInteger'
/// </summary>
[Fact]
public void RequiredNullableEnumIntegerTest()
{
// TODO unit test for the property 'RequiredNullableEnumInteger'
}
/// <summary>
/// Test the property 'RequiredNotnullableEnumInteger'
/// </summary>
[Fact]
public void RequiredNotnullableEnumIntegerTest()
{
// TODO unit test for the property 'RequiredNotnullableEnumInteger'
}
/// <summary>
/// Test the property 'NotrequiredNullableEnumInteger'
/// </summary>
[Fact]
public void NotrequiredNullableEnumIntegerTest()
{
// TODO unit test for the property 'NotrequiredNullableEnumInteger'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableEnumInteger'
/// </summary>
[Fact]
public void NotrequiredNotnullableEnumIntegerTest()
{
// TODO unit test for the property 'NotrequiredNotnullableEnumInteger'
}
/// <summary>
/// Test the property 'RequiredNullableEnumIntegerOnly'
/// </summary>
[Fact]
public void RequiredNullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'RequiredNullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'RequiredNotnullableEnumIntegerOnly'
/// </summary>
[Fact]
public void RequiredNotnullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'RequiredNotnullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'NotrequiredNullableEnumIntegerOnly'
/// </summary>
[Fact]
public void NotrequiredNullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'NotrequiredNullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableEnumIntegerOnly'
/// </summary>
[Fact]
public void NotrequiredNotnullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'NotrequiredNotnullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'RequiredNotnullableEnumString'
/// </summary>
[Fact]
public void RequiredNotnullableEnumStringTest()
{
// TODO unit test for the property 'RequiredNotnullableEnumString'
}
/// <summary>
/// Test the property 'RequiredNullableEnumString'
/// </summary>
[Fact]
public void RequiredNullableEnumStringTest()
{
// TODO unit test for the property 'RequiredNullableEnumString'
}
/// <summary>
/// Test the property 'NotrequiredNullableEnumString'
/// </summary>
[Fact]
public void NotrequiredNullableEnumStringTest()
{
// TODO unit test for the property 'NotrequiredNullableEnumString'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableEnumString'
/// </summary>
[Fact]
public void NotrequiredNotnullableEnumStringTest()
{
// TODO unit test for the property 'NotrequiredNotnullableEnumString'
}
/// <summary>
/// Test the property 'RequiredNullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void RequiredNullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'RequiredNullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'RequiredNotnullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void RequiredNotnullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'RequiredNotnullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'NotrequiredNullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void NotrequiredNullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'NotrequiredNullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void NotrequiredNotnullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'NotrequiredNotnullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'RequiredNullableUuid'
/// </summary>
[Fact]
public void RequiredNullableUuidTest()
{
// TODO unit test for the property 'RequiredNullableUuid'
}
/// <summary>
/// Test the property 'RequiredNotnullableUuid'
/// </summary>
[Fact]
public void RequiredNotnullableUuidTest()
{
// TODO unit test for the property 'RequiredNotnullableUuid'
}
/// <summary>
/// Test the property 'NotrequiredNullableUuid'
/// </summary>
[Fact]
public void NotrequiredNullableUuidTest()
{
// TODO unit test for the property 'NotrequiredNullableUuid'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableUuid'
/// </summary>
[Fact]
public void NotrequiredNotnullableUuidTest()
{
// TODO unit test for the property 'NotrequiredNotnullableUuid'
}
/// <summary>
/// Test the property 'RequiredNullableArrayOfString'
/// </summary>
[Fact]
public void RequiredNullableArrayOfStringTest()
{
// TODO unit test for the property 'RequiredNullableArrayOfString'
}
/// <summary>
/// Test the property 'RequiredNotnullableArrayOfString'
/// </summary>
[Fact]
public void RequiredNotnullableArrayOfStringTest()
{
// TODO unit test for the property 'RequiredNotnullableArrayOfString'
}
/// <summary>
/// Test the property 'NotrequiredNullableArrayOfString'
/// </summary>
[Fact]
public void NotrequiredNullableArrayOfStringTest()
{
// TODO unit test for the property 'NotrequiredNullableArrayOfString'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableArrayOfString'
/// </summary>
[Fact]
public void NotrequiredNotnullableArrayOfStringTest()
{
// TODO unit test for the property 'NotrequiredNotnullableArrayOfString'
}
}
}

View File

@ -64,7 +64,7 @@ public class UnitTest1
Apple apple = new("#000000", "cultivar", "origin"); Apple apple = new("#000000", "cultivar", "origin");
string appleJson = JsonSerializer.Serialize(apple, _jsonSerializerOptions); string appleJson = JsonSerializer.Serialize(apple, _jsonSerializerOptions);
Apple? apple2 = JsonSerializer.Deserialize<Apple>(appleJson, _jsonSerializerOptions); Apple? apple2 = JsonSerializer.Deserialize<Apple>(appleJson, _jsonSerializerOptions);
Assert.IsTrue(apple2 != null && apple.Cultivar.Equals(apple2.Cultivar) && apple.Origin.Equals(apple2.Origin)); Assert.IsTrue(apple2 != null && apple.Cultivar != null && apple.Cultivar.Equals(apple2.Cultivar) && apple.Origin != null && apple.Origin.Equals(apple2.Origin));
} }
[TestMethod] [TestMethod]
@ -106,12 +106,12 @@ public class UnitTest1
gmFruit2 != null && gmFruit2 != null &&
gmFruit2.Apple != null && gmFruit2.Apple != null &&
gmFruit2.Banana != null && gmFruit2.Banana != null &&
gmFruit2.Apple.Cultivar != null &&
gmFruit2.Apple.Cultivar.Equals(gmFruit.Apple.Cultivar) && gmFruit2.Apple.Cultivar.Equals(gmFruit.Apple.Cultivar) &&
gmFruit2.Apple.Origin != null &&
gmFruit2.Apple.Origin.Equals(gmFruit.Apple.Origin) && gmFruit2.Apple.Origin.Equals(gmFruit.Apple.Origin) &&
gmFruit2.Banana.LengthCm.Equals(gmFruit.Banana.LengthCm)); gmFruit2.Banana.LengthCm.Equals(gmFruit.Banana.LengthCm));
Apple? apple2 = JsonSerializer.Deserialize<Apple>(gmFruitJson);
Assert.IsTrue(apple2 != null && apple.Cultivar == apple2.Cultivar && apple.Origin == apple2.Origin);
// TODO: assert the the properties from Banana and GmFruit are in additionalProperties // TODO: assert the the properties from Banana and GmFruit are in additionalProperties
} }
@ -146,16 +146,16 @@ public class UnitTest1
ChildCat childCat = new("some name", ChildCat.PetTypeEnum.ChildCat); ChildCat childCat = new("some name", ChildCat.PetTypeEnum.ChildCat);
string childCatJson = JsonSerializer.Serialize(childCat, _jsonSerializerOptions); string childCatJson = JsonSerializer.Serialize(childCat, _jsonSerializerOptions);
ChildCat? childCat2 = JsonSerializer.Deserialize<ChildCat>(childCatJson, _jsonSerializerOptions); ChildCat? childCat2 = JsonSerializer.Deserialize<ChildCat>(childCatJson, _jsonSerializerOptions);
Assert.IsTrue(childCat2 != null && childCat.PetType.Equals(childCat2.PetType) && childCat.Name.Equals(childCat2.Name)); Assert.IsTrue(childCat2 != null && childCat.PetType.Equals(childCat2.PetType) && childCat.Name != null && childCat.Name.Equals(childCat2.Name));
} }
[TestMethod] [TestMethod]
public void Cat() public void Cat()
{ {
Cat cat = new("cat", false, "black"); // TODO: where is the address property? Cat cat = new("cat", "black", false); // TODO: where is the address property?
string catJson = JsonSerializer.Serialize(cat, _jsonSerializerOptions); string catJson = JsonSerializer.Serialize(cat, _jsonSerializerOptions);
Cat? cat2 = JsonSerializer.Deserialize<Cat>(catJson, _jsonSerializerOptions); Cat? cat2 = JsonSerializer.Deserialize<Cat>(catJson, _jsonSerializerOptions);
Assert.IsTrue(cat2 != null && cat.Declawed.Equals(cat2.Declawed) && cat.ClassName.Equals(cat2.ClassName) && cat.Color.Equals(cat2.Color)); // TODO: add the address property Assert.IsTrue(cat2 != null && cat.Declawed.Equals(cat2.Declawed) && cat.ClassName.Equals(cat2.ClassName) && cat.Color != null && cat.Color.Equals(cat2.Color)); // TODO: add the address property
} }
} }
} }

View File

@ -50,7 +50,7 @@ namespace OpenAPIClient_generichost_manual_tests
Apple apple = new("#000000", "cultivar", "origin"); Apple apple = new("#000000", "cultivar", "origin");
string appleJson = JsonSerializer.Serialize(apple, _jsonSerializerOptions); string appleJson = JsonSerializer.Serialize(apple, _jsonSerializerOptions);
Apple? apple2 = JsonSerializer.Deserialize<Apple>(appleJson, _jsonSerializerOptions); Apple? apple2 = JsonSerializer.Deserialize<Apple>(appleJson, _jsonSerializerOptions);
Assert.IsTrue(apple2 != null && apple.Cultivar.Equals(apple2.Cultivar) && apple.Origin.Equals(apple2.Origin)); Assert.IsTrue(apple2 != null && apple.Cultivar != null && apple.Cultivar.Equals(apple2.Cultivar) && apple.Origin != null && apple.Origin.Equals(apple2.Origin));
} }
[TestMethod] [TestMethod]
@ -92,12 +92,12 @@ namespace OpenAPIClient_generichost_manual_tests
gmFruit2 != null && gmFruit2 != null &&
gmFruit2.Apple != null && gmFruit2.Apple != null &&
gmFruit2.Banana != null && gmFruit2.Banana != null &&
gmFruit2.Apple.Cultivar != null &&
gmFruit2.Apple.Cultivar.Equals(gmFruit.Apple.Cultivar) && gmFruit2.Apple.Cultivar.Equals(gmFruit.Apple.Cultivar) &&
gmFruit2.Apple.Origin != null &&
gmFruit2.Apple.Origin.Equals(gmFruit.Apple.Origin) && gmFruit2.Apple.Origin.Equals(gmFruit.Apple.Origin) &&
gmFruit2.Banana.LengthCm.Equals(gmFruit.Banana.LengthCm)); gmFruit2.Banana.LengthCm.Equals(gmFruit.Banana.LengthCm));
Apple? apple2 = JsonSerializer.Deserialize<Apple>(gmFruitJson);
Assert.IsTrue(apple2 != null && apple.Cultivar == apple2.Cultivar && apple.Origin == apple2.Origin);
// TODO: assert the the properties from Banana and GmFruit are in additionalProperties // TODO: assert the the properties from Banana and GmFruit are in additionalProperties
} }
@ -132,16 +132,16 @@ namespace OpenAPIClient_generichost_manual_tests
ChildCat childCat = new("some name", Org.OpenAPITools.Model.ChildCat.PetTypeEnum.ChildCat); ChildCat childCat = new("some name", Org.OpenAPITools.Model.ChildCat.PetTypeEnum.ChildCat);
string childCatJson = JsonSerializer.Serialize(childCat, _jsonSerializerOptions); string childCatJson = JsonSerializer.Serialize(childCat, _jsonSerializerOptions);
ChildCat? childCat2 = JsonSerializer.Deserialize<ChildCat>(childCatJson, _jsonSerializerOptions); ChildCat? childCat2 = JsonSerializer.Deserialize<ChildCat>(childCatJson, _jsonSerializerOptions);
Assert.IsTrue(childCat2 != null && childCat.PetType.Equals(childCat2.PetType) && childCat.Name.Equals(childCat2.Name)); Assert.IsTrue(childCat2 != null && childCat.PetType.Equals(childCat2.PetType) && childCat.Name != null && childCat.Name.Equals(childCat2.Name));
} }
[TestMethod] [TestMethod]
public void Cat() public void Cat()
{ {
Cat cat = new("cat", false, "black"); // TODO: where is the address property? Cat cat = new("cat", "black", false); // TODO: where is the address property?
string catJson = JsonSerializer.Serialize(cat, _jsonSerializerOptions); string catJson = JsonSerializer.Serialize(cat, _jsonSerializerOptions);
Cat? cat2 = JsonSerializer.Deserialize<Cat>(catJson, _jsonSerializerOptions); Cat? cat2 = JsonSerializer.Deserialize<Cat>(catJson, _jsonSerializerOptions);
Assert.IsTrue(cat2 != null && cat.Declawed.Equals(cat2.Declawed) && cat.ClassName.Equals(cat2.ClassName) && cat.Color.Equals(cat2.Color)); // TODO: add the address property Assert.IsTrue(cat2 != null && cat.Declawed.Equals(cat2.Declawed) && cat.ClassName.Equals(cat2.ClassName) && cat.Color != null && cat.Color.Equals(cat2.Color)); // TODO: add the address property
} }
} }
} }

View File

@ -79,6 +79,7 @@ docs/models/PolymorphicProperty.md
docs/models/Quadrilateral.md docs/models/Quadrilateral.md
docs/models/QuadrilateralInterface.md docs/models/QuadrilateralInterface.md
docs/models/ReadOnlyFirst.md docs/models/ReadOnlyFirst.md
docs/models/RequiredClass.md
docs/models/Return.md docs/models/Return.md
docs/models/RolesReportsHash.md docs/models/RolesReportsHash.md
docs/models/RolesReportsHashRole.md docs/models/RolesReportsHashRole.md
@ -206,6 +207,7 @@ src/UseSourceGeneration/Model/PolymorphicProperty.cs
src/UseSourceGeneration/Model/Quadrilateral.cs src/UseSourceGeneration/Model/Quadrilateral.cs
src/UseSourceGeneration/Model/QuadrilateralInterface.cs src/UseSourceGeneration/Model/QuadrilateralInterface.cs
src/UseSourceGeneration/Model/ReadOnlyFirst.cs src/UseSourceGeneration/Model/ReadOnlyFirst.cs
src/UseSourceGeneration/Model/RequiredClass.cs
src/UseSourceGeneration/Model/Return.cs src/UseSourceGeneration/Model/Return.cs
src/UseSourceGeneration/Model/RolesReportsHash.cs src/UseSourceGeneration/Model/RolesReportsHash.cs
src/UseSourceGeneration/Model/RolesReportsHashRole.cs src/UseSourceGeneration/Model/RolesReportsHashRole.cs

View File

@ -1946,6 +1946,264 @@ components:
nullable: true nullable: true
type: string type: string
type: object type: object
RequiredClass:
properties:
required_nullable_integer_prop:
nullable: true
type: integer
required_notnullableinteger_prop:
nullable: false
type: integer
not_required_nullable_integer_prop:
nullable: true
type: integer
not_required_notnullableinteger_prop:
nullable: false
type: integer
required_nullable_string_prop:
nullable: true
type: string
required_notnullable_string_prop:
nullable: false
type: string
notrequired_nullable_string_prop:
nullable: true
type: string
notrequired_notnullable_string_prop:
nullable: false
type: string
required_nullable_boolean_prop:
nullable: true
type: boolean
required_notnullable_boolean_prop:
nullable: false
type: boolean
notrequired_nullable_boolean_prop:
nullable: true
type: boolean
notrequired_notnullable_boolean_prop:
nullable: false
type: boolean
required_nullable_date_prop:
format: date
nullable: true
type: string
required_not_nullable_date_prop:
format: date
nullable: false
type: string
not_required_nullable_date_prop:
format: date
nullable: true
type: string
not_required_notnullable_date_prop:
format: date
nullable: false
type: string
required_notnullable_datetime_prop:
format: date-time
nullable: false
type: string
required_nullable_datetime_prop:
format: date-time
nullable: true
type: string
notrequired_nullable_datetime_prop:
format: date-time
nullable: true
type: string
notrequired_notnullable_datetime_prop:
format: date-time
nullable: false
type: string
required_nullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: true
type: integer
required_notnullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: false
type: integer
notrequired_nullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: true
type: integer
notrequired_notnullable_enum_integer:
enum:
- 1
- -1
format: int32
nullable: false
type: integer
required_nullable_enum_integer_only:
enum:
- 2
- -2
nullable: true
type: integer
required_notnullable_enum_integer_only:
enum:
- 2
- -2
nullable: false
type: integer
notrequired_nullable_enum_integer_only:
enum:
- 2
- -2
nullable: true
type: integer
notrequired_notnullable_enum_integer_only:
enum:
- 2
- -2
nullable: false
type: integer
required_notnullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: false
type: string
required_nullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: true
type: string
notrequired_nullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: true
type: string
notrequired_notnullable_enum_string:
enum:
- UPPER
- lower
- ""
- "Value\twith tab"
- Value with " quote
- Value with escaped \" quote
- |-
Duplicate
value
- "Duplicate\r\nvalue"
nullable: false
type: string
required_nullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: true
required_notnullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: false
notrequired_nullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: true
notrequired_notnullable_outerEnumDefaultValue:
allOf:
- $ref: '#/components/schemas/OuterEnumDefaultValue'
nullable: false
required_nullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: true
type: string
required_notnullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: false
type: string
notrequired_nullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: true
type: string
notrequired_notnullable_uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
nullable: false
type: string
required_nullable_array_of_string:
items:
type: string
nullable: true
type: array
required_notnullable_array_of_string:
items:
type: string
nullable: false
type: array
notrequired_nullable_array_of_string:
items:
type: string
nullable: true
type: array
notrequired_notnullable_array_of_string:
items:
type: string
nullable: false
type: array
required:
- required_not_nullable_date_prop
- required_notnullable_array_of_string
- required_notnullable_boolean_prop
- required_notnullable_datetime_prop
- required_notnullable_enum_integer
- required_notnullable_enum_integer_only
- required_notnullable_enum_string
- required_notnullable_outerEnumDefaultValue
- required_notnullable_string_prop
- required_notnullable_uuid
- required_notnullableinteger_prop
- required_nullable_array_of_string
- required_nullable_boolean_prop
- required_nullable_date_prop
- required_nullable_datetime_prop
- required_nullable_enum_integer
- required_nullable_enum_integer_only
- required_nullable_enum_string
- required_nullable_integer_prop
- required_nullable_outerEnumDefaultValue
- required_nullable_string_prop
- required_nullable_uuid
type: object
NullableClass: NullableClass:
additionalProperties: additionalProperties:
nullable: true nullable: true

View File

@ -4,6 +4,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Anytype1** | **Object** | | [optional]
**EmptyMap** | **Object** | an object with no declared properties and no undeclared properties, hence it&#39;s an empty map. | [optional] **EmptyMap** | **Object** | an object with no declared properties and no undeclared properties, hence it&#39;s an empty map. | [optional]
**MapOfMapProperty** | **Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;** | | [optional] **MapOfMapProperty** | **Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;** | | [optional]
**MapProperty** | **Dictionary&lt;string, string&gt;** | | [optional] **MapProperty** | **Dictionary&lt;string, string&gt;** | | [optional]
@ -11,7 +12,6 @@ Name | Type | Description | Notes
**MapWithUndeclaredPropertiesAnytype2** | **Object** | | [optional] **MapWithUndeclaredPropertiesAnytype2** | **Object** | | [optional]
**MapWithUndeclaredPropertiesAnytype3** | **Dictionary&lt;string, Object&gt;** | | [optional] **MapWithUndeclaredPropertiesAnytype3** | **Dictionary&lt;string, Object&gt;** | | [optional]
**MapWithUndeclaredPropertiesString** | **Dictionary&lt;string, string&gt;** | | [optional] **MapWithUndeclaredPropertiesString** | **Dictionary&lt;string, string&gt;** | | [optional]
**Anytype1** | **Object** | | [optional]
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

View File

@ -5,9 +5,9 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**MainShape** | [**Shape**](Shape.md) | | [optional] **MainShape** | [**Shape**](Shape.md) | | [optional]
**Shapes** | [**List&lt;Shape&gt;**](Shape.md) | | [optional]
**NullableShape** | [**NullableShape**](NullableShape.md) | | [optional] **NullableShape** | [**NullableShape**](NullableShape.md) | | [optional]
**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.md) | | [optional] **ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.md) | | [optional]
**Shapes** | [**List&lt;Shape&gt;**](Shape.md) | | [optional]
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

View File

@ -4,15 +4,15 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**EnumStringRequired** | **string** | |
**EnumInteger** | **int** | | [optional] **EnumInteger** | **int** | | [optional]
**EnumIntegerOnly** | **int** | | [optional] **EnumIntegerOnly** | **int** | | [optional]
**EnumNumber** | **double** | | [optional] **EnumNumber** | **double** | | [optional]
**EnumString** | **string** | | [optional] **EnumString** | **string** | | [optional]
**EnumStringRequired** | **string** | | **OuterEnum** | **OuterEnum** | | [optional]
**OuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional] **OuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**OuterEnumInteger** | **OuterEnumInteger** | | [optional] **OuterEnumInteger** | **OuterEnumInteger** | | [optional]
**OuterEnumIntegerDefaultValue** | **OuterEnumIntegerDefaultValue** | | [optional] **OuterEnumIntegerDefaultValue** | **OuterEnumIntegerDefaultValue** | | [optional]
**OuterEnum** | **OuterEnum** | | [optional]
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

View File

@ -4,9 +4,11 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Binary** | **System.IO.Stream** | | [optional]
**VarByte** | **byte[]** | | **VarByte** | **byte[]** | |
**Date** | **DateTime** | | **Date** | **DateTime** | |
**Number** | **decimal** | |
**Password** | **string** | |
**Binary** | **System.IO.Stream** | | [optional]
**DateTime** | **DateTime** | | [optional] **DateTime** | **DateTime** | | [optional]
**VarDecimal** | **decimal** | | [optional] **VarDecimal** | **decimal** | | [optional]
**VarDouble** | **double** | | [optional] **VarDouble** | **double** | | [optional]
@ -14,8 +16,6 @@ Name | Type | Description | Notes
**Int32** | **int** | | [optional] **Int32** | **int** | | [optional]
**Int64** | **long** | | [optional] **Int64** | **long** | | [optional]
**Integer** | **int** | | [optional] **Integer** | **int** | | [optional]
**Number** | **decimal** | |
**Password** | **string** | |
**PatternWithBackslash** | **string** | None | [optional] **PatternWithBackslash** | **string** | None | [optional]
**PatternWithDigits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional] **PatternWithDigits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional]
**PatternWithDigitsAndDelimiter** | **string** | A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01. | [optional] **PatternWithDigitsAndDelimiter** | **string** | A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01. | [optional]

View File

@ -4,9 +4,8 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**ArrayItemsNullable** | **List&lt;Object&gt;** | | [optional]
**ObjectItemsNullable** | **Dictionary&lt;string, Object&gt;** | | [optional]
**ArrayAndItemsNullableProp** | **List&lt;Object&gt;** | | [optional] **ArrayAndItemsNullableProp** | **List&lt;Object&gt;** | | [optional]
**ArrayItemsNullable** | **List&lt;Object&gt;** | | [optional]
**ArrayNullableProp** | **List&lt;Object&gt;** | | [optional] **ArrayNullableProp** | **List&lt;Object&gt;** | | [optional]
**BooleanProp** | **bool** | | [optional] **BooleanProp** | **bool** | | [optional]
**DateProp** | **DateTime** | | [optional] **DateProp** | **DateTime** | | [optional]
@ -14,6 +13,7 @@ Name | Type | Description | Notes
**IntegerProp** | **int** | | [optional] **IntegerProp** | **int** | | [optional]
**NumberProp** | **decimal** | | [optional] **NumberProp** | **decimal** | | [optional]
**ObjectAndItemsNullableProp** | **Dictionary&lt;string, Object&gt;** | | [optional] **ObjectAndItemsNullableProp** | **Dictionary&lt;string, Object&gt;** | | [optional]
**ObjectItemsNullable** | **Dictionary&lt;string, Object&gt;** | | [optional]
**ObjectNullableProp** | **Dictionary&lt;string, Object&gt;** | | [optional] **ObjectNullableProp** | **Dictionary&lt;string, Object&gt;** | | [optional]
**StringProp** | **string** | | [optional] **StringProp** | **string** | | [optional]

View File

@ -4,12 +4,12 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Complete** | **bool** | | [optional] [default to false]
**Id** | **long** | | [optional] **Id** | **long** | | [optional]
**PetId** | **long** | | [optional] **PetId** | **long** | | [optional]
**Quantity** | **int** | | [optional] **Quantity** | **int** | | [optional]
**ShipDate** | **DateTime** | | [optional] **ShipDate** | **DateTime** | | [optional]
**Status** | **string** | Order Status | [optional] **Status** | **string** | Order Status | [optional]
**Complete** | **bool** | | [optional] [default to false]
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

View File

@ -4,10 +4,10 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Category** | [**Category**](Category.md) | | [optional]
**Id** | **long** | | [optional]
**Name** | **string** | | **Name** | **string** | |
**PhotoUrls** | **List&lt;string&gt;** | | **PhotoUrls** | **List&lt;string&gt;** | |
**Category** | [**Category**](Category.md) | | [optional]
**Id** | **long** | | [optional]
**Status** | **string** | pet status in the store | [optional] **Status** | **string** | pet status in the store | [optional]
**Tags** | [**List&lt;Tag&gt;**](Tag.md) | | [optional] **Tags** | [**List&lt;Tag&gt;**](Tag.md) | | [optional]

View File

@ -0,0 +1,53 @@
# UseSourceGeneration.Model.RequiredClass
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**RequiredNotNullableDateProp** | **DateTime** | |
**RequiredNotnullableArrayOfString** | **List&lt;string&gt;** | |
**RequiredNotnullableBooleanProp** | **bool** | |
**RequiredNotnullableDatetimeProp** | **DateTime** | |
**RequiredNotnullableEnumInteger** | **int** | |
**RequiredNotnullableEnumIntegerOnly** | **int** | |
**RequiredNotnullableEnumString** | **string** | |
**RequiredNotnullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
**RequiredNotnullableStringProp** | **string** | |
**RequiredNotnullableUuid** | **Guid** | |
**RequiredNotnullableintegerProp** | **int** | |
**RequiredNullableArrayOfString** | **List&lt;string&gt;** | |
**RequiredNullableBooleanProp** | **bool** | |
**RequiredNullableDateProp** | **DateTime** | |
**RequiredNullableDatetimeProp** | **DateTime** | |
**RequiredNullableEnumInteger** | **int** | |
**RequiredNullableEnumIntegerOnly** | **int** | |
**RequiredNullableEnumString** | **string** | |
**RequiredNullableIntegerProp** | **int** | |
**RequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
**RequiredNullableStringProp** | **string** | |
**RequiredNullableUuid** | **Guid** | |
**NotRequiredNotnullableDateProp** | **DateTime** | | [optional]
**NotRequiredNotnullableintegerProp** | **int** | | [optional]
**NotRequiredNullableDateProp** | **DateTime** | | [optional]
**NotRequiredNullableIntegerProp** | **int** | | [optional]
**NotrequiredNotnullableArrayOfString** | **List&lt;string&gt;** | | [optional]
**NotrequiredNotnullableBooleanProp** | **bool** | | [optional]
**NotrequiredNotnullableDatetimeProp** | **DateTime** | | [optional]
**NotrequiredNotnullableEnumInteger** | **int** | | [optional]
**NotrequiredNotnullableEnumIntegerOnly** | **int** | | [optional]
**NotrequiredNotnullableEnumString** | **string** | | [optional]
**NotrequiredNotnullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**NotrequiredNotnullableStringProp** | **string** | | [optional]
**NotrequiredNotnullableUuid** | **Guid** | | [optional]
**NotrequiredNullableArrayOfString** | **List&lt;string&gt;** | | [optional]
**NotrequiredNullableBooleanProp** | **bool** | | [optional]
**NotrequiredNullableDatetimeProp** | **DateTime** | | [optional]
**NotrequiredNullableEnumInteger** | **int** | | [optional]
**NotrequiredNullableEnumIntegerOnly** | **int** | | [optional]
**NotrequiredNullableEnumString** | **string** | | [optional]
**NotrequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**NotrequiredNullableStringProp** | **string** | | [optional]
**NotrequiredNullableUuid** | **Guid** | | [optional]
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

View File

@ -4,18 +4,18 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**AnyTypeProp** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional]
**AnyTypePropNullable** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The &#39;nullable&#39; attribute does not change the allowed values. | [optional]
**Email** | **string** | | [optional] **Email** | **string** | | [optional]
**FirstName** | **string** | | [optional] **FirstName** | **string** | | [optional]
**Id** | **long** | | [optional] **Id** | **long** | | [optional]
**LastName** | **string** | | [optional] **LastName** | **string** | | [optional]
**ObjectWithNoDeclaredProps** | **Object** | test code generation for objects Value must be a map of strings to values. It cannot be the &#39;null&#39; value. | [optional] **ObjectWithNoDeclaredProps** | **Object** | test code generation for objects Value must be a map of strings to values. It cannot be the &#39;null&#39; value. | [optional]
**ObjectWithNoDeclaredPropsNullable** | **Object** | test code generation for nullable objects. Value must be a map of strings to values or the &#39;null&#39; value. | [optional]
**Password** | **string** | | [optional] **Password** | **string** | | [optional]
**Phone** | **string** | | [optional] **Phone** | **string** | | [optional]
**UserStatus** | **int** | User Status | [optional] **UserStatus** | **int** | User Status | [optional]
**Username** | **string** | | [optional] **Username** | **string** | | [optional]
**AnyTypeProp** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional]
**AnyTypePropNullable** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The &#39;nullable&#39; attribute does not change the allowed values. | [optional]
**ObjectWithNoDeclaredPropsNullable** | **Object** | test code generation for nullable objects. Value must be a map of strings to values or the &#39;null&#39; value. | [optional]
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

View File

@ -0,0 +1,452 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using Xunit;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using UseSourceGeneration.Model;
using UseSourceGeneration.Client;
using System.Reflection;
namespace UseSourceGeneration.Test.Model
{
/// <summary>
/// Class for testing RequiredClass
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
public class RequiredClassTests : IDisposable
{
// TODO uncomment below to declare an instance variable for RequiredClass
//private RequiredClass instance;
public RequiredClassTests()
{
// TODO uncomment below to create an instance of RequiredClass
//instance = new RequiredClass();
}
public void Dispose()
{
// Cleanup when everything is done.
}
/// <summary>
/// Test an instance of RequiredClass
/// </summary>
[Fact]
public void RequiredClassInstanceTest()
{
// TODO uncomment below to test "IsType" RequiredClass
//Assert.IsType<RequiredClass>(instance);
}
/// <summary>
/// Test the property 'RequiredNotNullableDateProp'
/// </summary>
[Fact]
public void RequiredNotNullableDatePropTest()
{
// TODO unit test for the property 'RequiredNotNullableDateProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableArrayOfString'
/// </summary>
[Fact]
public void RequiredNotnullableArrayOfStringTest()
{
// TODO unit test for the property 'RequiredNotnullableArrayOfString'
}
/// <summary>
/// Test the property 'RequiredNotnullableBooleanProp'
/// </summary>
[Fact]
public void RequiredNotnullableBooleanPropTest()
{
// TODO unit test for the property 'RequiredNotnullableBooleanProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableDatetimeProp'
/// </summary>
[Fact]
public void RequiredNotnullableDatetimePropTest()
{
// TODO unit test for the property 'RequiredNotnullableDatetimeProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableEnumInteger'
/// </summary>
[Fact]
public void RequiredNotnullableEnumIntegerTest()
{
// TODO unit test for the property 'RequiredNotnullableEnumInteger'
}
/// <summary>
/// Test the property 'RequiredNotnullableEnumIntegerOnly'
/// </summary>
[Fact]
public void RequiredNotnullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'RequiredNotnullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'RequiredNotnullableEnumString'
/// </summary>
[Fact]
public void RequiredNotnullableEnumStringTest()
{
// TODO unit test for the property 'RequiredNotnullableEnumString'
}
/// <summary>
/// Test the property 'RequiredNotnullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void RequiredNotnullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'RequiredNotnullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'RequiredNotnullableStringProp'
/// </summary>
[Fact]
public void RequiredNotnullableStringPropTest()
{
// TODO unit test for the property 'RequiredNotnullableStringProp'
}
/// <summary>
/// Test the property 'RequiredNotnullableUuid'
/// </summary>
[Fact]
public void RequiredNotnullableUuidTest()
{
// TODO unit test for the property 'RequiredNotnullableUuid'
}
/// <summary>
/// Test the property 'RequiredNotnullableintegerProp'
/// </summary>
[Fact]
public void RequiredNotnullableintegerPropTest()
{
// TODO unit test for the property 'RequiredNotnullableintegerProp'
}
/// <summary>
/// Test the property 'NotRequiredNotnullableDateProp'
/// </summary>
[Fact]
public void NotRequiredNotnullableDatePropTest()
{
// TODO unit test for the property 'NotRequiredNotnullableDateProp'
}
/// <summary>
/// Test the property 'NotRequiredNotnullableintegerProp'
/// </summary>
[Fact]
public void NotRequiredNotnullableintegerPropTest()
{
// TODO unit test for the property 'NotRequiredNotnullableintegerProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableArrayOfString'
/// </summary>
[Fact]
public void NotrequiredNotnullableArrayOfStringTest()
{
// TODO unit test for the property 'NotrequiredNotnullableArrayOfString'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableBooleanProp'
/// </summary>
[Fact]
public void NotrequiredNotnullableBooleanPropTest()
{
// TODO unit test for the property 'NotrequiredNotnullableBooleanProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableDatetimeProp'
/// </summary>
[Fact]
public void NotrequiredNotnullableDatetimePropTest()
{
// TODO unit test for the property 'NotrequiredNotnullableDatetimeProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableEnumInteger'
/// </summary>
[Fact]
public void NotrequiredNotnullableEnumIntegerTest()
{
// TODO unit test for the property 'NotrequiredNotnullableEnumInteger'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableEnumIntegerOnly'
/// </summary>
[Fact]
public void NotrequiredNotnullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'NotrequiredNotnullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableEnumString'
/// </summary>
[Fact]
public void NotrequiredNotnullableEnumStringTest()
{
// TODO unit test for the property 'NotrequiredNotnullableEnumString'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void NotrequiredNotnullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'NotrequiredNotnullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableStringProp'
/// </summary>
[Fact]
public void NotrequiredNotnullableStringPropTest()
{
// TODO unit test for the property 'NotrequiredNotnullableStringProp'
}
/// <summary>
/// Test the property 'NotrequiredNotnullableUuid'
/// </summary>
[Fact]
public void NotrequiredNotnullableUuidTest()
{
// TODO unit test for the property 'NotrequiredNotnullableUuid'
}
/// <summary>
/// Test the property 'RequiredNullableArrayOfString'
/// </summary>
[Fact]
public void RequiredNullableArrayOfStringTest()
{
// TODO unit test for the property 'RequiredNullableArrayOfString'
}
/// <summary>
/// Test the property 'RequiredNullableBooleanProp'
/// </summary>
[Fact]
public void RequiredNullableBooleanPropTest()
{
// TODO unit test for the property 'RequiredNullableBooleanProp'
}
/// <summary>
/// Test the property 'RequiredNullableDateProp'
/// </summary>
[Fact]
public void RequiredNullableDatePropTest()
{
// TODO unit test for the property 'RequiredNullableDateProp'
}
/// <summary>
/// Test the property 'RequiredNullableDatetimeProp'
/// </summary>
[Fact]
public void RequiredNullableDatetimePropTest()
{
// TODO unit test for the property 'RequiredNullableDatetimeProp'
}
/// <summary>
/// Test the property 'RequiredNullableEnumInteger'
/// </summary>
[Fact]
public void RequiredNullableEnumIntegerTest()
{
// TODO unit test for the property 'RequiredNullableEnumInteger'
}
/// <summary>
/// Test the property 'RequiredNullableEnumIntegerOnly'
/// </summary>
[Fact]
public void RequiredNullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'RequiredNullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'RequiredNullableEnumString'
/// </summary>
[Fact]
public void RequiredNullableEnumStringTest()
{
// TODO unit test for the property 'RequiredNullableEnumString'
}
/// <summary>
/// Test the property 'RequiredNullableIntegerProp'
/// </summary>
[Fact]
public void RequiredNullableIntegerPropTest()
{
// TODO unit test for the property 'RequiredNullableIntegerProp'
}
/// <summary>
/// Test the property 'RequiredNullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void RequiredNullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'RequiredNullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'RequiredNullableStringProp'
/// </summary>
[Fact]
public void RequiredNullableStringPropTest()
{
// TODO unit test for the property 'RequiredNullableStringProp'
}
/// <summary>
/// Test the property 'RequiredNullableUuid'
/// </summary>
[Fact]
public void RequiredNullableUuidTest()
{
// TODO unit test for the property 'RequiredNullableUuid'
}
/// <summary>
/// Test the property 'NotRequiredNullableDateProp'
/// </summary>
[Fact]
public void NotRequiredNullableDatePropTest()
{
// TODO unit test for the property 'NotRequiredNullableDateProp'
}
/// <summary>
/// Test the property 'NotRequiredNullableIntegerProp'
/// </summary>
[Fact]
public void NotRequiredNullableIntegerPropTest()
{
// TODO unit test for the property 'NotRequiredNullableIntegerProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableArrayOfString'
/// </summary>
[Fact]
public void NotrequiredNullableArrayOfStringTest()
{
// TODO unit test for the property 'NotrequiredNullableArrayOfString'
}
/// <summary>
/// Test the property 'NotrequiredNullableBooleanProp'
/// </summary>
[Fact]
public void NotrequiredNullableBooleanPropTest()
{
// TODO unit test for the property 'NotrequiredNullableBooleanProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableDatetimeProp'
/// </summary>
[Fact]
public void NotrequiredNullableDatetimePropTest()
{
// TODO unit test for the property 'NotrequiredNullableDatetimeProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableEnumInteger'
/// </summary>
[Fact]
public void NotrequiredNullableEnumIntegerTest()
{
// TODO unit test for the property 'NotrequiredNullableEnumInteger'
}
/// <summary>
/// Test the property 'NotrequiredNullableEnumIntegerOnly'
/// </summary>
[Fact]
public void NotrequiredNullableEnumIntegerOnlyTest()
{
// TODO unit test for the property 'NotrequiredNullableEnumIntegerOnly'
}
/// <summary>
/// Test the property 'NotrequiredNullableEnumString'
/// </summary>
[Fact]
public void NotrequiredNullableEnumStringTest()
{
// TODO unit test for the property 'NotrequiredNullableEnumString'
}
/// <summary>
/// Test the property 'NotrequiredNullableOuterEnumDefaultValue'
/// </summary>
[Fact]
public void NotrequiredNullableOuterEnumDefaultValueTest()
{
// TODO unit test for the property 'NotrequiredNullableOuterEnumDefaultValue'
}
/// <summary>
/// Test the property 'NotrequiredNullableStringProp'
/// </summary>
[Fact]
public void NotrequiredNullableStringPropTest()
{
// TODO unit test for the property 'NotrequiredNullableStringProp'
}
/// <summary>
/// Test the property 'NotrequiredNullableUuid'
/// </summary>
[Fact]
public void NotrequiredNullableUuidTest()
{
// TODO unit test for the property 'NotrequiredNullableUuid'
}
}
}

View File

@ -143,6 +143,8 @@ namespace UseSourceGeneration.Client
return EnumArrays.JustSymbolEnumToJsonValue(enumArraysJustSymbolEnum); return EnumArrays.JustSymbolEnumToJsonValue(enumArraysJustSymbolEnum);
if (obj is EnumClass enumClass) if (obj is EnumClass enumClass)
return EnumClassValueConverter.ToJsonValue(enumClass); return EnumClassValueConverter.ToJsonValue(enumClass);
if (obj is EnumTest.EnumStringRequiredEnum enumTestEnumStringRequiredEnum)
return EnumTest.EnumStringRequiredEnumToJsonValue(enumTestEnumStringRequiredEnum);
if (obj is EnumTest.EnumIntegerEnum enumTestEnumIntegerEnum) if (obj is EnumTest.EnumIntegerEnum enumTestEnumIntegerEnum)
return EnumTest.EnumIntegerEnumToJsonValue(enumTestEnumIntegerEnum).ToString(); return EnumTest.EnumIntegerEnumToJsonValue(enumTestEnumIntegerEnum).ToString();
if (obj is EnumTest.EnumIntegerOnlyEnum enumTestEnumIntegerOnlyEnum) if (obj is EnumTest.EnumIntegerOnlyEnum enumTestEnumIntegerOnlyEnum)
@ -151,8 +153,6 @@ namespace UseSourceGeneration.Client
return EnumTest.EnumNumberEnumToJsonValue(enumTestEnumNumberEnum).ToString(); return EnumTest.EnumNumberEnumToJsonValue(enumTestEnumNumberEnum).ToString();
if (obj is EnumTest.EnumStringEnum enumTestEnumStringEnum) if (obj is EnumTest.EnumStringEnum enumTestEnumStringEnum)
return EnumTest.EnumStringEnumToJsonValue(enumTestEnumStringEnum); return EnumTest.EnumStringEnumToJsonValue(enumTestEnumStringEnum);
if (obj is EnumTest.EnumStringRequiredEnum enumTestEnumStringRequiredEnum)
return EnumTest.EnumStringRequiredEnumToJsonValue(enumTestEnumStringRequiredEnum);
if (obj is MapTest.InnerEnum mapTestInnerEnum) if (obj is MapTest.InnerEnum mapTestInnerEnum)
return MapTest.InnerEnumToJsonValue(mapTestInnerEnum); return MapTest.InnerEnumToJsonValue(mapTestInnerEnum);
if (obj is Order.StatusEnum orderStatusEnum) if (obj is Order.StatusEnum orderStatusEnum)
@ -169,6 +169,30 @@ namespace UseSourceGeneration.Client
return OuterEnumTestValueConverter.ToJsonValue(outerEnumTest); return OuterEnumTestValueConverter.ToJsonValue(outerEnumTest);
if (obj is Pet.StatusEnum petStatusEnum) if (obj is Pet.StatusEnum petStatusEnum)
return Pet.StatusEnumToJsonValue(petStatusEnum); return Pet.StatusEnumToJsonValue(petStatusEnum);
if (obj is RequiredClass.RequiredNotnullableEnumIntegerEnum requiredClassRequiredNotnullableEnumIntegerEnum)
return RequiredClass.RequiredNotnullableEnumIntegerEnumToJsonValue(requiredClassRequiredNotnullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.RequiredNotnullableEnumIntegerOnlyEnum requiredClassRequiredNotnullableEnumIntegerOnlyEnum)
return RequiredClass.RequiredNotnullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNotnullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.RequiredNotnullableEnumStringEnum requiredClassRequiredNotnullableEnumStringEnum)
return RequiredClass.RequiredNotnullableEnumStringEnumToJsonValue(requiredClassRequiredNotnullableEnumStringEnum);
if (obj is RequiredClass.RequiredNullableEnumIntegerEnum requiredClassRequiredNullableEnumIntegerEnum)
return RequiredClass.RequiredNullableEnumIntegerEnumToJsonValue(requiredClassRequiredNullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.RequiredNullableEnumIntegerOnlyEnum requiredClassRequiredNullableEnumIntegerOnlyEnum)
return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum)
return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum);
if (obj is RequiredClass.NotrequiredNotnullableEnumIntegerEnum requiredClassNotrequiredNotnullableEnumIntegerEnum)
return RequiredClass.NotrequiredNotnullableEnumIntegerEnumToJsonValue(requiredClassNotrequiredNotnullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.NotrequiredNotnullableEnumIntegerOnlyEnum requiredClassNotrequiredNotnullableEnumIntegerOnlyEnum)
return RequiredClass.NotrequiredNotnullableEnumIntegerOnlyEnumToJsonValue(requiredClassNotrequiredNotnullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.NotrequiredNotnullableEnumStringEnum requiredClassNotrequiredNotnullableEnumStringEnum)
return RequiredClass.NotrequiredNotnullableEnumStringEnumToJsonValue(requiredClassNotrequiredNotnullableEnumStringEnum);
if (obj is RequiredClass.NotrequiredNullableEnumIntegerEnum requiredClassNotrequiredNullableEnumIntegerEnum)
return RequiredClass.NotrequiredNullableEnumIntegerEnumToJsonValue(requiredClassNotrequiredNullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.NotrequiredNullableEnumIntegerOnlyEnum requiredClassNotrequiredNullableEnumIntegerOnlyEnum)
return RequiredClass.NotrequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassNotrequiredNullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.NotrequiredNullableEnumStringEnum requiredClassNotrequiredNullableEnumStringEnum)
return RequiredClass.NotrequiredNullableEnumStringEnumToJsonValue(requiredClassNotrequiredNullableEnumStringEnum);
if (obj is Zebra.TypeEnum zebraTypeEnum) if (obj is Zebra.TypeEnum zebraTypeEnum)
return Zebra.TypeEnumToJsonValue(zebraTypeEnum); return Zebra.TypeEnumToJsonValue(zebraTypeEnum);
if (obj is ZeroBasedEnum zeroBasedEnum) if (obj is ZeroBasedEnum zeroBasedEnum)

View File

@ -116,6 +116,7 @@ namespace UseSourceGeneration.Client
_jsonOptions.Converters.Add(new QuadrilateralJsonConverter()); _jsonOptions.Converters.Add(new QuadrilateralJsonConverter());
_jsonOptions.Converters.Add(new QuadrilateralInterfaceJsonConverter()); _jsonOptions.Converters.Add(new QuadrilateralInterfaceJsonConverter());
_jsonOptions.Converters.Add(new ReadOnlyFirstJsonConverter()); _jsonOptions.Converters.Add(new ReadOnlyFirstJsonConverter());
_jsonOptions.Converters.Add(new RequiredClassJsonConverter());
_jsonOptions.Converters.Add(new ReturnJsonConverter()); _jsonOptions.Converters.Add(new ReturnJsonConverter());
_jsonOptions.Converters.Add(new RolesReportsHashJsonConverter()); _jsonOptions.Converters.Add(new RolesReportsHashJsonConverter());
_jsonOptions.Converters.Add(new RolesReportsHashRoleJsonConverter()); _jsonOptions.Converters.Add(new RolesReportsHashRoleJsonConverter());
@ -210,6 +211,7 @@ namespace UseSourceGeneration.Client
new QuadrilateralSerializationContext(), new QuadrilateralSerializationContext(),
new QuadrilateralInterfaceSerializationContext(), new QuadrilateralInterfaceSerializationContext(),
new ReadOnlyFirstSerializationContext(), new ReadOnlyFirstSerializationContext(),
new RequiredClassSerializationContext(),
new ReturnSerializationContext(), new ReturnSerializationContext(),
new RolesReportsHashSerializationContext(), new RolesReportsHashSerializationContext(),
new RolesReportsHashRoleSerializationContext(), new RolesReportsHashRoleSerializationContext(),

View File

@ -37,5 +37,17 @@ namespace UseSourceGeneration.Client
IsSet = true; IsSet = true;
Value = value; Value = value;
} }
/// <summary>
/// Implicitly converts this option to the contained type
/// </summary>
/// <param name="option"></param>
public static implicit operator TType(Option<TType> option) => option.Value;
/// <summary>
/// Implicitly converts the provided value to an Option
/// </summary>
/// <param name="value"></param>
public static implicit operator Option<TType>(TType value) => new Option<TType>(value);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="activityOutputs">activityOutputs</param> /// <param name="activityOutputs">activityOutputs</param>
[JsonConstructor] [JsonConstructor]
public Activity(Dictionary<string, List<ActivityOutputElementRepresentation>> activityOutputs) public Activity(Option<Dictionary<string, List<ActivityOutputElementRepresentation>>?> activityOutputs = default)
{ {
ActivityOutputs = activityOutputs; ActivityOutputsOption = activityOutputs;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of ActivityOutputs
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, List<ActivityOutputElementRepresentation>>?> ActivityOutputsOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ActivityOutputs /// Gets or Sets ActivityOutputs
/// </summary> /// </summary>
[JsonPropertyName("activity_outputs")] [JsonPropertyName("activity_outputs")]
public Dictionary<string, List<ActivityOutputElementRepresentation>> ActivityOutputs { get; set; } public Dictionary<string, List<ActivityOutputElementRepresentation>>? ActivityOutputs { get { return this. ActivityOutputsOption; } set { this.ActivityOutputsOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Dictionary<string, List<ActivityOutputElementRepresentation>>? activityOutputs = default; Option<Dictionary<string, List<ActivityOutputElementRepresentation>>?> activityOutputs = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
{ {
case "activity_outputs": case "activity_outputs":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
activityOutputs = JsonSerializer.Deserialize<Dictionary<string, List<ActivityOutputElementRepresentation>>>(ref utf8JsonReader, jsonSerializerOptions); activityOutputs = new Option<Dictionary<string, List<ActivityOutputElementRepresentation>>?>(JsonSerializer.Deserialize<Dictionary<string, List<ActivityOutputElementRepresentation>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -131,8 +138,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (activityOutputs == null) if (activityOutputs.IsSet && activityOutputs.Value == null)
throw new ArgumentNullException(nameof(activityOutputs), "Property is required for class Activity."); throw new ArgumentNullException(nameof(activityOutputs), "Property is not nullable for class Activity.");
return new Activity(activityOutputs); return new Activity(activityOutputs);
} }
@ -161,8 +168,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Activity activity, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Activity activity, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("activity_outputs"); if (activity.ActivityOutputsOption.IsSet && activity.ActivityOutputs == null)
JsonSerializer.Serialize(writer, activity.ActivityOutputs, jsonSerializerOptions); throw new ArgumentNullException(nameof(activity.ActivityOutputs), "Property is required for class Activity.");
if (activity.ActivityOutputsOption.IsSet)
{
writer.WritePropertyName("activity_outputs");
JsonSerializer.Serialize(writer, activity.ActivityOutputs, jsonSerializerOptions);
}
} }
} }

View File

@ -38,26 +38,40 @@ namespace UseSourceGeneration.Model
/// <param name="prop1">prop1</param> /// <param name="prop1">prop1</param>
/// <param name="prop2">prop2</param> /// <param name="prop2">prop2</param>
[JsonConstructor] [JsonConstructor]
public ActivityOutputElementRepresentation(string prop1, Object prop2) public ActivityOutputElementRepresentation(Option<string?> prop1 = default, Option<Object?> prop2 = default)
{ {
Prop1 = prop1; Prop1Option = prop1;
Prop2 = prop2; Prop2Option = prop2;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Prop1
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> Prop1Option { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Prop1 /// Gets or Sets Prop1
/// </summary> /// </summary>
[JsonPropertyName("prop1")] [JsonPropertyName("prop1")]
public string Prop1 { get; set; } public string? Prop1 { get { return this. Prop1Option; } set { this.Prop1Option = new(value); } }
/// <summary>
/// Used to track the state of Prop2
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Object?> Prop2Option { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Prop2 /// Gets or Sets Prop2
/// </summary> /// </summary>
[JsonPropertyName("prop2")] [JsonPropertyName("prop2")]
public Object Prop2 { get; set; } public Object? Prop2 { get { return this. Prop2Option; } set { this.Prop2Option = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -113,8 +127,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? prop1 = default; Option<string?> prop1 = default;
Object? prop2 = default; Option<Object?> prop2 = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -132,11 +146,11 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "prop1": case "prop1":
prop1 = utf8JsonReader.GetString(); prop1 = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "prop2": case "prop2":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
prop2 = JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions); prop2 = new Option<Object?>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -144,11 +158,11 @@ namespace UseSourceGeneration.Model
} }
} }
if (prop1 == null) if (prop1.IsSet && prop1.Value == null)
throw new ArgumentNullException(nameof(prop1), "Property is required for class ActivityOutputElementRepresentation."); throw new ArgumentNullException(nameof(prop1), "Property is not nullable for class ActivityOutputElementRepresentation.");
if (prop2 == null) if (prop2.IsSet && prop2.Value == null)
throw new ArgumentNullException(nameof(prop2), "Property is required for class ActivityOutputElementRepresentation."); throw new ArgumentNullException(nameof(prop2), "Property is not nullable for class ActivityOutputElementRepresentation.");
return new ActivityOutputElementRepresentation(prop1, prop2); return new ActivityOutputElementRepresentation(prop1, prop2);
} }
@ -177,9 +191,20 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ActivityOutputElementRepresentation activityOutputElementRepresentation, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ActivityOutputElementRepresentation activityOutputElementRepresentation, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("prop1", activityOutputElementRepresentation.Prop1); if (activityOutputElementRepresentation.Prop1Option.IsSet && activityOutputElementRepresentation.Prop1 == null)
writer.WritePropertyName("prop2"); throw new ArgumentNullException(nameof(activityOutputElementRepresentation.Prop1), "Property is required for class ActivityOutputElementRepresentation.");
JsonSerializer.Serialize(writer, activityOutputElementRepresentation.Prop2, jsonSerializerOptions);
if (activityOutputElementRepresentation.Prop2Option.IsSet && activityOutputElementRepresentation.Prop2 == null)
throw new ArgumentNullException(nameof(activityOutputElementRepresentation.Prop2), "Property is required for class ActivityOutputElementRepresentation.");
if (activityOutputElementRepresentation.Prop1Option.IsSet)
writer.WriteString("prop1", activityOutputElementRepresentation.Prop1);
if (activityOutputElementRepresentation.Prop2Option.IsSet)
{
writer.WritePropertyName("prop2");
JsonSerializer.Serialize(writer, activityOutputElementRepresentation.Prop2, jsonSerializerOptions);
}
} }
} }

View File

@ -35,6 +35,7 @@ namespace UseSourceGeneration.Model
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="AdditionalPropertiesClass" /> class. /// Initializes a new instance of the <see cref="AdditionalPropertiesClass" /> class.
/// </summary> /// </summary>
/// <param name="anytype1">anytype1</param>
/// <param name="emptyMap">an object with no declared properties and no undeclared properties, hence it&#39;s an empty map.</param> /// <param name="emptyMap">an object with no declared properties and no undeclared properties, hence it&#39;s an empty map.</param>
/// <param name="mapOfMapProperty">mapOfMapProperty</param> /// <param name="mapOfMapProperty">mapOfMapProperty</param>
/// <param name="mapProperty">mapProperty</param> /// <param name="mapProperty">mapProperty</param>
@ -42,71 +43,126 @@ namespace UseSourceGeneration.Model
/// <param name="mapWithUndeclaredPropertiesAnytype2">mapWithUndeclaredPropertiesAnytype2</param> /// <param name="mapWithUndeclaredPropertiesAnytype2">mapWithUndeclaredPropertiesAnytype2</param>
/// <param name="mapWithUndeclaredPropertiesAnytype3">mapWithUndeclaredPropertiesAnytype3</param> /// <param name="mapWithUndeclaredPropertiesAnytype3">mapWithUndeclaredPropertiesAnytype3</param>
/// <param name="mapWithUndeclaredPropertiesString">mapWithUndeclaredPropertiesString</param> /// <param name="mapWithUndeclaredPropertiesString">mapWithUndeclaredPropertiesString</param>
/// <param name="anytype1">anytype1</param>
[JsonConstructor] [JsonConstructor]
public AdditionalPropertiesClass(Object emptyMap, Dictionary<string, Dictionary<string, string>> mapOfMapProperty, Dictionary<string, string> mapProperty, Object mapWithUndeclaredPropertiesAnytype1, Object mapWithUndeclaredPropertiesAnytype2, Dictionary<string, Object> mapWithUndeclaredPropertiesAnytype3, Dictionary<string, string> mapWithUndeclaredPropertiesString, Object? anytype1 = default) public AdditionalPropertiesClass(Option<Object?> anytype1 = default, Option<Object?> emptyMap = default, Option<Dictionary<string, Dictionary<string, string>>?> mapOfMapProperty = default, Option<Dictionary<string, string>?> mapProperty = default, Option<Object?> mapWithUndeclaredPropertiesAnytype1 = default, Option<Object?> mapWithUndeclaredPropertiesAnytype2 = default, Option<Dictionary<string, Object>?> mapWithUndeclaredPropertiesAnytype3 = default, Option<Dictionary<string, string>?> mapWithUndeclaredPropertiesString = default)
{ {
EmptyMap = emptyMap; Anytype1Option = anytype1;
MapOfMapProperty = mapOfMapProperty; EmptyMapOption = emptyMap;
MapProperty = mapProperty; MapOfMapPropertyOption = mapOfMapProperty;
MapWithUndeclaredPropertiesAnytype1 = mapWithUndeclaredPropertiesAnytype1; MapPropertyOption = mapProperty;
MapWithUndeclaredPropertiesAnytype2 = mapWithUndeclaredPropertiesAnytype2; MapWithUndeclaredPropertiesAnytype1Option = mapWithUndeclaredPropertiesAnytype1;
MapWithUndeclaredPropertiesAnytype3 = mapWithUndeclaredPropertiesAnytype3; MapWithUndeclaredPropertiesAnytype2Option = mapWithUndeclaredPropertiesAnytype2;
MapWithUndeclaredPropertiesString = mapWithUndeclaredPropertiesString; MapWithUndeclaredPropertiesAnytype3Option = mapWithUndeclaredPropertiesAnytype3;
Anytype1 = anytype1; MapWithUndeclaredPropertiesStringOption = mapWithUndeclaredPropertiesString;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary> /// <summary>
/// an object with no declared properties and no undeclared properties, hence it&#39;s an empty map. /// Used to track the state of Anytype1
/// </summary> /// </summary>
/// <value>an object with no declared properties and no undeclared properties, hence it&#39;s an empty map.</value> [JsonIgnore]
[JsonPropertyName("empty_map")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Object EmptyMap { get; set; } public Option<Object?> Anytype1Option { get; private set; }
/// <summary>
/// Gets or Sets MapOfMapProperty
/// </summary>
[JsonPropertyName("map_of_map_property")]
public Dictionary<string, Dictionary<string, string>> MapOfMapProperty { get; set; }
/// <summary>
/// Gets or Sets MapProperty
/// </summary>
[JsonPropertyName("map_property")]
public Dictionary<string, string> MapProperty { get; set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesAnytype1
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_anytype_1")]
public Object MapWithUndeclaredPropertiesAnytype1 { get; set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesAnytype2
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_anytype_2")]
public Object MapWithUndeclaredPropertiesAnytype2 { get; set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesAnytype3
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_anytype_3")]
public Dictionary<string, Object> MapWithUndeclaredPropertiesAnytype3 { get; set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesString
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_string")]
public Dictionary<string, string> MapWithUndeclaredPropertiesString { get; set; }
/// <summary> /// <summary>
/// Gets or Sets Anytype1 /// Gets or Sets Anytype1
/// </summary> /// </summary>
[JsonPropertyName("anytype_1")] [JsonPropertyName("anytype_1")]
public Object? Anytype1 { get; set; } public Object? Anytype1 { get { return this. Anytype1Option; } set { this.Anytype1Option = new(value); } }
/// <summary>
/// Used to track the state of EmptyMap
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Object?> EmptyMapOption { get; private set; }
/// <summary>
/// an object with no declared properties and no undeclared properties, hence it&#39;s an empty map.
/// </summary>
/// <value>an object with no declared properties and no undeclared properties, hence it&#39;s an empty map.</value>
[JsonPropertyName("empty_map")]
public Object? EmptyMap { get { return this. EmptyMapOption; } set { this.EmptyMapOption = new(value); } }
/// <summary>
/// Used to track the state of MapOfMapProperty
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Dictionary<string, string>>?> MapOfMapPropertyOption { get; private set; }
/// <summary>
/// Gets or Sets MapOfMapProperty
/// </summary>
[JsonPropertyName("map_of_map_property")]
public Dictionary<string, Dictionary<string, string>>? MapOfMapProperty { get { return this. MapOfMapPropertyOption; } set { this.MapOfMapPropertyOption = new(value); } }
/// <summary>
/// Used to track the state of MapProperty
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, string>?> MapPropertyOption { get; private set; }
/// <summary>
/// Gets or Sets MapProperty
/// </summary>
[JsonPropertyName("map_property")]
public Dictionary<string, string>? MapProperty { get { return this. MapPropertyOption; } set { this.MapPropertyOption = new(value); } }
/// <summary>
/// Used to track the state of MapWithUndeclaredPropertiesAnytype1
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Object?> MapWithUndeclaredPropertiesAnytype1Option { get; private set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesAnytype1
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_anytype_1")]
public Object? MapWithUndeclaredPropertiesAnytype1 { get { return this. MapWithUndeclaredPropertiesAnytype1Option; } set { this.MapWithUndeclaredPropertiesAnytype1Option = new(value); } }
/// <summary>
/// Used to track the state of MapWithUndeclaredPropertiesAnytype2
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Object?> MapWithUndeclaredPropertiesAnytype2Option { get; private set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesAnytype2
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_anytype_2")]
public Object? MapWithUndeclaredPropertiesAnytype2 { get { return this. MapWithUndeclaredPropertiesAnytype2Option; } set { this.MapWithUndeclaredPropertiesAnytype2Option = new(value); } }
/// <summary>
/// Used to track the state of MapWithUndeclaredPropertiesAnytype3
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Object>?> MapWithUndeclaredPropertiesAnytype3Option { get; private set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesAnytype3
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_anytype_3")]
public Dictionary<string, Object>? MapWithUndeclaredPropertiesAnytype3 { get { return this. MapWithUndeclaredPropertiesAnytype3Option; } set { this.MapWithUndeclaredPropertiesAnytype3Option = new(value); } }
/// <summary>
/// Used to track the state of MapWithUndeclaredPropertiesString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, string>?> MapWithUndeclaredPropertiesStringOption { get; private set; }
/// <summary>
/// Gets or Sets MapWithUndeclaredPropertiesString
/// </summary>
[JsonPropertyName("map_with_undeclared_properties_string")]
public Dictionary<string, string>? MapWithUndeclaredPropertiesString { get { return this. MapWithUndeclaredPropertiesStringOption; } set { this.MapWithUndeclaredPropertiesStringOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -122,6 +178,7 @@ namespace UseSourceGeneration.Model
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("class AdditionalPropertiesClass {\n"); sb.Append("class AdditionalPropertiesClass {\n");
sb.Append(" Anytype1: ").Append(Anytype1).Append("\n");
sb.Append(" EmptyMap: ").Append(EmptyMap).Append("\n"); sb.Append(" EmptyMap: ").Append(EmptyMap).Append("\n");
sb.Append(" MapOfMapProperty: ").Append(MapOfMapProperty).Append("\n"); sb.Append(" MapOfMapProperty: ").Append(MapOfMapProperty).Append("\n");
sb.Append(" MapProperty: ").Append(MapProperty).Append("\n"); sb.Append(" MapProperty: ").Append(MapProperty).Append("\n");
@ -129,7 +186,6 @@ namespace UseSourceGeneration.Model
sb.Append(" MapWithUndeclaredPropertiesAnytype2: ").Append(MapWithUndeclaredPropertiesAnytype2).Append("\n"); sb.Append(" MapWithUndeclaredPropertiesAnytype2: ").Append(MapWithUndeclaredPropertiesAnytype2).Append("\n");
sb.Append(" MapWithUndeclaredPropertiesAnytype3: ").Append(MapWithUndeclaredPropertiesAnytype3).Append("\n"); sb.Append(" MapWithUndeclaredPropertiesAnytype3: ").Append(MapWithUndeclaredPropertiesAnytype3).Append("\n");
sb.Append(" MapWithUndeclaredPropertiesString: ").Append(MapWithUndeclaredPropertiesString).Append("\n"); sb.Append(" MapWithUndeclaredPropertiesString: ").Append(MapWithUndeclaredPropertiesString).Append("\n");
sb.Append(" Anytype1: ").Append(Anytype1).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append("}\n"); sb.Append("}\n");
return sb.ToString(); return sb.ToString();
@ -168,14 +224,14 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Object? emptyMap = default; Option<Object?> anytype1 = default;
Dictionary<string, Dictionary<string, string>>? mapOfMapProperty = default; Option<Object?> emptyMap = default;
Dictionary<string, string>? mapProperty = default; Option<Dictionary<string, Dictionary<string, string>>?> mapOfMapProperty = default;
Object? mapWithUndeclaredPropertiesAnytype1 = default; Option<Dictionary<string, string>?> mapProperty = default;
Object? mapWithUndeclaredPropertiesAnytype2 = default; Option<Object?> mapWithUndeclaredPropertiesAnytype1 = default;
Dictionary<string, Object>? mapWithUndeclaredPropertiesAnytype3 = default; Option<Object?> mapWithUndeclaredPropertiesAnytype2 = default;
Dictionary<string, string>? mapWithUndeclaredPropertiesString = default; Option<Dictionary<string, Object>?> mapWithUndeclaredPropertiesAnytype3 = default;
Object? anytype1 = default; Option<Dictionary<string, string>?> mapWithUndeclaredPropertiesString = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -192,37 +248,37 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "anytype_1":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
anytype1 = new Option<Object?>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "empty_map": case "empty_map":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
emptyMap = JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions); emptyMap = new Option<Object?>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_of_map_property": case "map_of_map_property":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapOfMapProperty = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(ref utf8JsonReader, jsonSerializerOptions); mapOfMapProperty = new Option<Dictionary<string, Dictionary<string, string>>?>(JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_property": case "map_property":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapProperty = JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions); mapProperty = new Option<Dictionary<string, string>?>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_with_undeclared_properties_anytype_1": case "map_with_undeclared_properties_anytype_1":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapWithUndeclaredPropertiesAnytype1 = JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions); mapWithUndeclaredPropertiesAnytype1 = new Option<Object?>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_with_undeclared_properties_anytype_2": case "map_with_undeclared_properties_anytype_2":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapWithUndeclaredPropertiesAnytype2 = JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions); mapWithUndeclaredPropertiesAnytype2 = new Option<Object?>(JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_with_undeclared_properties_anytype_3": case "map_with_undeclared_properties_anytype_3":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapWithUndeclaredPropertiesAnytype3 = JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions); mapWithUndeclaredPropertiesAnytype3 = new Option<Dictionary<string, Object>?>(JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_with_undeclared_properties_string": case "map_with_undeclared_properties_string":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapWithUndeclaredPropertiesString = JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions); mapWithUndeclaredPropertiesString = new Option<Dictionary<string, string>?>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions)!);
break;
case "anytype_1":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
anytype1 = JsonSerializer.Deserialize<Object>(ref utf8JsonReader, jsonSerializerOptions);
break; break;
default: default:
break; break;
@ -230,28 +286,28 @@ namespace UseSourceGeneration.Model
} }
} }
if (emptyMap == null) if (emptyMap.IsSet && emptyMap.Value == null)
throw new ArgumentNullException(nameof(emptyMap), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(emptyMap), "Property is not nullable for class AdditionalPropertiesClass.");
if (mapOfMapProperty == null) if (mapOfMapProperty.IsSet && mapOfMapProperty.Value == null)
throw new ArgumentNullException(nameof(mapOfMapProperty), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(mapOfMapProperty), "Property is not nullable for class AdditionalPropertiesClass.");
if (mapProperty == null) if (mapProperty.IsSet && mapProperty.Value == null)
throw new ArgumentNullException(nameof(mapProperty), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(mapProperty), "Property is not nullable for class AdditionalPropertiesClass.");
if (mapWithUndeclaredPropertiesAnytype1 == null) if (mapWithUndeclaredPropertiesAnytype1.IsSet && mapWithUndeclaredPropertiesAnytype1.Value == null)
throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesAnytype1), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesAnytype1), "Property is not nullable for class AdditionalPropertiesClass.");
if (mapWithUndeclaredPropertiesAnytype2 == null) if (mapWithUndeclaredPropertiesAnytype2.IsSet && mapWithUndeclaredPropertiesAnytype2.Value == null)
throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesAnytype2), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesAnytype2), "Property is not nullable for class AdditionalPropertiesClass.");
if (mapWithUndeclaredPropertiesAnytype3 == null) if (mapWithUndeclaredPropertiesAnytype3.IsSet && mapWithUndeclaredPropertiesAnytype3.Value == null)
throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesAnytype3), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesAnytype3), "Property is not nullable for class AdditionalPropertiesClass.");
if (mapWithUndeclaredPropertiesString == null) if (mapWithUndeclaredPropertiesString.IsSet && mapWithUndeclaredPropertiesString.Value == null)
throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesString), "Property is required for class AdditionalPropertiesClass."); throw new ArgumentNullException(nameof(mapWithUndeclaredPropertiesString), "Property is not nullable for class AdditionalPropertiesClass.");
return new AdditionalPropertiesClass(emptyMap, mapOfMapProperty, mapProperty, mapWithUndeclaredPropertiesAnytype1, mapWithUndeclaredPropertiesAnytype2, mapWithUndeclaredPropertiesAnytype3, mapWithUndeclaredPropertiesString, anytype1); return new AdditionalPropertiesClass(anytype1, emptyMap, mapOfMapProperty, mapProperty, mapWithUndeclaredPropertiesAnytype1, mapWithUndeclaredPropertiesAnytype2, mapWithUndeclaredPropertiesAnytype3, mapWithUndeclaredPropertiesString);
} }
/// <summary> /// <summary>
@ -278,22 +334,70 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, AdditionalPropertiesClass additionalPropertiesClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, AdditionalPropertiesClass additionalPropertiesClass, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("empty_map"); if (additionalPropertiesClass.EmptyMapOption.IsSet && additionalPropertiesClass.EmptyMap == null)
JsonSerializer.Serialize(writer, additionalPropertiesClass.EmptyMap, jsonSerializerOptions); throw new ArgumentNullException(nameof(additionalPropertiesClass.EmptyMap), "Property is required for class AdditionalPropertiesClass.");
writer.WritePropertyName("map_of_map_property");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapOfMapProperty, jsonSerializerOptions); if (additionalPropertiesClass.MapOfMapPropertyOption.IsSet && additionalPropertiesClass.MapOfMapProperty == null)
writer.WritePropertyName("map_property"); throw new ArgumentNullException(nameof(additionalPropertiesClass.MapOfMapProperty), "Property is required for class AdditionalPropertiesClass.");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapProperty, jsonSerializerOptions);
writer.WritePropertyName("map_with_undeclared_properties_anytype_1"); if (additionalPropertiesClass.MapPropertyOption.IsSet && additionalPropertiesClass.MapProperty == null)
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype1, jsonSerializerOptions); throw new ArgumentNullException(nameof(additionalPropertiesClass.MapProperty), "Property is required for class AdditionalPropertiesClass.");
writer.WritePropertyName("map_with_undeclared_properties_anytype_2");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype2, jsonSerializerOptions); if (additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype1Option.IsSet && additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype1 == null)
writer.WritePropertyName("map_with_undeclared_properties_anytype_3"); throw new ArgumentNullException(nameof(additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype1), "Property is required for class AdditionalPropertiesClass.");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype3, jsonSerializerOptions);
writer.WritePropertyName("map_with_undeclared_properties_string"); if (additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype2Option.IsSet && additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype2 == null)
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesString, jsonSerializerOptions); throw new ArgumentNullException(nameof(additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype2), "Property is required for class AdditionalPropertiesClass.");
writer.WritePropertyName("anytype_1");
JsonSerializer.Serialize(writer, additionalPropertiesClass.Anytype1, jsonSerializerOptions); if (additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype3Option.IsSet && additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype3 == null)
throw new ArgumentNullException(nameof(additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype3), "Property is required for class AdditionalPropertiesClass.");
if (additionalPropertiesClass.MapWithUndeclaredPropertiesStringOption.IsSet && additionalPropertiesClass.MapWithUndeclaredPropertiesString == null)
throw new ArgumentNullException(nameof(additionalPropertiesClass.MapWithUndeclaredPropertiesString), "Property is required for class AdditionalPropertiesClass.");
if (additionalPropertiesClass.Anytype1Option.IsSet)
if (additionalPropertiesClass.Anytype1Option.Value != null)
{
writer.WritePropertyName("anytype_1");
JsonSerializer.Serialize(writer, additionalPropertiesClass.Anytype1, jsonSerializerOptions);
}
else
writer.WriteNull("anytype_1");
if (additionalPropertiesClass.EmptyMapOption.IsSet)
{
writer.WritePropertyName("empty_map");
JsonSerializer.Serialize(writer, additionalPropertiesClass.EmptyMap, jsonSerializerOptions);
}
if (additionalPropertiesClass.MapOfMapPropertyOption.IsSet)
{
writer.WritePropertyName("map_of_map_property");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapOfMapProperty, jsonSerializerOptions);
}
if (additionalPropertiesClass.MapPropertyOption.IsSet)
{
writer.WritePropertyName("map_property");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapProperty, jsonSerializerOptions);
}
if (additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype1Option.IsSet)
{
writer.WritePropertyName("map_with_undeclared_properties_anytype_1");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype1, jsonSerializerOptions);
}
if (additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype2Option.IsSet)
{
writer.WritePropertyName("map_with_undeclared_properties_anytype_2");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype2, jsonSerializerOptions);
}
if (additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype3Option.IsSet)
{
writer.WritePropertyName("map_with_undeclared_properties_anytype_3");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesAnytype3, jsonSerializerOptions);
}
if (additionalPropertiesClass.MapWithUndeclaredPropertiesStringOption.IsSet)
{
writer.WritePropertyName("map_with_undeclared_properties_string");
JsonSerializer.Serialize(writer, additionalPropertiesClass.MapWithUndeclaredPropertiesString, jsonSerializerOptions);
}
} }
} }

View File

@ -38,10 +38,10 @@ namespace UseSourceGeneration.Model
/// <param name="className">className</param> /// <param name="className">className</param>
/// <param name="color">color (default to &quot;red&quot;)</param> /// <param name="color">color (default to &quot;red&quot;)</param>
[JsonConstructor] [JsonConstructor]
public Animal(string className, string color = @"red") public Animal(string className, Option<string?> color = default)
{ {
ClassName = className; ClassName = className;
Color = color; ColorOption = color;
OnCreated(); OnCreated();
} }
@ -53,11 +53,18 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("className")] [JsonPropertyName("className")]
public string ClassName { get; set; } public string ClassName { get; set; }
/// <summary>
/// Used to track the state of Color
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> ColorOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Color /// Gets or Sets Color
/// </summary> /// </summary>
[JsonPropertyName("color")] [JsonPropertyName("color")]
public string Color { get; set; } public string? Color { get { return this. ColorOption; } set { this.ColorOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -123,8 +130,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? className = default; Option<string?> className = default;
string? color = default; Option<string?> color = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -142,10 +149,10 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "color": case "color":
color = utf8JsonReader.GetString(); color = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -153,13 +160,16 @@ namespace UseSourceGeneration.Model
} }
} }
if (className == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(className), "Property is required for class Animal."); throw new ArgumentException("Property is required for class Animal.", nameof(className));
if (color == null) if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(color), "Property is required for class Animal."); throw new ArgumentNullException(nameof(className), "Property is not nullable for class Animal.");
return new Animal(className, color); if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is not nullable for class Animal.");
return new Animal(className.Value!, color);
} }
/// <summary> /// <summary>
@ -186,8 +196,16 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Animal animal, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Animal animal, JsonSerializerOptions jsonSerializerOptions)
{ {
if (animal.ClassName == null)
throw new ArgumentNullException(nameof(animal.ClassName), "Property is required for class Animal.");
if (animal.ColorOption.IsSet && animal.Color == null)
throw new ArgumentNullException(nameof(animal.Color), "Property is required for class Animal.");
writer.WriteString("className", animal.ClassName); writer.WriteString("className", animal.ClassName);
writer.WriteString("color", animal.Color);
if (animal.ColorOption.IsSet)
writer.WriteString("color", animal.Color);
} }
} }

View File

@ -39,33 +39,54 @@ namespace UseSourceGeneration.Model
/// <param name="message">message</param> /// <param name="message">message</param>
/// <param name="type">type</param> /// <param name="type">type</param>
[JsonConstructor] [JsonConstructor]
public ApiResponse(int code, string message, string type) public ApiResponse(Option<int?> code = default, Option<string?> message = default, Option<string?> type = default)
{ {
Code = code; CodeOption = code;
Message = message; MessageOption = message;
Type = type; TypeOption = type;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Code
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> CodeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Code /// Gets or Sets Code
/// </summary> /// </summary>
[JsonPropertyName("code")] [JsonPropertyName("code")]
public int Code { get; set; } public int? Code { get { return this. CodeOption; } set { this.CodeOption = new(value); } }
/// <summary>
/// Used to track the state of Message
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> MessageOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Message /// Gets or Sets Message
/// </summary> /// </summary>
[JsonPropertyName("message")] [JsonPropertyName("message")]
public string Message { get; set; } public string? Message { get { return this. MessageOption; } set { this.MessageOption = new(value); } }
/// <summary>
/// Used to track the state of Type
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> TypeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Type /// Gets or Sets Type
/// </summary> /// </summary>
[JsonPropertyName("type")] [JsonPropertyName("type")]
public string Type { get; set; } public string? Type { get { return this. TypeOption; } set { this.TypeOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -122,9 +143,9 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
int? code = default; Option<int?> code = default;
string? message = default; Option<string?> message = default;
string? type = default; Option<string?> type = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -143,13 +164,13 @@ namespace UseSourceGeneration.Model
{ {
case "code": case "code":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
code = utf8JsonReader.GetInt32(); code = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
case "message": case "message":
message = utf8JsonReader.GetString(); message = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "type": case "type":
type = utf8JsonReader.GetString(); type = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -157,16 +178,16 @@ namespace UseSourceGeneration.Model
} }
} }
if (code == null) if (code.IsSet && code.Value == null)
throw new ArgumentNullException(nameof(code), "Property is required for class ApiResponse."); throw new ArgumentNullException(nameof(code), "Property is not nullable for class ApiResponse.");
if (message == null) if (message.IsSet && message.Value == null)
throw new ArgumentNullException(nameof(message), "Property is required for class ApiResponse."); throw new ArgumentNullException(nameof(message), "Property is not nullable for class ApiResponse.");
if (type == null) if (type.IsSet && type.Value == null)
throw new ArgumentNullException(nameof(type), "Property is required for class ApiResponse."); throw new ArgumentNullException(nameof(type), "Property is not nullable for class ApiResponse.");
return new ApiResponse(code.Value, message, type); return new ApiResponse(code, message, type);
} }
/// <summary> /// <summary>
@ -193,9 +214,20 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ApiResponse apiResponse, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ApiResponse apiResponse, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteNumber("code", apiResponse.Code); if (apiResponse.MessageOption.IsSet && apiResponse.Message == null)
writer.WriteString("message", apiResponse.Message); throw new ArgumentNullException(nameof(apiResponse.Message), "Property is required for class ApiResponse.");
writer.WriteString("type", apiResponse.Type);
if (apiResponse.TypeOption.IsSet && apiResponse.Type == null)
throw new ArgumentNullException(nameof(apiResponse.Type), "Property is required for class ApiResponse.");
if (apiResponse.CodeOption.IsSet)
writer.WriteNumber("code", apiResponse.CodeOption.Value!.Value);
if (apiResponse.MessageOption.IsSet)
writer.WriteString("message", apiResponse.Message);
if (apiResponse.TypeOption.IsSet)
writer.WriteString("type", apiResponse.Type);
} }
} }

View File

@ -39,33 +39,54 @@ namespace UseSourceGeneration.Model
/// <param name="cultivar">cultivar</param> /// <param name="cultivar">cultivar</param>
/// <param name="origin">origin</param> /// <param name="origin">origin</param>
[JsonConstructor] [JsonConstructor]
public Apple(string colorCode, string cultivar, string origin) public Apple(Option<string?> colorCode = default, Option<string?> cultivar = default, Option<string?> origin = default)
{ {
ColorCode = colorCode; ColorCodeOption = colorCode;
Cultivar = cultivar; CultivarOption = cultivar;
Origin = origin; OriginOption = origin;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of ColorCode
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> ColorCodeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ColorCode /// Gets or Sets ColorCode
/// </summary> /// </summary>
[JsonPropertyName("color_code")] [JsonPropertyName("color_code")]
public string ColorCode { get; set; } public string? ColorCode { get { return this. ColorCodeOption; } set { this.ColorCodeOption = new(value); } }
/// <summary>
/// Used to track the state of Cultivar
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> CultivarOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Cultivar /// Gets or Sets Cultivar
/// </summary> /// </summary>
[JsonPropertyName("cultivar")] [JsonPropertyName("cultivar")]
public string Cultivar { get; set; } public string? Cultivar { get { return this. CultivarOption; } set { this.CultivarOption = new(value); } }
/// <summary>
/// Used to track the state of Origin
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> OriginOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Origin /// Gets or Sets Origin
/// </summary> /// </summary>
[JsonPropertyName("origin")] [JsonPropertyName("origin")]
public string Origin { get; set; } public string? Origin { get { return this. OriginOption; } set { this.OriginOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -96,28 +117,31 @@ namespace UseSourceGeneration.Model
/// <returns>Validation Result</returns> /// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{ {
if (this.ColorCode != null) { if (this.ColorCodeOption.Value != null) {
// ColorCode (string) pattern // ColorCode (string) pattern
Regex regexColorCode = new Regex(@"^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$", RegexOptions.CultureInvariant); Regex regexColorCode = new Regex(@"^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$", RegexOptions.CultureInvariant);
if (!regexColorCode.Match(this.ColorCode).Success)
if (this.ColorCodeOption.Value != null &&!regexColorCode.Match(this.ColorCodeOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for ColorCode, must match a pattern of " + regexColorCode, new [] { "ColorCode" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for ColorCode, must match a pattern of " + regexColorCode, new [] { "ColorCode" });
} }
} }
if (this.Cultivar != null) { if (this.CultivarOption.Value != null) {
// Cultivar (string) pattern // Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\s]*$", RegexOptions.CultureInvariant); Regex regexCultivar = new Regex(@"^[a-zA-Z\s]*$", RegexOptions.CultureInvariant);
if (!regexCultivar.Match(this.Cultivar).Success)
if (this.CultivarOption.Value != null &&!regexCultivar.Match(this.CultivarOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
} }
} }
if (this.Origin != null) { if (this.OriginOption.Value != null) {
// Origin (string) pattern // Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); Regex regexOrigin = new Regex(@"^[A-Z\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (!regexOrigin.Match(this.Origin).Success)
if (this.OriginOption.Value != null &&!regexOrigin.Match(this.OriginOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
} }
@ -149,9 +173,9 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? colorCode = default; Option<string?> colorCode = default;
string? cultivar = default; Option<string?> cultivar = default;
string? origin = default; Option<string?> origin = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -169,13 +193,13 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "color_code": case "color_code":
colorCode = utf8JsonReader.GetString(); colorCode = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "cultivar": case "cultivar":
cultivar = utf8JsonReader.GetString(); cultivar = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "origin": case "origin":
origin = utf8JsonReader.GetString(); origin = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -183,14 +207,14 @@ namespace UseSourceGeneration.Model
} }
} }
if (colorCode == null) if (colorCode.IsSet && colorCode.Value == null)
throw new ArgumentNullException(nameof(colorCode), "Property is required for class Apple."); throw new ArgumentNullException(nameof(colorCode), "Property is not nullable for class Apple.");
if (cultivar == null) if (cultivar.IsSet && cultivar.Value == null)
throw new ArgumentNullException(nameof(cultivar), "Property is required for class Apple."); throw new ArgumentNullException(nameof(cultivar), "Property is not nullable for class Apple.");
if (origin == null) if (origin.IsSet && origin.Value == null)
throw new ArgumentNullException(nameof(origin), "Property is required for class Apple."); throw new ArgumentNullException(nameof(origin), "Property is not nullable for class Apple.");
return new Apple(colorCode, cultivar, origin); return new Apple(colorCode, cultivar, origin);
} }
@ -219,9 +243,23 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Apple apple, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Apple apple, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("color_code", apple.ColorCode); if (apple.ColorCodeOption.IsSet && apple.ColorCode == null)
writer.WriteString("cultivar", apple.Cultivar); throw new ArgumentNullException(nameof(apple.ColorCode), "Property is required for class Apple.");
writer.WriteString("origin", apple.Origin);
if (apple.CultivarOption.IsSet && apple.Cultivar == null)
throw new ArgumentNullException(nameof(apple.Cultivar), "Property is required for class Apple.");
if (apple.OriginOption.IsSet && apple.Origin == null)
throw new ArgumentNullException(nameof(apple.Origin), "Property is required for class Apple.");
if (apple.ColorCodeOption.IsSet)
writer.WriteString("color_code", apple.ColorCode);
if (apple.CultivarOption.IsSet)
writer.WriteString("cultivar", apple.Cultivar);
if (apple.OriginOption.IsSet)
writer.WriteString("origin", apple.Origin);
} }
} }

View File

@ -38,10 +38,10 @@ namespace UseSourceGeneration.Model
/// <param name="cultivar">cultivar</param> /// <param name="cultivar">cultivar</param>
/// <param name="mealy">mealy</param> /// <param name="mealy">mealy</param>
[JsonConstructor] [JsonConstructor]
public AppleReq(string cultivar, bool mealy) public AppleReq(string cultivar, Option<bool?> mealy = default)
{ {
Cultivar = cultivar; Cultivar = cultivar;
Mealy = mealy; MealyOption = mealy;
OnCreated(); OnCreated();
} }
@ -53,11 +53,18 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("cultivar")] [JsonPropertyName("cultivar")]
public string Cultivar { get; set; } public string Cultivar { get; set; }
/// <summary>
/// Used to track the state of Mealy
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<bool?> MealyOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Mealy /// Gets or Sets Mealy
/// </summary> /// </summary>
[JsonPropertyName("mealy")] [JsonPropertyName("mealy")]
public bool Mealy { get; set; } public bool? Mealy { get { return this. MealyOption; } set { this.MealyOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -106,8 +113,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? cultivar = default; Option<string?> cultivar = default;
bool? mealy = default; Option<bool?> mealy = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -125,11 +132,11 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "cultivar": case "cultivar":
cultivar = utf8JsonReader.GetString(); cultivar = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "mealy": case "mealy":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mealy = utf8JsonReader.GetBoolean(); mealy = new Option<bool?>(utf8JsonReader.GetBoolean());
break; break;
default: default:
break; break;
@ -137,13 +144,16 @@ namespace UseSourceGeneration.Model
} }
} }
if (cultivar == null) if (!cultivar.IsSet)
throw new ArgumentNullException(nameof(cultivar), "Property is required for class AppleReq."); throw new ArgumentException("Property is required for class AppleReq.", nameof(cultivar));
if (mealy == null) if (cultivar.IsSet && cultivar.Value == null)
throw new ArgumentNullException(nameof(mealy), "Property is required for class AppleReq."); throw new ArgumentNullException(nameof(cultivar), "Property is not nullable for class AppleReq.");
return new AppleReq(cultivar, mealy.Value); if (mealy.IsSet && mealy.Value == null)
throw new ArgumentNullException(nameof(mealy), "Property is not nullable for class AppleReq.");
return new AppleReq(cultivar.Value!, mealy);
} }
/// <summary> /// <summary>
@ -170,8 +180,13 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, AppleReq appleReq, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, AppleReq appleReq, JsonSerializerOptions jsonSerializerOptions)
{ {
if (appleReq.Cultivar == null)
throw new ArgumentNullException(nameof(appleReq.Cultivar), "Property is required for class AppleReq.");
writer.WriteString("cultivar", appleReq.Cultivar); writer.WriteString("cultivar", appleReq.Cultivar);
writer.WriteBoolean("mealy", appleReq.Mealy);
if (appleReq.MealyOption.IsSet)
writer.WriteBoolean("mealy", appleReq.MealyOption.Value!.Value);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="arrayArrayNumber">arrayArrayNumber</param> /// <param name="arrayArrayNumber">arrayArrayNumber</param>
[JsonConstructor] [JsonConstructor]
public ArrayOfArrayOfNumberOnly(List<List<decimal>> arrayArrayNumber) public ArrayOfArrayOfNumberOnly(Option<List<List<decimal>>?> arrayArrayNumber = default)
{ {
ArrayArrayNumber = arrayArrayNumber; ArrayArrayNumberOption = arrayArrayNumber;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of ArrayArrayNumber
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<List<decimal>>?> ArrayArrayNumberOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayArrayNumber /// Gets or Sets ArrayArrayNumber
/// </summary> /// </summary>
[JsonPropertyName("ArrayArrayNumber")] [JsonPropertyName("ArrayArrayNumber")]
public List<List<decimal>> ArrayArrayNumber { get; set; } public List<List<decimal>>? ArrayArrayNumber { get { return this. ArrayArrayNumberOption; } set { this.ArrayArrayNumberOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<List<decimal>>? arrayArrayNumber = default; Option<List<List<decimal>>?> arrayArrayNumber = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
{ {
case "ArrayArrayNumber": case "ArrayArrayNumber":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayArrayNumber = JsonSerializer.Deserialize<List<List<decimal>>>(ref utf8JsonReader, jsonSerializerOptions); arrayArrayNumber = new Option<List<List<decimal>>?>(JsonSerializer.Deserialize<List<List<decimal>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -131,8 +138,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (arrayArrayNumber == null) if (arrayArrayNumber.IsSet && arrayArrayNumber.Value == null)
throw new ArgumentNullException(nameof(arrayArrayNumber), "Property is required for class ArrayOfArrayOfNumberOnly."); throw new ArgumentNullException(nameof(arrayArrayNumber), "Property is not nullable for class ArrayOfArrayOfNumberOnly.");
return new ArrayOfArrayOfNumberOnly(arrayArrayNumber); return new ArrayOfArrayOfNumberOnly(arrayArrayNumber);
} }
@ -161,8 +168,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ArrayOfArrayOfNumberOnly arrayOfArrayOfNumberOnly, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ArrayOfArrayOfNumberOnly arrayOfArrayOfNumberOnly, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("ArrayArrayNumber"); if (arrayOfArrayOfNumberOnly.ArrayArrayNumberOption.IsSet && arrayOfArrayOfNumberOnly.ArrayArrayNumber == null)
JsonSerializer.Serialize(writer, arrayOfArrayOfNumberOnly.ArrayArrayNumber, jsonSerializerOptions); throw new ArgumentNullException(nameof(arrayOfArrayOfNumberOnly.ArrayArrayNumber), "Property is required for class ArrayOfArrayOfNumberOnly.");
if (arrayOfArrayOfNumberOnly.ArrayArrayNumberOption.IsSet)
{
writer.WritePropertyName("ArrayArrayNumber");
JsonSerializer.Serialize(writer, arrayOfArrayOfNumberOnly.ArrayArrayNumber, jsonSerializerOptions);
}
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="arrayNumber">arrayNumber</param> /// <param name="arrayNumber">arrayNumber</param>
[JsonConstructor] [JsonConstructor]
public ArrayOfNumberOnly(List<decimal> arrayNumber) public ArrayOfNumberOnly(Option<List<decimal>?> arrayNumber = default)
{ {
ArrayNumber = arrayNumber; ArrayNumberOption = arrayNumber;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of ArrayNumber
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<decimal>?> ArrayNumberOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayNumber /// Gets or Sets ArrayNumber
/// </summary> /// </summary>
[JsonPropertyName("ArrayNumber")] [JsonPropertyName("ArrayNumber")]
public List<decimal> ArrayNumber { get; set; } public List<decimal>? ArrayNumber { get { return this. ArrayNumberOption; } set { this.ArrayNumberOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<decimal>? arrayNumber = default; Option<List<decimal>?> arrayNumber = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
{ {
case "ArrayNumber": case "ArrayNumber":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayNumber = JsonSerializer.Deserialize<List<decimal>>(ref utf8JsonReader, jsonSerializerOptions); arrayNumber = new Option<List<decimal>?>(JsonSerializer.Deserialize<List<decimal>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -131,8 +138,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (arrayNumber == null) if (arrayNumber.IsSet && arrayNumber.Value == null)
throw new ArgumentNullException(nameof(arrayNumber), "Property is required for class ArrayOfNumberOnly."); throw new ArgumentNullException(nameof(arrayNumber), "Property is not nullable for class ArrayOfNumberOnly.");
return new ArrayOfNumberOnly(arrayNumber); return new ArrayOfNumberOnly(arrayNumber);
} }
@ -161,8 +168,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ArrayOfNumberOnly arrayOfNumberOnly, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ArrayOfNumberOnly arrayOfNumberOnly, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("ArrayNumber"); if (arrayOfNumberOnly.ArrayNumberOption.IsSet && arrayOfNumberOnly.ArrayNumber == null)
JsonSerializer.Serialize(writer, arrayOfNumberOnly.ArrayNumber, jsonSerializerOptions); throw new ArgumentNullException(nameof(arrayOfNumberOnly.ArrayNumber), "Property is required for class ArrayOfNumberOnly.");
if (arrayOfNumberOnly.ArrayNumberOption.IsSet)
{
writer.WritePropertyName("ArrayNumber");
JsonSerializer.Serialize(writer, arrayOfNumberOnly.ArrayNumber, jsonSerializerOptions);
}
} }
} }

View File

@ -39,33 +39,54 @@ namespace UseSourceGeneration.Model
/// <param name="arrayArrayOfModel">arrayArrayOfModel</param> /// <param name="arrayArrayOfModel">arrayArrayOfModel</param>
/// <param name="arrayOfString">arrayOfString</param> /// <param name="arrayOfString">arrayOfString</param>
[JsonConstructor] [JsonConstructor]
public ArrayTest(List<List<long>> arrayArrayOfInteger, List<List<ReadOnlyFirst>> arrayArrayOfModel, List<string> arrayOfString) public ArrayTest(Option<List<List<long>>?> arrayArrayOfInteger = default, Option<List<List<ReadOnlyFirst>>?> arrayArrayOfModel = default, Option<List<string>?> arrayOfString = default)
{ {
ArrayArrayOfInteger = arrayArrayOfInteger; ArrayArrayOfIntegerOption = arrayArrayOfInteger;
ArrayArrayOfModel = arrayArrayOfModel; ArrayArrayOfModelOption = arrayArrayOfModel;
ArrayOfString = arrayOfString; ArrayOfStringOption = arrayOfString;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of ArrayArrayOfInteger
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<List<long>>?> ArrayArrayOfIntegerOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayArrayOfInteger /// Gets or Sets ArrayArrayOfInteger
/// </summary> /// </summary>
[JsonPropertyName("array_array_of_integer")] [JsonPropertyName("array_array_of_integer")]
public List<List<long>> ArrayArrayOfInteger { get; set; } public List<List<long>>? ArrayArrayOfInteger { get { return this. ArrayArrayOfIntegerOption; } set { this.ArrayArrayOfIntegerOption = new(value); } }
/// <summary>
/// Used to track the state of ArrayArrayOfModel
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<List<ReadOnlyFirst>>?> ArrayArrayOfModelOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayArrayOfModel /// Gets or Sets ArrayArrayOfModel
/// </summary> /// </summary>
[JsonPropertyName("array_array_of_model")] [JsonPropertyName("array_array_of_model")]
public List<List<ReadOnlyFirst>> ArrayArrayOfModel { get; set; } public List<List<ReadOnlyFirst>>? ArrayArrayOfModel { get { return this. ArrayArrayOfModelOption; } set { this.ArrayArrayOfModelOption = new(value); } }
/// <summary>
/// Used to track the state of ArrayOfString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<string>?> ArrayOfStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayOfString /// Gets or Sets ArrayOfString
/// </summary> /// </summary>
[JsonPropertyName("array_of_string")] [JsonPropertyName("array_of_string")]
public List<string> ArrayOfString { get; set; } public List<string>? ArrayOfString { get { return this. ArrayOfStringOption; } set { this.ArrayOfStringOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -122,9 +143,9 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<List<long>>? arrayArrayOfInteger = default; Option<List<List<long>>?> arrayArrayOfInteger = default;
List<List<ReadOnlyFirst>>? arrayArrayOfModel = default; Option<List<List<ReadOnlyFirst>>?> arrayArrayOfModel = default;
List<string>? arrayOfString = default; Option<List<string>?> arrayOfString = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -143,15 +164,15 @@ namespace UseSourceGeneration.Model
{ {
case "array_array_of_integer": case "array_array_of_integer":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayArrayOfInteger = JsonSerializer.Deserialize<List<List<long>>>(ref utf8JsonReader, jsonSerializerOptions); arrayArrayOfInteger = new Option<List<List<long>>?>(JsonSerializer.Deserialize<List<List<long>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "array_array_of_model": case "array_array_of_model":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayArrayOfModel = JsonSerializer.Deserialize<List<List<ReadOnlyFirst>>>(ref utf8JsonReader, jsonSerializerOptions); arrayArrayOfModel = new Option<List<List<ReadOnlyFirst>>?>(JsonSerializer.Deserialize<List<List<ReadOnlyFirst>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "array_of_string": case "array_of_string":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayOfString = JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions); arrayOfString = new Option<List<string>?>(JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -159,14 +180,14 @@ namespace UseSourceGeneration.Model
} }
} }
if (arrayArrayOfInteger == null) if (arrayArrayOfInteger.IsSet && arrayArrayOfInteger.Value == null)
throw new ArgumentNullException(nameof(arrayArrayOfInteger), "Property is required for class ArrayTest."); throw new ArgumentNullException(nameof(arrayArrayOfInteger), "Property is not nullable for class ArrayTest.");
if (arrayArrayOfModel == null) if (arrayArrayOfModel.IsSet && arrayArrayOfModel.Value == null)
throw new ArgumentNullException(nameof(arrayArrayOfModel), "Property is required for class ArrayTest."); throw new ArgumentNullException(nameof(arrayArrayOfModel), "Property is not nullable for class ArrayTest.");
if (arrayOfString == null) if (arrayOfString.IsSet && arrayOfString.Value == null)
throw new ArgumentNullException(nameof(arrayOfString), "Property is required for class ArrayTest."); throw new ArgumentNullException(nameof(arrayOfString), "Property is not nullable for class ArrayTest.");
return new ArrayTest(arrayArrayOfInteger, arrayArrayOfModel, arrayOfString); return new ArrayTest(arrayArrayOfInteger, arrayArrayOfModel, arrayOfString);
} }
@ -195,12 +216,30 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ArrayTest arrayTest, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ArrayTest arrayTest, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("array_array_of_integer"); if (arrayTest.ArrayArrayOfIntegerOption.IsSet && arrayTest.ArrayArrayOfInteger == null)
JsonSerializer.Serialize(writer, arrayTest.ArrayArrayOfInteger, jsonSerializerOptions); throw new ArgumentNullException(nameof(arrayTest.ArrayArrayOfInteger), "Property is required for class ArrayTest.");
writer.WritePropertyName("array_array_of_model");
JsonSerializer.Serialize(writer, arrayTest.ArrayArrayOfModel, jsonSerializerOptions); if (arrayTest.ArrayArrayOfModelOption.IsSet && arrayTest.ArrayArrayOfModel == null)
writer.WritePropertyName("array_of_string"); throw new ArgumentNullException(nameof(arrayTest.ArrayArrayOfModel), "Property is required for class ArrayTest.");
JsonSerializer.Serialize(writer, arrayTest.ArrayOfString, jsonSerializerOptions);
if (arrayTest.ArrayOfStringOption.IsSet && arrayTest.ArrayOfString == null)
throw new ArgumentNullException(nameof(arrayTest.ArrayOfString), "Property is required for class ArrayTest.");
if (arrayTest.ArrayArrayOfIntegerOption.IsSet)
{
writer.WritePropertyName("array_array_of_integer");
JsonSerializer.Serialize(writer, arrayTest.ArrayArrayOfInteger, jsonSerializerOptions);
}
if (arrayTest.ArrayArrayOfModelOption.IsSet)
{
writer.WritePropertyName("array_array_of_model");
JsonSerializer.Serialize(writer, arrayTest.ArrayArrayOfModel, jsonSerializerOptions);
}
if (arrayTest.ArrayOfStringOption.IsSet)
{
writer.WritePropertyName("array_of_string");
JsonSerializer.Serialize(writer, arrayTest.ArrayOfString, jsonSerializerOptions);
}
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="lengthCm">lengthCm</param> /// <param name="lengthCm">lengthCm</param>
[JsonConstructor] [JsonConstructor]
public Banana(decimal lengthCm) public Banana(Option<decimal?> lengthCm = default)
{ {
LengthCm = lengthCm; LengthCmOption = lengthCm;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of LengthCm
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<decimal?> LengthCmOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets LengthCm /// Gets or Sets LengthCm
/// </summary> /// </summary>
[JsonPropertyName("lengthCm")] [JsonPropertyName("lengthCm")]
public decimal LengthCm { get; set; } public decimal? LengthCm { get { return this. LengthCmOption; } set { this.LengthCmOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
decimal? lengthCm = default; Option<decimal?> lengthCm = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
{ {
case "lengthCm": case "lengthCm":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
lengthCm = utf8JsonReader.GetDecimal(); lengthCm = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
default: default:
break; break;
@ -131,10 +138,10 @@ namespace UseSourceGeneration.Model
} }
} }
if (lengthCm == null) if (lengthCm.IsSet && lengthCm.Value == null)
throw new ArgumentNullException(nameof(lengthCm), "Property is required for class Banana."); throw new ArgumentNullException(nameof(lengthCm), "Property is not nullable for class Banana.");
return new Banana(lengthCm.Value); return new Banana(lengthCm);
} }
/// <summary> /// <summary>
@ -161,7 +168,8 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Banana banana, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Banana banana, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteNumber("lengthCm", banana.LengthCm); if (banana.LengthCmOption.IsSet)
writer.WriteNumber("lengthCm", banana.LengthCmOption.Value!.Value);
} }
} }

View File

@ -38,10 +38,10 @@ namespace UseSourceGeneration.Model
/// <param name="lengthCm">lengthCm</param> /// <param name="lengthCm">lengthCm</param>
/// <param name="sweet">sweet</param> /// <param name="sweet">sweet</param>
[JsonConstructor] [JsonConstructor]
public BananaReq(decimal lengthCm, bool sweet) public BananaReq(decimal lengthCm, Option<bool?> sweet = default)
{ {
LengthCm = lengthCm; LengthCm = lengthCm;
Sweet = sweet; SweetOption = sweet;
OnCreated(); OnCreated();
} }
@ -53,11 +53,18 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("lengthCm")] [JsonPropertyName("lengthCm")]
public decimal LengthCm { get; set; } public decimal LengthCm { get; set; }
/// <summary>
/// Used to track the state of Sweet
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<bool?> SweetOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Sweet /// Gets or Sets Sweet
/// </summary> /// </summary>
[JsonPropertyName("sweet")] [JsonPropertyName("sweet")]
public bool Sweet { get; set; } public bool? Sweet { get { return this. SweetOption; } set { this.SweetOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -106,8 +113,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
decimal? lengthCm = default; Option<decimal?> lengthCm = default;
bool? sweet = default; Option<bool?> sweet = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -126,11 +133,11 @@ namespace UseSourceGeneration.Model
{ {
case "lengthCm": case "lengthCm":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
lengthCm = utf8JsonReader.GetDecimal(); lengthCm = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
case "sweet": case "sweet":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
sweet = utf8JsonReader.GetBoolean(); sweet = new Option<bool?>(utf8JsonReader.GetBoolean());
break; break;
default: default:
break; break;
@ -138,13 +145,16 @@ namespace UseSourceGeneration.Model
} }
} }
if (lengthCm == null) if (!lengthCm.IsSet)
throw new ArgumentNullException(nameof(lengthCm), "Property is required for class BananaReq."); throw new ArgumentException("Property is required for class BananaReq.", nameof(lengthCm));
if (sweet == null) if (lengthCm.IsSet && lengthCm.Value == null)
throw new ArgumentNullException(nameof(sweet), "Property is required for class BananaReq."); throw new ArgumentNullException(nameof(lengthCm), "Property is not nullable for class BananaReq.");
return new BananaReq(lengthCm.Value, sweet.Value); if (sweet.IsSet && sweet.Value == null)
throw new ArgumentNullException(nameof(sweet), "Property is not nullable for class BananaReq.");
return new BananaReq(lengthCm.Value!.Value!, sweet);
} }
/// <summary> /// <summary>
@ -172,7 +182,9 @@ namespace UseSourceGeneration.Model
public void WriteProperties(ref Utf8JsonWriter writer, BananaReq bananaReq, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, BananaReq bananaReq, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteNumber("lengthCm", bananaReq.LengthCm); writer.WriteNumber("lengthCm", bananaReq.LengthCm);
writer.WriteBoolean("sweet", bananaReq.Sweet);
if (bananaReq.SweetOption.IsSet)
writer.WriteBoolean("sweet", bananaReq.SweetOption.Value!.Value);
} }
} }

View File

@ -104,7 +104,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? className = default; Option<string?> className = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +122,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,10 +130,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (className == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(className), "Property is required for class BasquePig."); throw new ArgumentException("Property is required for class BasquePig.", nameof(className));
return new BasquePig(className); if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(className), "Property is not nullable for class BasquePig.");
return new BasquePig(className.Value!);
} }
/// <summary> /// <summary>
@ -160,6 +163,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, BasquePig basquePig, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, BasquePig basquePig, JsonSerializerOptions jsonSerializerOptions)
{ {
if (basquePig.ClassName == null)
throw new ArgumentNullException(nameof(basquePig.ClassName), "Property is required for class BasquePig.");
writer.WriteString("className", basquePig.ClassName); writer.WriteString("className", basquePig.ClassName);
} }
} }

View File

@ -42,55 +42,97 @@ namespace UseSourceGeneration.Model
/// <param name="smallCamel">smallCamel</param> /// <param name="smallCamel">smallCamel</param>
/// <param name="smallSnake">smallSnake</param> /// <param name="smallSnake">smallSnake</param>
[JsonConstructor] [JsonConstructor]
public Capitalization(string aTTNAME, string capitalCamel, string capitalSnake, string sCAETHFlowPoints, string smallCamel, string smallSnake) public Capitalization(Option<string?> aTTNAME = default, Option<string?> capitalCamel = default, Option<string?> capitalSnake = default, Option<string?> sCAETHFlowPoints = default, Option<string?> smallCamel = default, Option<string?> smallSnake = default)
{ {
ATT_NAME = aTTNAME; ATT_NAMEOption = aTTNAME;
CapitalCamel = capitalCamel; CapitalCamelOption = capitalCamel;
CapitalSnake = capitalSnake; CapitalSnakeOption = capitalSnake;
SCAETHFlowPoints = sCAETHFlowPoints; SCAETHFlowPointsOption = sCAETHFlowPoints;
SmallCamel = smallCamel; SmallCamelOption = smallCamel;
SmallSnake = smallSnake; SmallSnakeOption = smallSnake;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of ATT_NAME
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> ATT_NAMEOption { get; private set; }
/// <summary> /// <summary>
/// Name of the pet /// Name of the pet
/// </summary> /// </summary>
/// <value>Name of the pet </value> /// <value>Name of the pet </value>
[JsonPropertyName("ATT_NAME")] [JsonPropertyName("ATT_NAME")]
public string ATT_NAME { get; set; } public string? ATT_NAME { get { return this. ATT_NAMEOption; } set { this.ATT_NAMEOption = new(value); } }
/// <summary>
/// Used to track the state of CapitalCamel
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> CapitalCamelOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets CapitalCamel /// Gets or Sets CapitalCamel
/// </summary> /// </summary>
[JsonPropertyName("CapitalCamel")] [JsonPropertyName("CapitalCamel")]
public string CapitalCamel { get; set; } public string? CapitalCamel { get { return this. CapitalCamelOption; } set { this.CapitalCamelOption = new(value); } }
/// <summary>
/// Used to track the state of CapitalSnake
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> CapitalSnakeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets CapitalSnake /// Gets or Sets CapitalSnake
/// </summary> /// </summary>
[JsonPropertyName("Capital_Snake")] [JsonPropertyName("Capital_Snake")]
public string CapitalSnake { get; set; } public string? CapitalSnake { get { return this. CapitalSnakeOption; } set { this.CapitalSnakeOption = new(value); } }
/// <summary>
/// Used to track the state of SCAETHFlowPoints
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> SCAETHFlowPointsOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets SCAETHFlowPoints /// Gets or Sets SCAETHFlowPoints
/// </summary> /// </summary>
[JsonPropertyName("SCA_ETH_Flow_Points")] [JsonPropertyName("SCA_ETH_Flow_Points")]
public string SCAETHFlowPoints { get; set; } public string? SCAETHFlowPoints { get { return this. SCAETHFlowPointsOption; } set { this.SCAETHFlowPointsOption = new(value); } }
/// <summary>
/// Used to track the state of SmallCamel
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> SmallCamelOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets SmallCamel /// Gets or Sets SmallCamel
/// </summary> /// </summary>
[JsonPropertyName("smallCamel")] [JsonPropertyName("smallCamel")]
public string SmallCamel { get; set; } public string? SmallCamel { get { return this. SmallCamelOption; } set { this.SmallCamelOption = new(value); } }
/// <summary>
/// Used to track the state of SmallSnake
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> SmallSnakeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets SmallSnake /// Gets or Sets SmallSnake
/// </summary> /// </summary>
[JsonPropertyName("small_Snake")] [JsonPropertyName("small_Snake")]
public string SmallSnake { get; set; } public string? SmallSnake { get { return this. SmallSnakeOption; } set { this.SmallSnakeOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -150,12 +192,12 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? aTTNAME = default; Option<string?> aTTNAME = default;
string? capitalCamel = default; Option<string?> capitalCamel = default;
string? capitalSnake = default; Option<string?> capitalSnake = default;
string? sCAETHFlowPoints = default; Option<string?> sCAETHFlowPoints = default;
string? smallCamel = default; Option<string?> smallCamel = default;
string? smallSnake = default; Option<string?> smallSnake = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -173,22 +215,22 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "ATT_NAME": case "ATT_NAME":
aTTNAME = utf8JsonReader.GetString(); aTTNAME = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "CapitalCamel": case "CapitalCamel":
capitalCamel = utf8JsonReader.GetString(); capitalCamel = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "Capital_Snake": case "Capital_Snake":
capitalSnake = utf8JsonReader.GetString(); capitalSnake = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "SCA_ETH_Flow_Points": case "SCA_ETH_Flow_Points":
sCAETHFlowPoints = utf8JsonReader.GetString(); sCAETHFlowPoints = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "smallCamel": case "smallCamel":
smallCamel = utf8JsonReader.GetString(); smallCamel = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "small_Snake": case "small_Snake":
smallSnake = utf8JsonReader.GetString(); smallSnake = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -196,23 +238,23 @@ namespace UseSourceGeneration.Model
} }
} }
if (aTTNAME == null) if (aTTNAME.IsSet && aTTNAME.Value == null)
throw new ArgumentNullException(nameof(aTTNAME), "Property is required for class Capitalization."); throw new ArgumentNullException(nameof(aTTNAME), "Property is not nullable for class Capitalization.");
if (capitalCamel == null) if (capitalCamel.IsSet && capitalCamel.Value == null)
throw new ArgumentNullException(nameof(capitalCamel), "Property is required for class Capitalization."); throw new ArgumentNullException(nameof(capitalCamel), "Property is not nullable for class Capitalization.");
if (capitalSnake == null) if (capitalSnake.IsSet && capitalSnake.Value == null)
throw new ArgumentNullException(nameof(capitalSnake), "Property is required for class Capitalization."); throw new ArgumentNullException(nameof(capitalSnake), "Property is not nullable for class Capitalization.");
if (sCAETHFlowPoints == null) if (sCAETHFlowPoints.IsSet && sCAETHFlowPoints.Value == null)
throw new ArgumentNullException(nameof(sCAETHFlowPoints), "Property is required for class Capitalization."); throw new ArgumentNullException(nameof(sCAETHFlowPoints), "Property is not nullable for class Capitalization.");
if (smallCamel == null) if (smallCamel.IsSet && smallCamel.Value == null)
throw new ArgumentNullException(nameof(smallCamel), "Property is required for class Capitalization."); throw new ArgumentNullException(nameof(smallCamel), "Property is not nullable for class Capitalization.");
if (smallSnake == null) if (smallSnake.IsSet && smallSnake.Value == null)
throw new ArgumentNullException(nameof(smallSnake), "Property is required for class Capitalization."); throw new ArgumentNullException(nameof(smallSnake), "Property is not nullable for class Capitalization.");
return new Capitalization(aTTNAME, capitalCamel, capitalSnake, sCAETHFlowPoints, smallCamel, smallSnake); return new Capitalization(aTTNAME, capitalCamel, capitalSnake, sCAETHFlowPoints, smallCamel, smallSnake);
} }
@ -241,12 +283,41 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Capitalization capitalization, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Capitalization capitalization, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("ATT_NAME", capitalization.ATT_NAME); if (capitalization.ATT_NAMEOption.IsSet && capitalization.ATT_NAME == null)
writer.WriteString("CapitalCamel", capitalization.CapitalCamel); throw new ArgumentNullException(nameof(capitalization.ATT_NAME), "Property is required for class Capitalization.");
writer.WriteString("Capital_Snake", capitalization.CapitalSnake);
writer.WriteString("SCA_ETH_Flow_Points", capitalization.SCAETHFlowPoints); if (capitalization.CapitalCamelOption.IsSet && capitalization.CapitalCamel == null)
writer.WriteString("smallCamel", capitalization.SmallCamel); throw new ArgumentNullException(nameof(capitalization.CapitalCamel), "Property is required for class Capitalization.");
writer.WriteString("small_Snake", capitalization.SmallSnake);
if (capitalization.CapitalSnakeOption.IsSet && capitalization.CapitalSnake == null)
throw new ArgumentNullException(nameof(capitalization.CapitalSnake), "Property is required for class Capitalization.");
if (capitalization.SCAETHFlowPointsOption.IsSet && capitalization.SCAETHFlowPoints == null)
throw new ArgumentNullException(nameof(capitalization.SCAETHFlowPoints), "Property is required for class Capitalization.");
if (capitalization.SmallCamelOption.IsSet && capitalization.SmallCamel == null)
throw new ArgumentNullException(nameof(capitalization.SmallCamel), "Property is required for class Capitalization.");
if (capitalization.SmallSnakeOption.IsSet && capitalization.SmallSnake == null)
throw new ArgumentNullException(nameof(capitalization.SmallSnake), "Property is required for class Capitalization.");
if (capitalization.ATT_NAMEOption.IsSet)
writer.WriteString("ATT_NAME", capitalization.ATT_NAME);
if (capitalization.CapitalCamelOption.IsSet)
writer.WriteString("CapitalCamel", capitalization.CapitalCamel);
if (capitalization.CapitalSnakeOption.IsSet)
writer.WriteString("Capital_Snake", capitalization.CapitalSnake);
if (capitalization.SCAETHFlowPointsOption.IsSet)
writer.WriteString("SCA_ETH_Flow_Points", capitalization.SCAETHFlowPoints);
if (capitalization.SmallCamelOption.IsSet)
writer.WriteString("smallCamel", capitalization.SmallCamel);
if (capitalization.SmallSnakeOption.IsSet)
writer.WriteString("small_Snake", capitalization.SmallSnake);
} }
} }

View File

@ -36,22 +36,29 @@ namespace UseSourceGeneration.Model
/// Initializes a new instance of the <see cref="Cat" /> class. /// Initializes a new instance of the <see cref="Cat" /> class.
/// </summary> /// </summary>
/// <param name="className">className</param> /// <param name="className">className</param>
/// <param name="declawed">declawed</param>
/// <param name="color">color (default to &quot;red&quot;)</param> /// <param name="color">color (default to &quot;red&quot;)</param>
/// <param name="declawed">declawed</param>
[JsonConstructor] [JsonConstructor]
public Cat(string className, bool declawed, string color = @"red") : base(className, color) public Cat(string className, Option<string?> color = default, Option<bool?> declawed = default) : base(className, color)
{ {
Declawed = declawed; DeclawedOption = declawed;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Declawed
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<bool?> DeclawedOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Declawed /// Gets or Sets Declawed
/// </summary> /// </summary>
[JsonPropertyName("declawed")] [JsonPropertyName("declawed")]
public bool Declawed { get; set; } public bool? Declawed { get { return this. DeclawedOption; } set { this.DeclawedOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -90,9 +97,9 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? className = default; Option<string?> className = default;
bool? declawed = default; Option<string?> color = default;
string? color = default; Option<bool?> declawed = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -110,14 +117,14 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break;
case "color":
color = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "declawed": case "declawed":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
declawed = utf8JsonReader.GetBoolean(); declawed = new Option<bool?>(utf8JsonReader.GetBoolean());
break;
case "color":
color = utf8JsonReader.GetString();
break; break;
default: default:
break; break;
@ -125,16 +132,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (className == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(className), "Property is required for class Cat."); throw new ArgumentException("Property is required for class Cat.", nameof(className));
if (declawed == null) if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(declawed), "Property is required for class Cat."); throw new ArgumentNullException(nameof(className), "Property is not nullable for class Cat.");
if (color == null) if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is required for class Cat."); throw new ArgumentNullException(nameof(color), "Property is not nullable for class Cat.");
return new Cat(className, declawed.Value, color); if (declawed.IsSet && declawed.Value == null)
throw new ArgumentNullException(nameof(declawed), "Property is not nullable for class Cat.");
return new Cat(className.Value!, color, declawed);
} }
/// <summary> /// <summary>
@ -161,9 +171,19 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Cat cat, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Cat cat, JsonSerializerOptions jsonSerializerOptions)
{ {
if (cat.ClassName == null)
throw new ArgumentNullException(nameof(cat.ClassName), "Property is required for class Cat.");
if (cat.ColorOption.IsSet && cat.Color == null)
throw new ArgumentNullException(nameof(cat.Color), "Property is required for class Cat.");
writer.WriteString("className", cat.ClassName); writer.WriteString("className", cat.ClassName);
writer.WriteBoolean("declawed", cat.Declawed);
writer.WriteString("color", cat.Color); if (cat.ColorOption.IsSet)
writer.WriteString("color", cat.Color);
if (cat.DeclawedOption.IsSet)
writer.WriteBoolean("declawed", cat.DeclawedOption.Value!.Value);
} }
} }

View File

@ -38,20 +38,27 @@ namespace UseSourceGeneration.Model
/// <param name="id">id</param> /// <param name="id">id</param>
/// <param name="name">name (default to &quot;default-name&quot;)</param> /// <param name="name">name (default to &quot;default-name&quot;)</param>
[JsonConstructor] [JsonConstructor]
public Category(long id, string name = @"default-name") public Category(Option<long?> id = default, string name = @"default-name")
{ {
Id = id; IdOption = id;
Name = name; Name = name;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Id
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<long?> IdOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Id /// Gets or Sets Id
/// </summary> /// </summary>
[JsonPropertyName("id")] [JsonPropertyName("id")]
public long Id { get; set; } public long? Id { get { return this. IdOption; } set { this.IdOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets Name /// Gets or Sets Name
@ -113,8 +120,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
long? id = default; Option<long?> id = default;
string? name = default; Option<string?> name = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -133,10 +140,10 @@ namespace UseSourceGeneration.Model
{ {
case "id": case "id":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
id = utf8JsonReader.GetInt64(); id = new Option<long?>(utf8JsonReader.GetInt64());
break; break;
case "name": case "name":
name = utf8JsonReader.GetString(); name = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -144,13 +151,16 @@ namespace UseSourceGeneration.Model
} }
} }
if (id == null) if (!name.IsSet)
throw new ArgumentNullException(nameof(id), "Property is required for class Category."); throw new ArgumentException("Property is required for class Category.", nameof(name));
if (name == null) if (id.IsSet && id.Value == null)
throw new ArgumentNullException(nameof(name), "Property is required for class Category."); throw new ArgumentNullException(nameof(id), "Property is not nullable for class Category.");
return new Category(id.Value, name); if (name.IsSet && name.Value == null)
throw new ArgumentNullException(nameof(name), "Property is not nullable for class Category.");
return new Category(id, name.Value!);
} }
/// <summary> /// <summary>
@ -177,7 +187,12 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Category category, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Category category, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteNumber("id", category.Id); if (category.Name == null)
throw new ArgumentNullException(nameof(category.Name), "Property is required for class Category.");
if (category.IdOption.IsSet)
writer.WriteNumber("id", category.IdOption.Value!.Value);
writer.WriteString("name", category.Name); writer.WriteString("name", category.Name);
} }
} }

View File

@ -38,10 +38,10 @@ namespace UseSourceGeneration.Model
/// <param name="name">name</param> /// <param name="name">name</param>
/// <param name="petType">petType (default to PetTypeEnum.ChildCat)</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat)</param>
[JsonConstructor] [JsonConstructor]
public ChildCat(string name, PetTypeEnum petType = PetTypeEnum.ChildCat) : base(ChildCat.PetTypeEnumToJsonValue(petType)) public ChildCat(Option<string?> name = default, Option<PetTypeEnum?> petType = default) : base(ChildCat.PetTypeEnumToJsonValue(petType.Value))
{ {
Name = name; NameOption = name;
PetType = petType; PetTypeOption = petType;
OnCreated(); OnCreated();
} }
@ -91,26 +91,39 @@ namespace UseSourceGeneration.Model
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public static string PetTypeEnumToJsonValue(PetTypeEnum value) public static string PetTypeEnumToJsonValue(PetTypeEnum? value)
{ {
if (value == PetTypeEnum.ChildCat) if (value == PetTypeEnum.ChildCat)
return "ChildCat"; return "ChildCat";
throw new NotImplementedException($"Value could not be handled: '{value}'"); throw new NotImplementedException($"Value could not be handled: '{value}'");
} }
/// <summary>
/// Used to track the state of PetType
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public new Option<PetTypeEnum?> PetTypeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[JsonPropertyName("pet_type")] [JsonPropertyName("pet_type")]
public new PetTypeEnum PetType { get; set; } public new PetTypeEnum? PetType { get { return this.PetTypeOption; } set { this.PetTypeOption = new(value); } }
/// <summary>
/// Used to track the state of Name
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> NameOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Name /// Gets or Sets Name
/// </summary> /// </summary>
[JsonPropertyName("name")] [JsonPropertyName("name")]
public string Name { get; set; } public string? Name { get { return this. NameOption; } set { this.NameOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -150,8 +163,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? name = default; Option<string?> name = default;
ChildCat.PetTypeEnum? petType = default; Option<ChildCat.PetTypeEnum?> petType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -169,13 +182,12 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "name": case "name":
name = utf8JsonReader.GetString(); name = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "pet_type": case "pet_type":
string? petTypeRawValue = utf8JsonReader.GetString(); string? petTypeRawValue = utf8JsonReader.GetString();
petType = petTypeRawValue == null if (petTypeRawValue != null)
? null petType = new Option<ChildCat.PetTypeEnum?>(ChildCat.PetTypeEnumFromStringOrDefault(petTypeRawValue));
: ChildCat.PetTypeEnumFromStringOrDefault(petTypeRawValue);
break; break;
default: default:
break; break;
@ -183,13 +195,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (name == null) if (name.IsSet && name.Value == null)
throw new ArgumentNullException(nameof(name), "Property is required for class ChildCat."); throw new ArgumentNullException(nameof(name), "Property is not nullable for class ChildCat.");
if (petType == null) if (petType.IsSet && petType.Value == null)
throw new ArgumentNullException(nameof(petType), "Property is required for class ChildCat."); throw new ArgumentNullException(nameof(petType), "Property is not nullable for class ChildCat.");
return new ChildCat(name, petType.Value); return new ChildCat(name, petType);
} }
/// <summary> /// <summary>
@ -216,9 +228,13 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ChildCat childCat, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ChildCat childCat, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("name", childCat.Name); if (childCat.NameOption.IsSet && childCat.Name == null)
throw new ArgumentNullException(nameof(childCat.Name), "Property is required for class ChildCat.");
var petTypeRawValue = ChildCat.PetTypeEnumToJsonValue(childCat.PetType); if (childCat.NameOption.IsSet)
writer.WriteString("name", childCat.Name);
var petTypeRawValue = ChildCat.PetTypeEnumToJsonValue(childCat.PetTypeOption.Value!.Value);
if (petTypeRawValue != null) if (petTypeRawValue != null)
writer.WriteString("pet_type", petTypeRawValue); writer.WriteString("pet_type", petTypeRawValue);
else else

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="varClass">varClass</param> /// <param name="varClass">varClass</param>
[JsonConstructor] [JsonConstructor]
public ClassModel(string varClass) public ClassModel(Option<string?> varClass = default)
{ {
VarClass = varClass; VarClassOption = varClass;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of VarClass
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> VarClassOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets VarClass /// Gets or Sets VarClass
/// </summary> /// </summary>
[JsonPropertyName("_class")] [JsonPropertyName("_class")]
public string VarClass { get; set; } public string? VarClass { get { return this. VarClassOption; } set { this.VarClassOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? varClass = default; Option<string?> varClass = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +129,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "_class": case "_class":
varClass = utf8JsonReader.GetString(); varClass = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,8 +137,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (varClass == null) if (varClass.IsSet && varClass.Value == null)
throw new ArgumentNullException(nameof(varClass), "Property is required for class ClassModel."); throw new ArgumentNullException(nameof(varClass), "Property is not nullable for class ClassModel.");
return new ClassModel(varClass); return new ClassModel(varClass);
} }
@ -160,7 +167,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ClassModel classModel, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ClassModel classModel, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("_class", classModel.VarClass); if (classModel.VarClassOption.IsSet && classModel.VarClass == null)
throw new ArgumentNullException(nameof(classModel.VarClass), "Property is required for class ClassModel.");
if (classModel.VarClassOption.IsSet)
writer.WriteString("_class", classModel.VarClass);
} }
} }

View File

@ -113,8 +113,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? quadrilateralType = default; Option<string?> quadrilateralType = default;
string? shapeType = default; Option<string?> shapeType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -132,10 +132,10 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "quadrilateralType": case "quadrilateralType":
quadrilateralType = utf8JsonReader.GetString(); quadrilateralType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "shapeType": case "shapeType":
shapeType = utf8JsonReader.GetString(); shapeType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -143,13 +143,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (quadrilateralType == null) if (!quadrilateralType.IsSet)
throw new ArgumentNullException(nameof(quadrilateralType), "Property is required for class ComplexQuadrilateral."); throw new ArgumentException("Property is required for class ComplexQuadrilateral.", nameof(quadrilateralType));
if (shapeType == null) if (!shapeType.IsSet)
throw new ArgumentNullException(nameof(shapeType), "Property is required for class ComplexQuadrilateral."); throw new ArgumentException("Property is required for class ComplexQuadrilateral.", nameof(shapeType));
return new ComplexQuadrilateral(quadrilateralType, shapeType); if (quadrilateralType.IsSet && quadrilateralType.Value == null)
throw new ArgumentNullException(nameof(quadrilateralType), "Property is not nullable for class ComplexQuadrilateral.");
if (shapeType.IsSet && shapeType.Value == null)
throw new ArgumentNullException(nameof(shapeType), "Property is not nullable for class ComplexQuadrilateral.");
return new ComplexQuadrilateral(quadrilateralType.Value!, shapeType.Value!);
} }
/// <summary> /// <summary>
@ -176,7 +182,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ComplexQuadrilateral complexQuadrilateral, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ComplexQuadrilateral complexQuadrilateral, JsonSerializerOptions jsonSerializerOptions)
{ {
if (complexQuadrilateral.QuadrilateralType == null)
throw new ArgumentNullException(nameof(complexQuadrilateral.QuadrilateralType), "Property is required for class ComplexQuadrilateral.");
if (complexQuadrilateral.ShapeType == null)
throw new ArgumentNullException(nameof(complexQuadrilateral.ShapeType), "Property is required for class ComplexQuadrilateral.");
writer.WriteString("quadrilateralType", complexQuadrilateral.QuadrilateralType); writer.WriteString("quadrilateralType", complexQuadrilateral.QuadrilateralType);
writer.WriteString("shapeType", complexQuadrilateral.ShapeType); writer.WriteString("shapeType", complexQuadrilateral.ShapeType);
} }
} }

View File

@ -104,7 +104,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? className = default; Option<string?> className = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +122,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,10 +130,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (className == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(className), "Property is required for class DanishPig."); throw new ArgumentException("Property is required for class DanishPig.", nameof(className));
return new DanishPig(className); if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(className), "Property is not nullable for class DanishPig.");
return new DanishPig(className.Value!);
} }
/// <summary> /// <summary>
@ -160,6 +163,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, DanishPig danishPig, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, DanishPig danishPig, JsonSerializerOptions jsonSerializerOptions)
{ {
if (danishPig.ClassName == null)
throw new ArgumentNullException(nameof(danishPig.ClassName), "Property is required for class DanishPig.");
writer.WriteString("className", danishPig.ClassName); writer.WriteString("className", danishPig.ClassName);
} }
} }

View File

@ -37,20 +37,27 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="dateOnlyProperty">dateOnlyProperty</param> /// <param name="dateOnlyProperty">dateOnlyProperty</param>
[JsonConstructor] [JsonConstructor]
public DateOnlyClass(DateTime dateOnlyProperty) public DateOnlyClass(Option<DateTime?> dateOnlyProperty = default)
{ {
DateOnlyProperty = dateOnlyProperty; DateOnlyPropertyOption = dateOnlyProperty;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of DateOnlyProperty
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DateTime?> DateOnlyPropertyOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets DateOnlyProperty /// Gets or Sets DateOnlyProperty
/// </summary> /// </summary>
/// <example>Fri Jul 21 00:00:00 UTC 2017</example> /// <example>Fri Jul 21 00:00:00 UTC 2017</example>
[JsonPropertyName("dateOnlyProperty")] [JsonPropertyName("dateOnlyProperty")]
public DateTime DateOnlyProperty { get; set; } public DateTime? DateOnlyProperty { get { return this. DateOnlyPropertyOption; } set { this.DateOnlyPropertyOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -110,7 +117,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
DateTime? dateOnlyProperty = default; Option<DateTime?> dateOnlyProperty = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -129,7 +136,7 @@ namespace UseSourceGeneration.Model
{ {
case "dateOnlyProperty": case "dateOnlyProperty":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateOnlyProperty = JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions); dateOnlyProperty = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
default: default:
break; break;
@ -137,10 +144,10 @@ namespace UseSourceGeneration.Model
} }
} }
if (dateOnlyProperty == null) if (dateOnlyProperty.IsSet && dateOnlyProperty.Value == null)
throw new ArgumentNullException(nameof(dateOnlyProperty), "Property is required for class DateOnlyClass."); throw new ArgumentNullException(nameof(dateOnlyProperty), "Property is not nullable for class DateOnlyClass.");
return new DateOnlyClass(dateOnlyProperty.Value); return new DateOnlyClass(dateOnlyProperty);
} }
/// <summary> /// <summary>
@ -167,7 +174,8 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, DateOnlyClass dateOnlyClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, DateOnlyClass dateOnlyClass, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("dateOnlyProperty", dateOnlyClass.DateOnlyProperty.ToString(DateOnlyPropertyFormat)); if (dateOnlyClass.DateOnlyPropertyOption.IsSet)
writer.WriteString("dateOnlyProperty", dateOnlyClass.DateOnlyPropertyOption.Value!.Value.ToString(DateOnlyPropertyFormat));
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="name">name</param> /// <param name="name">name</param>
[JsonConstructor] [JsonConstructor]
public DeprecatedObject(string name) public DeprecatedObject(Option<string?> name = default)
{ {
Name = name; NameOption = name;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Name
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> NameOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Name /// Gets or Sets Name
/// </summary> /// </summary>
[JsonPropertyName("name")] [JsonPropertyName("name")]
public string Name { get; set; } public string? Name { get { return this. NameOption; } set { this.NameOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? name = default; Option<string?> name = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +129,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "name": case "name":
name = utf8JsonReader.GetString(); name = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,8 +137,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (name == null) if (name.IsSet && name.Value == null)
throw new ArgumentNullException(nameof(name), "Property is required for class DeprecatedObject."); throw new ArgumentNullException(nameof(name), "Property is not nullable for class DeprecatedObject.");
return new DeprecatedObject(name); return new DeprecatedObject(name);
} }
@ -160,7 +167,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, DeprecatedObject deprecatedObject, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, DeprecatedObject deprecatedObject, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("name", deprecatedObject.Name); if (deprecatedObject.NameOption.IsSet && deprecatedObject.Name == null)
throw new ArgumentNullException(nameof(deprecatedObject.Name), "Property is required for class DeprecatedObject.");
if (deprecatedObject.NameOption.IsSet)
writer.WriteString("name", deprecatedObject.Name);
} }
} }

View File

@ -35,23 +35,30 @@ namespace UseSourceGeneration.Model
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Dog" /> class. /// Initializes a new instance of the <see cref="Dog" /> class.
/// </summary> /// </summary>
/// <param name="breed">breed</param>
/// <param name="className">className</param> /// <param name="className">className</param>
/// <param name="breed">breed</param>
/// <param name="color">color (default to &quot;red&quot;)</param> /// <param name="color">color (default to &quot;red&quot;)</param>
[JsonConstructor] [JsonConstructor]
public Dog(string breed, string className, string color = @"red") : base(className, color) public Dog(string className, Option<string?> breed = default, Option<string?> color = default) : base(className, color)
{ {
Breed = breed; BreedOption = breed;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Breed
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> BreedOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Breed /// Gets or Sets Breed
/// </summary> /// </summary>
[JsonPropertyName("breed")] [JsonPropertyName("breed")]
public string Breed { get; set; } public string? Breed { get { return this. BreedOption; } set { this.BreedOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -90,9 +97,9 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? breed = default; Option<string?> className = default;
string? className = default; Option<string?> breed = default;
string? color = default; Option<string?> color = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -109,14 +116,14 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "breed":
breed = utf8JsonReader.GetString();
break;
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break;
case "breed":
breed = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "color": case "color":
color = utf8JsonReader.GetString(); color = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -124,16 +131,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (breed == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(breed), "Property is required for class Dog."); throw new ArgumentException("Property is required for class Dog.", nameof(className));
if (className == null) if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(className), "Property is required for class Dog."); throw new ArgumentNullException(nameof(className), "Property is not nullable for class Dog.");
if (color == null) if (breed.IsSet && breed.Value == null)
throw new ArgumentNullException(nameof(color), "Property is required for class Dog."); throw new ArgumentNullException(nameof(breed), "Property is not nullable for class Dog.");
return new Dog(breed, className, color); if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is not nullable for class Dog.");
return new Dog(className.Value!, breed, color);
} }
/// <summary> /// <summary>
@ -160,9 +170,22 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Dog dog, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Dog dog, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("breed", dog.Breed); if (dog.ClassName == null)
throw new ArgumentNullException(nameof(dog.ClassName), "Property is required for class Dog.");
if (dog.BreedOption.IsSet && dog.Breed == null)
throw new ArgumentNullException(nameof(dog.Breed), "Property is required for class Dog.");
if (dog.ColorOption.IsSet && dog.Color == null)
throw new ArgumentNullException(nameof(dog.Color), "Property is required for class Dog.");
writer.WriteString("className", dog.ClassName); writer.WriteString("className", dog.ClassName);
writer.WriteString("color", dog.Color);
if (dog.BreedOption.IsSet)
writer.WriteString("breed", dog.Breed);
if (dog.ColorOption.IsSet)
writer.WriteString("color", dog.Color);
} }
} }

View File

@ -36,44 +36,72 @@ namespace UseSourceGeneration.Model
/// Initializes a new instance of the <see cref="Drawing" /> class. /// Initializes a new instance of the <see cref="Drawing" /> class.
/// </summary> /// </summary>
/// <param name="mainShape">mainShape</param> /// <param name="mainShape">mainShape</param>
/// <param name="shapes">shapes</param>
/// <param name="nullableShape">nullableShape</param> /// <param name="nullableShape">nullableShape</param>
/// <param name="shapeOrNull">shapeOrNull</param> /// <param name="shapeOrNull">shapeOrNull</param>
/// <param name="shapes">shapes</param>
[JsonConstructor] [JsonConstructor]
public Drawing(Shape mainShape, List<Shape> shapes, NullableShape? nullableShape = default, ShapeOrNull? shapeOrNull = default) : base() public Drawing(Option<Shape?> mainShape = default, Option<NullableShape?> nullableShape = default, Option<ShapeOrNull?> shapeOrNull = default, Option<List<Shape>?> shapes = default) : base()
{ {
MainShape = mainShape; MainShapeOption = mainShape;
Shapes = shapes; NullableShapeOption = nullableShape;
NullableShape = nullableShape; ShapeOrNullOption = shapeOrNull;
ShapeOrNull = shapeOrNull; ShapesOption = shapes;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of MainShape
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Shape?> MainShapeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets MainShape /// Gets or Sets MainShape
/// </summary> /// </summary>
[JsonPropertyName("mainShape")] [JsonPropertyName("mainShape")]
public Shape MainShape { get; set; } public Shape? MainShape { get { return this. MainShapeOption; } set { this.MainShapeOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets Shapes /// Used to track the state of NullableShape
/// </summary> /// </summary>
[JsonPropertyName("shapes")] [JsonIgnore]
public List<Shape> Shapes { get; set; } [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<NullableShape?> NullableShapeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets NullableShape /// Gets or Sets NullableShape
/// </summary> /// </summary>
[JsonPropertyName("nullableShape")] [JsonPropertyName("nullableShape")]
public NullableShape? NullableShape { get; set; } public NullableShape? NullableShape { get { return this. NullableShapeOption; } set { this.NullableShapeOption = new(value); } }
/// <summary>
/// Used to track the state of ShapeOrNull
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<ShapeOrNull?> ShapeOrNullOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ShapeOrNull /// Gets or Sets ShapeOrNull
/// </summary> /// </summary>
[JsonPropertyName("shapeOrNull")] [JsonPropertyName("shapeOrNull")]
public ShapeOrNull? ShapeOrNull { get; set; } public ShapeOrNull? ShapeOrNull { get { return this. ShapeOrNullOption; } set { this.ShapeOrNullOption = new(value); } }
/// <summary>
/// Used to track the state of Shapes
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<Shape>?> ShapesOption { get; private set; }
/// <summary>
/// Gets or Sets Shapes
/// </summary>
[JsonPropertyName("shapes")]
public List<Shape>? Shapes { get { return this. ShapesOption; } set { this.ShapesOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -91,9 +119,9 @@ namespace UseSourceGeneration.Model
sb.Append("class Drawing {\n"); sb.Append("class Drawing {\n");
sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n");
sb.Append(" MainShape: ").Append(MainShape).Append("\n"); sb.Append(" MainShape: ").Append(MainShape).Append("\n");
sb.Append(" Shapes: ").Append(Shapes).Append("\n");
sb.Append(" NullableShape: ").Append(NullableShape).Append("\n"); sb.Append(" NullableShape: ").Append(NullableShape).Append("\n");
sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n");
sb.Append(" Shapes: ").Append(Shapes).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append("}\n"); sb.Append("}\n");
return sb.ToString(); return sb.ToString();
@ -142,10 +170,10 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Shape? mainShape = default; Option<Shape?> mainShape = default;
List<Shape>? shapes = default; Option<NullableShape?> nullableShape = default;
NullableShape? nullableShape = default; Option<ShapeOrNull?> shapeOrNull = default;
ShapeOrNull? shapeOrNull = default; Option<List<Shape>?> shapes = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -164,19 +192,19 @@ namespace UseSourceGeneration.Model
{ {
case "mainShape": case "mainShape":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mainShape = JsonSerializer.Deserialize<Shape>(ref utf8JsonReader, jsonSerializerOptions); mainShape = new Option<Shape?>(JsonSerializer.Deserialize<Shape>(ref utf8JsonReader, jsonSerializerOptions)!);
break;
case "shapes":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
shapes = JsonSerializer.Deserialize<List<Shape>>(ref utf8JsonReader, jsonSerializerOptions);
break; break;
case "nullableShape": case "nullableShape":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
nullableShape = JsonSerializer.Deserialize<NullableShape>(ref utf8JsonReader, jsonSerializerOptions); nullableShape = new Option<NullableShape?>(JsonSerializer.Deserialize<NullableShape>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "shapeOrNull": case "shapeOrNull":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
shapeOrNull = JsonSerializer.Deserialize<ShapeOrNull>(ref utf8JsonReader, jsonSerializerOptions); shapeOrNull = new Option<ShapeOrNull?>(JsonSerializer.Deserialize<ShapeOrNull>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "shapes":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
shapes = new Option<List<Shape>?>(JsonSerializer.Deserialize<List<Shape>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -184,13 +212,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (mainShape == null) if (mainShape.IsSet && mainShape.Value == null)
throw new ArgumentNullException(nameof(mainShape), "Property is required for class Drawing."); throw new ArgumentNullException(nameof(mainShape), "Property is not nullable for class Drawing.");
if (shapes == null) if (shapes.IsSet && shapes.Value == null)
throw new ArgumentNullException(nameof(shapes), "Property is required for class Drawing."); throw new ArgumentNullException(nameof(shapes), "Property is not nullable for class Drawing.");
return new Drawing(mainShape, shapes, nullableShape, shapeOrNull); return new Drawing(mainShape, nullableShape, shapeOrNull, shapes);
} }
/// <summary> /// <summary>
@ -217,14 +245,38 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Drawing drawing, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Drawing drawing, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("mainShape"); if (drawing.MainShapeOption.IsSet && drawing.MainShape == null)
JsonSerializer.Serialize(writer, drawing.MainShape, jsonSerializerOptions); throw new ArgumentNullException(nameof(drawing.MainShape), "Property is required for class Drawing.");
writer.WritePropertyName("shapes");
JsonSerializer.Serialize(writer, drawing.Shapes, jsonSerializerOptions); if (drawing.ShapesOption.IsSet && drawing.Shapes == null)
writer.WritePropertyName("nullableShape"); throw new ArgumentNullException(nameof(drawing.Shapes), "Property is required for class Drawing.");
JsonSerializer.Serialize(writer, drawing.NullableShape, jsonSerializerOptions);
writer.WritePropertyName("shapeOrNull"); if (drawing.MainShapeOption.IsSet)
JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); {
writer.WritePropertyName("mainShape");
JsonSerializer.Serialize(writer, drawing.MainShape, jsonSerializerOptions);
}
if (drawing.NullableShapeOption.IsSet)
if (drawing.NullableShapeOption.Value != null)
{
writer.WritePropertyName("nullableShape");
JsonSerializer.Serialize(writer, drawing.NullableShape, jsonSerializerOptions);
}
else
writer.WriteNull("nullableShape");
if (drawing.ShapeOrNullOption.IsSet)
if (drawing.ShapeOrNullOption.Value != null)
{
writer.WritePropertyName("shapeOrNull");
JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions);
}
else
writer.WriteNull("shapeOrNull");
if (drawing.ShapesOption.IsSet)
{
writer.WritePropertyName("shapes");
JsonSerializer.Serialize(writer, drawing.Shapes, jsonSerializerOptions);
}
} }
} }

View File

@ -38,10 +38,10 @@ namespace UseSourceGeneration.Model
/// <param name="arrayEnum">arrayEnum</param> /// <param name="arrayEnum">arrayEnum</param>
/// <param name="justSymbol">justSymbol</param> /// <param name="justSymbol">justSymbol</param>
[JsonConstructor] [JsonConstructor]
public EnumArrays(List<EnumArrays.ArrayEnumEnum> arrayEnum, JustSymbolEnum justSymbol) public EnumArrays(Option<List<EnumArrays.ArrayEnumEnum>?> arrayEnum = default, Option<JustSymbolEnum?> justSymbol = default)
{ {
ArrayEnum = arrayEnum; ArrayEnumOption = arrayEnum;
JustSymbol = justSymbol; JustSymbolOption = justSymbol;
OnCreated(); OnCreated();
} }
@ -102,9 +102,8 @@ namespace UseSourceGeneration.Model
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public static string ArrayEnumEnumToJsonValue(ArrayEnumEnum value) public static string ArrayEnumEnumToJsonValue(ArrayEnumEnum? value)
{ {
if (value == ArrayEnumEnum.Fish) if (value == ArrayEnumEnum.Fish)
return "fish"; return "fish";
@ -169,9 +168,8 @@ namespace UseSourceGeneration.Model
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public static string JustSymbolEnumToJsonValue(JustSymbolEnum value) public static string JustSymbolEnumToJsonValue(JustSymbolEnum? value)
{ {
if (value == JustSymbolEnum.GreaterThanOrEqualTo) if (value == JustSymbolEnum.GreaterThanOrEqualTo)
return ">="; return ">=";
@ -181,17 +179,31 @@ namespace UseSourceGeneration.Model
throw new NotImplementedException($"Value could not be handled: '{value}'"); throw new NotImplementedException($"Value could not be handled: '{value}'");
} }
/// <summary>
/// Used to track the state of JustSymbol
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<JustSymbolEnum?> JustSymbolOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets JustSymbol /// Gets or Sets JustSymbol
/// </summary> /// </summary>
[JsonPropertyName("just_symbol")] [JsonPropertyName("just_symbol")]
public JustSymbolEnum JustSymbol { get; set; } public JustSymbolEnum? JustSymbol { get { return this.JustSymbolOption; } set { this.JustSymbolOption = new(value); } }
/// <summary>
/// Used to track the state of ArrayEnum
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<EnumArrays.ArrayEnumEnum>?> ArrayEnumOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayEnum /// Gets or Sets ArrayEnum
/// </summary> /// </summary>
[JsonPropertyName("array_enum")] [JsonPropertyName("array_enum")]
public List<EnumArrays.ArrayEnumEnum> ArrayEnum { get; set; } public List<EnumArrays.ArrayEnumEnum>? ArrayEnum { get { return this. ArrayEnumOption; } set { this.ArrayEnumOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -247,8 +259,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<EnumArrays.ArrayEnumEnum>? arrayEnum = default; Option<List<EnumArrays.ArrayEnumEnum>?> arrayEnum = default;
EnumArrays.JustSymbolEnum? justSymbol = default; Option<EnumArrays.JustSymbolEnum?> justSymbol = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -267,13 +279,12 @@ namespace UseSourceGeneration.Model
{ {
case "array_enum": case "array_enum":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayEnum = JsonSerializer.Deserialize<List<EnumArrays.ArrayEnumEnum>>(ref utf8JsonReader, jsonSerializerOptions); arrayEnum = new Option<List<EnumArrays.ArrayEnumEnum>?>(JsonSerializer.Deserialize<List<EnumArrays.ArrayEnumEnum>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "just_symbol": case "just_symbol":
string? justSymbolRawValue = utf8JsonReader.GetString(); string? justSymbolRawValue = utf8JsonReader.GetString();
justSymbol = justSymbolRawValue == null if (justSymbolRawValue != null)
? null justSymbol = new Option<EnumArrays.JustSymbolEnum?>(EnumArrays.JustSymbolEnumFromStringOrDefault(justSymbolRawValue));
: EnumArrays.JustSymbolEnumFromStringOrDefault(justSymbolRawValue);
break; break;
default: default:
break; break;
@ -281,13 +292,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (arrayEnum == null) if (arrayEnum.IsSet && arrayEnum.Value == null)
throw new ArgumentNullException(nameof(arrayEnum), "Property is required for class EnumArrays."); throw new ArgumentNullException(nameof(arrayEnum), "Property is not nullable for class EnumArrays.");
if (justSymbol == null) if (justSymbol.IsSet && justSymbol.Value == null)
throw new ArgumentNullException(nameof(justSymbol), "Property is required for class EnumArrays."); throw new ArgumentNullException(nameof(justSymbol), "Property is not nullable for class EnumArrays.");
return new EnumArrays(arrayEnum, justSymbol.Value); return new EnumArrays(arrayEnum, justSymbol);
} }
/// <summary> /// <summary>
@ -314,10 +325,15 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, EnumArrays enumArrays, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, EnumArrays enumArrays, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("array_enum"); if (enumArrays.ArrayEnumOption.IsSet && enumArrays.ArrayEnum == null)
JsonSerializer.Serialize(writer, enumArrays.ArrayEnum, jsonSerializerOptions); throw new ArgumentNullException(nameof(enumArrays.ArrayEnum), "Property is required for class EnumArrays.");
var justSymbolRawValue = EnumArrays.JustSymbolEnumToJsonValue(enumArrays.JustSymbol); if (enumArrays.ArrayEnumOption.IsSet)
{
writer.WritePropertyName("array_enum");
JsonSerializer.Serialize(writer, enumArrays.ArrayEnum, jsonSerializerOptions);
}
var justSymbolRawValue = EnumArrays.JustSymbolEnumToJsonValue(enumArrays.JustSymbolOption.Value!.Value);
if (justSymbolRawValue != null) if (justSymbolRawValue != null)
writer.WriteString("just_symbol", justSymbolRawValue); writer.WriteString("just_symbol", justSymbolRawValue);
else else

View File

@ -113,8 +113,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? shapeType = default; Option<string?> shapeType = default;
string? triangleType = default; Option<string?> triangleType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -132,10 +132,10 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "shapeType": case "shapeType":
shapeType = utf8JsonReader.GetString(); shapeType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "triangleType": case "triangleType":
triangleType = utf8JsonReader.GetString(); triangleType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -143,13 +143,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (shapeType == null) if (!shapeType.IsSet)
throw new ArgumentNullException(nameof(shapeType), "Property is required for class EquilateralTriangle."); throw new ArgumentException("Property is required for class EquilateralTriangle.", nameof(shapeType));
if (triangleType == null) if (!triangleType.IsSet)
throw new ArgumentNullException(nameof(triangleType), "Property is required for class EquilateralTriangle."); throw new ArgumentException("Property is required for class EquilateralTriangle.", nameof(triangleType));
return new EquilateralTriangle(shapeType, triangleType); if (shapeType.IsSet && shapeType.Value == null)
throw new ArgumentNullException(nameof(shapeType), "Property is not nullable for class EquilateralTriangle.");
if (triangleType.IsSet && triangleType.Value == null)
throw new ArgumentNullException(nameof(triangleType), "Property is not nullable for class EquilateralTriangle.");
return new EquilateralTriangle(shapeType.Value!, triangleType.Value!);
} }
/// <summary> /// <summary>
@ -176,7 +182,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, EquilateralTriangle equilateralTriangle, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, EquilateralTriangle equilateralTriangle, JsonSerializerOptions jsonSerializerOptions)
{ {
if (equilateralTriangle.ShapeType == null)
throw new ArgumentNullException(nameof(equilateralTriangle.ShapeType), "Property is required for class EquilateralTriangle.");
if (equilateralTriangle.TriangleType == null)
throw new ArgumentNullException(nameof(equilateralTriangle.TriangleType), "Property is required for class EquilateralTriangle.");
writer.WriteString("shapeType", equilateralTriangle.ShapeType); writer.WriteString("shapeType", equilateralTriangle.ShapeType);
writer.WriteString("triangleType", equilateralTriangle.TriangleType); writer.WriteString("triangleType", equilateralTriangle.TriangleType);
} }
} }

View File

@ -37,20 +37,27 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="sourceURI">Test capitalization</param> /// <param name="sourceURI">Test capitalization</param>
[JsonConstructor] [JsonConstructor]
public File(string sourceURI) public File(Option<string?> sourceURI = default)
{ {
SourceURI = sourceURI; SourceURIOption = sourceURI;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of SourceURI
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> SourceURIOption { get; private set; }
/// <summary> /// <summary>
/// Test capitalization /// Test capitalization
/// </summary> /// </summary>
/// <value>Test capitalization</value> /// <value>Test capitalization</value>
[JsonPropertyName("sourceURI")] [JsonPropertyName("sourceURI")]
public string SourceURI { get; set; } public string? SourceURI { get { return this. SourceURIOption; } set { this.SourceURIOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -105,7 +112,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? sourceURI = default; Option<string?> sourceURI = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "sourceURI": case "sourceURI":
sourceURI = utf8JsonReader.GetString(); sourceURI = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -131,8 +138,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (sourceURI == null) if (sourceURI.IsSet && sourceURI.Value == null)
throw new ArgumentNullException(nameof(sourceURI), "Property is required for class File."); throw new ArgumentNullException(nameof(sourceURI), "Property is not nullable for class File.");
return new File(sourceURI); return new File(sourceURI);
} }
@ -161,7 +168,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, File file, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, File file, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("sourceURI", file.SourceURI); if (file.SourceURIOption.IsSet && file.SourceURI == null)
throw new ArgumentNullException(nameof(file.SourceURI), "Property is required for class File.");
if (file.SourceURIOption.IsSet)
writer.WriteString("sourceURI", file.SourceURI);
} }
} }

View File

@ -38,26 +38,40 @@ namespace UseSourceGeneration.Model
/// <param name="file">file</param> /// <param name="file">file</param>
/// <param name="files">files</param> /// <param name="files">files</param>
[JsonConstructor] [JsonConstructor]
public FileSchemaTestClass(File file, List<File> files) public FileSchemaTestClass(Option<File?> file = default, Option<List<File>?> files = default)
{ {
File = file; FileOption = file;
Files = files; FilesOption = files;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of File
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<File?> FileOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets File /// Gets or Sets File
/// </summary> /// </summary>
[JsonPropertyName("file")] [JsonPropertyName("file")]
public File File { get; set; } public File? File { get { return this. FileOption; } set { this.FileOption = new(value); } }
/// <summary>
/// Used to track the state of Files
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<File>?> FilesOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Files /// Gets or Sets Files
/// </summary> /// </summary>
[JsonPropertyName("files")] [JsonPropertyName("files")]
public List<File> Files { get; set; } public List<File>? Files { get { return this. FilesOption; } set { this.FilesOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -113,8 +127,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
File? file = default; Option<File?> file = default;
List<File>? files = default; Option<List<File>?> files = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -133,11 +147,11 @@ namespace UseSourceGeneration.Model
{ {
case "file": case "file":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
file = JsonSerializer.Deserialize<File>(ref utf8JsonReader, jsonSerializerOptions); file = new Option<File?>(JsonSerializer.Deserialize<File>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "files": case "files":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
files = JsonSerializer.Deserialize<List<File>>(ref utf8JsonReader, jsonSerializerOptions); files = new Option<List<File>?>(JsonSerializer.Deserialize<List<File>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -145,11 +159,11 @@ namespace UseSourceGeneration.Model
} }
} }
if (file == null) if (file.IsSet && file.Value == null)
throw new ArgumentNullException(nameof(file), "Property is required for class FileSchemaTestClass."); throw new ArgumentNullException(nameof(file), "Property is not nullable for class FileSchemaTestClass.");
if (files == null) if (files.IsSet && files.Value == null)
throw new ArgumentNullException(nameof(files), "Property is required for class FileSchemaTestClass."); throw new ArgumentNullException(nameof(files), "Property is not nullable for class FileSchemaTestClass.");
return new FileSchemaTestClass(file, files); return new FileSchemaTestClass(file, files);
} }
@ -178,10 +192,22 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, FileSchemaTestClass fileSchemaTestClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, FileSchemaTestClass fileSchemaTestClass, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("file"); if (fileSchemaTestClass.FileOption.IsSet && fileSchemaTestClass.File == null)
JsonSerializer.Serialize(writer, fileSchemaTestClass.File, jsonSerializerOptions); throw new ArgumentNullException(nameof(fileSchemaTestClass.File), "Property is required for class FileSchemaTestClass.");
writer.WritePropertyName("files");
JsonSerializer.Serialize(writer, fileSchemaTestClass.Files, jsonSerializerOptions); if (fileSchemaTestClass.FilesOption.IsSet && fileSchemaTestClass.Files == null)
throw new ArgumentNullException(nameof(fileSchemaTestClass.Files), "Property is required for class FileSchemaTestClass.");
if (fileSchemaTestClass.FileOption.IsSet)
{
writer.WritePropertyName("file");
JsonSerializer.Serialize(writer, fileSchemaTestClass.File, jsonSerializerOptions);
}
if (fileSchemaTestClass.FilesOption.IsSet)
{
writer.WritePropertyName("files");
JsonSerializer.Serialize(writer, fileSchemaTestClass.Files, jsonSerializerOptions);
}
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="bar">bar (default to &quot;bar&quot;)</param> /// <param name="bar">bar (default to &quot;bar&quot;)</param>
[JsonConstructor] [JsonConstructor]
public Foo(string bar = @"bar") public Foo(Option<string?> bar = default)
{ {
Bar = bar; BarOption = bar;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Bar
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> BarOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Bar /// Gets or Sets Bar
/// </summary> /// </summary>
[JsonPropertyName("bar")] [JsonPropertyName("bar")]
public string Bar { get; set; } public string? Bar { get { return this. BarOption; } set { this.BarOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? bar = default; Option<string?> bar = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +129,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "bar": case "bar":
bar = utf8JsonReader.GetString(); bar = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,8 +137,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (bar == null) if (bar.IsSet && bar.Value == null)
throw new ArgumentNullException(nameof(bar), "Property is required for class Foo."); throw new ArgumentNullException(nameof(bar), "Property is not nullable for class Foo.");
return new Foo(bar); return new Foo(bar);
} }
@ -160,7 +167,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Foo foo, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Foo foo, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("bar", foo.Bar); if (foo.BarOption.IsSet && foo.Bar == null)
throw new ArgumentNullException(nameof(foo.Bar), "Property is required for class Foo.");
if (foo.BarOption.IsSet)
writer.WriteString("bar", foo.Bar);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="varString">varString</param> /// <param name="varString">varString</param>
[JsonConstructor] [JsonConstructor]
public FooGetDefaultResponse(Foo varString) public FooGetDefaultResponse(Option<Foo?> varString = default)
{ {
VarString = varString; VarStringOption = varString;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of VarString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Foo?> VarStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets VarString /// Gets or Sets VarString
/// </summary> /// </summary>
[JsonPropertyName("string")] [JsonPropertyName("string")]
public Foo VarString { get; set; } public Foo? VarString { get { return this. VarStringOption; } set { this.VarStringOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Foo? varString = default; Option<Foo?> varString = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
{ {
case "string": case "string":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
varString = JsonSerializer.Deserialize<Foo>(ref utf8JsonReader, jsonSerializerOptions); varString = new Option<Foo?>(JsonSerializer.Deserialize<Foo>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -131,8 +138,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (varString == null) if (varString.IsSet && varString.Value == null)
throw new ArgumentNullException(nameof(varString), "Property is required for class FooGetDefaultResponse."); throw new ArgumentNullException(nameof(varString), "Property is not nullable for class FooGetDefaultResponse.");
return new FooGetDefaultResponse(varString); return new FooGetDefaultResponse(varString);
} }
@ -161,8 +168,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, FooGetDefaultResponse fooGetDefaultResponse, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, FooGetDefaultResponse fooGetDefaultResponse, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("string"); if (fooGetDefaultResponse.VarStringOption.IsSet && fooGetDefaultResponse.VarString == null)
JsonSerializer.Serialize(writer, fooGetDefaultResponse.VarString, jsonSerializerOptions); throw new ArgumentNullException(nameof(fooGetDefaultResponse.VarString), "Property is required for class FooGetDefaultResponse.");
if (fooGetDefaultResponse.VarStringOption.IsSet)
{
writer.WritePropertyName("string");
JsonSerializer.Serialize(writer, fooGetDefaultResponse.VarString, jsonSerializerOptions);
}
} }
} }

View File

@ -35,9 +35,11 @@ namespace UseSourceGeneration.Model
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FormatTest" /> class. /// Initializes a new instance of the <see cref="FormatTest" /> class.
/// </summary> /// </summary>
/// <param name="binary">binary</param>
/// <param name="varByte">varByte</param> /// <param name="varByte">varByte</param>
/// <param name="date">date</param> /// <param name="date">date</param>
/// <param name="number">number</param>
/// <param name="password">password</param>
/// <param name="binary">binary</param>
/// <param name="dateTime">dateTime</param> /// <param name="dateTime">dateTime</param>
/// <param name="varDecimal">varDecimal</param> /// <param name="varDecimal">varDecimal</param>
/// <param name="varDouble">varDouble</param> /// <param name="varDouble">varDouble</param>
@ -45,8 +47,6 @@ namespace UseSourceGeneration.Model
/// <param name="int32">int32</param> /// <param name="int32">int32</param>
/// <param name="int64">int64</param> /// <param name="int64">int64</param>
/// <param name="integer">integer</param> /// <param name="integer">integer</param>
/// <param name="number">number</param>
/// <param name="password">password</param>
/// <param name="patternWithBackslash">None</param> /// <param name="patternWithBackslash">None</param>
/// <param name="patternWithDigits">A string that is a 10 digit number. Can have leading zeros.</param> /// <param name="patternWithDigits">A string that is a 10 digit number. Can have leading zeros.</param>
/// <param name="patternWithDigitsAndDelimiter">A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01.</param> /// <param name="patternWithDigitsAndDelimiter">A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01.</param>
@ -55,38 +55,32 @@ namespace UseSourceGeneration.Model
/// <param name="unsignedLong">unsignedLong</param> /// <param name="unsignedLong">unsignedLong</param>
/// <param name="uuid">uuid</param> /// <param name="uuid">uuid</param>
[JsonConstructor] [JsonConstructor]
public FormatTest(System.IO.Stream binary, byte[] varByte, DateTime date, DateTime dateTime, decimal varDecimal, double varDouble, float varFloat, int int32, long int64, int integer, decimal number, string password, string patternWithBackslash, string patternWithDigits, string patternWithDigitsAndDelimiter, string varString, uint unsignedInteger, ulong unsignedLong, Guid uuid) public FormatTest(byte[] varByte, DateTime date, decimal number, string password, Option<System.IO.Stream?> binary = default, Option<DateTime?> dateTime = default, Option<decimal?> varDecimal = default, Option<double?> varDouble = default, Option<float?> varFloat = default, Option<int?> int32 = default, Option<long?> int64 = default, Option<int?> integer = default, Option<string?> patternWithBackslash = default, Option<string?> patternWithDigits = default, Option<string?> patternWithDigitsAndDelimiter = default, Option<string?> varString = default, Option<uint?> unsignedInteger = default, Option<ulong?> unsignedLong = default, Option<Guid?> uuid = default)
{ {
Binary = binary;
VarByte = varByte; VarByte = varByte;
Date = date; Date = date;
DateTime = dateTime;
VarDecimal = varDecimal;
VarDouble = varDouble;
VarFloat = varFloat;
Int32 = int32;
Int64 = int64;
Integer = integer;
Number = number; Number = number;
Password = password; Password = password;
PatternWithBackslash = patternWithBackslash; BinaryOption = binary;
PatternWithDigits = patternWithDigits; DateTimeOption = dateTime;
PatternWithDigitsAndDelimiter = patternWithDigitsAndDelimiter; VarDecimalOption = varDecimal;
VarString = varString; VarDoubleOption = varDouble;
UnsignedInteger = unsignedInteger; VarFloatOption = varFloat;
UnsignedLong = unsignedLong; Int32Option = int32;
Uuid = uuid; Int64Option = int64;
IntegerOption = integer;
PatternWithBackslashOption = patternWithBackslash;
PatternWithDigitsOption = patternWithDigits;
PatternWithDigitsAndDelimiterOption = patternWithDigitsAndDelimiter;
VarStringOption = varString;
UnsignedIntegerOption = unsignedInteger;
UnsignedLongOption = unsignedLong;
UuidOption = uuid;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Gets or Sets Binary
/// </summary>
[JsonPropertyName("binary")]
public System.IO.Stream Binary { get; set; }
/// <summary> /// <summary>
/// Gets or Sets VarByte /// Gets or Sets VarByte
/// </summary> /// </summary>
@ -100,49 +94,6 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("date")] [JsonPropertyName("date")]
public DateTime Date { get; set; } public DateTime Date { get; set; }
/// <summary>
/// Gets or Sets DateTime
/// </summary>
/// <example>2007-12-03T10:15:30+01:00</example>
[JsonPropertyName("dateTime")]
public DateTime DateTime { get; set; }
/// <summary>
/// Gets or Sets VarDecimal
/// </summary>
[JsonPropertyName("decimal")]
public decimal VarDecimal { get; set; }
/// <summary>
/// Gets or Sets VarDouble
/// </summary>
[JsonPropertyName("double")]
public double VarDouble { get; set; }
/// <summary>
/// Gets or Sets VarFloat
/// </summary>
[JsonPropertyName("float")]
public float VarFloat { get; set; }
/// <summary>
/// Gets or Sets Int32
/// </summary>
[JsonPropertyName("int32")]
public int Int32 { get; set; }
/// <summary>
/// Gets or Sets Int64
/// </summary>
[JsonPropertyName("int64")]
public long Int64 { get; set; }
/// <summary>
/// Gets or Sets Integer
/// </summary>
[JsonPropertyName("integer")]
public int Integer { get; set; }
/// <summary> /// <summary>
/// Gets or Sets Number /// Gets or Sets Number
/// </summary> /// </summary>
@ -155,51 +106,205 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("password")] [JsonPropertyName("password")]
public string Password { get; set; } public string Password { get; set; }
/// <summary>
/// Used to track the state of Binary
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<System.IO.Stream?> BinaryOption { get; private set; }
/// <summary>
/// Gets or Sets Binary
/// </summary>
[JsonPropertyName("binary")]
public System.IO.Stream? Binary { get { return this. BinaryOption; } set { this.BinaryOption = new(value); } }
/// <summary>
/// Used to track the state of DateTime
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DateTime?> DateTimeOption { get; private set; }
/// <summary>
/// Gets or Sets DateTime
/// </summary>
/// <example>2007-12-03T10:15:30+01:00</example>
[JsonPropertyName("dateTime")]
public DateTime? DateTime { get { return this. DateTimeOption; } set { this.DateTimeOption = new(value); } }
/// <summary>
/// Used to track the state of VarDecimal
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<decimal?> VarDecimalOption { get; private set; }
/// <summary>
/// Gets or Sets VarDecimal
/// </summary>
[JsonPropertyName("decimal")]
public decimal? VarDecimal { get { return this. VarDecimalOption; } set { this.VarDecimalOption = new(value); } }
/// <summary>
/// Used to track the state of VarDouble
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<double?> VarDoubleOption { get; private set; }
/// <summary>
/// Gets or Sets VarDouble
/// </summary>
[JsonPropertyName("double")]
public double? VarDouble { get { return this. VarDoubleOption; } set { this.VarDoubleOption = new(value); } }
/// <summary>
/// Used to track the state of VarFloat
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<float?> VarFloatOption { get; private set; }
/// <summary>
/// Gets or Sets VarFloat
/// </summary>
[JsonPropertyName("float")]
public float? VarFloat { get { return this. VarFloatOption; } set { this.VarFloatOption = new(value); } }
/// <summary>
/// Used to track the state of Int32
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> Int32Option { get; private set; }
/// <summary>
/// Gets or Sets Int32
/// </summary>
[JsonPropertyName("int32")]
public int? Int32 { get { return this. Int32Option; } set { this.Int32Option = new(value); } }
/// <summary>
/// Used to track the state of Int64
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<long?> Int64Option { get; private set; }
/// <summary>
/// Gets or Sets Int64
/// </summary>
[JsonPropertyName("int64")]
public long? Int64 { get { return this. Int64Option; } set { this.Int64Option = new(value); } }
/// <summary>
/// Used to track the state of Integer
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> IntegerOption { get; private set; }
/// <summary>
/// Gets or Sets Integer
/// </summary>
[JsonPropertyName("integer")]
public int? Integer { get { return this. IntegerOption; } set { this.IntegerOption = new(value); } }
/// <summary>
/// Used to track the state of PatternWithBackslash
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> PatternWithBackslashOption { get; private set; }
/// <summary> /// <summary>
/// None /// None
/// </summary> /// </summary>
/// <value>None</value> /// <value>None</value>
[JsonPropertyName("pattern_with_backslash")] [JsonPropertyName("pattern_with_backslash")]
public string PatternWithBackslash { get; set; } public string? PatternWithBackslash { get { return this. PatternWithBackslashOption; } set { this.PatternWithBackslashOption = new(value); } }
/// <summary>
/// Used to track the state of PatternWithDigits
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> PatternWithDigitsOption { get; private set; }
/// <summary> /// <summary>
/// A string that is a 10 digit number. Can have leading zeros. /// A string that is a 10 digit number. Can have leading zeros.
/// </summary> /// </summary>
/// <value>A string that is a 10 digit number. Can have leading zeros.</value> /// <value>A string that is a 10 digit number. Can have leading zeros.</value>
[JsonPropertyName("pattern_with_digits")] [JsonPropertyName("pattern_with_digits")]
public string PatternWithDigits { get; set; } public string? PatternWithDigits { get { return this. PatternWithDigitsOption; } set { this.PatternWithDigitsOption = new(value); } }
/// <summary>
/// Used to track the state of PatternWithDigitsAndDelimiter
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> PatternWithDigitsAndDelimiterOption { get; private set; }
/// <summary> /// <summary>
/// A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01. /// A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01.
/// </summary> /// </summary>
/// <value>A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01.</value> /// <value>A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01.</value>
[JsonPropertyName("pattern_with_digits_and_delimiter")] [JsonPropertyName("pattern_with_digits_and_delimiter")]
public string PatternWithDigitsAndDelimiter { get; set; } public string? PatternWithDigitsAndDelimiter { get { return this. PatternWithDigitsAndDelimiterOption; } set { this.PatternWithDigitsAndDelimiterOption = new(value); } }
/// <summary>
/// Used to track the state of VarString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> VarStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets VarString /// Gets or Sets VarString
/// </summary> /// </summary>
[JsonPropertyName("string")] [JsonPropertyName("string")]
public string VarString { get; set; } public string? VarString { get { return this. VarStringOption; } set { this.VarStringOption = new(value); } }
/// <summary>
/// Used to track the state of UnsignedInteger
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<uint?> UnsignedIntegerOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets UnsignedInteger /// Gets or Sets UnsignedInteger
/// </summary> /// </summary>
[JsonPropertyName("unsigned_integer")] [JsonPropertyName("unsigned_integer")]
public uint UnsignedInteger { get; set; } public uint? UnsignedInteger { get { return this. UnsignedIntegerOption; } set { this.UnsignedIntegerOption = new(value); } }
/// <summary>
/// Used to track the state of UnsignedLong
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<ulong?> UnsignedLongOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets UnsignedLong /// Gets or Sets UnsignedLong
/// </summary> /// </summary>
[JsonPropertyName("unsigned_long")] [JsonPropertyName("unsigned_long")]
public ulong UnsignedLong { get; set; } public ulong? UnsignedLong { get { return this. UnsignedLongOption; } set { this.UnsignedLongOption = new(value); } }
/// <summary>
/// Used to track the state of Uuid
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Guid?> UuidOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Uuid /// Gets or Sets Uuid
/// </summary> /// </summary>
/// <example>72f98069-206d-4f12-9f12-3d1e525a8e84</example> /// <example>72f98069-206d-4f12-9f12-3d1e525a8e84</example>
[JsonPropertyName("uuid")] [JsonPropertyName("uuid")]
public Guid Uuid { get; set; } public Guid? Uuid { get { return this. UuidOption; } set { this.UuidOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -215,9 +320,11 @@ namespace UseSourceGeneration.Model
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("class FormatTest {\n"); sb.Append("class FormatTest {\n");
sb.Append(" Binary: ").Append(Binary).Append("\n");
sb.Append(" VarByte: ").Append(VarByte).Append("\n"); sb.Append(" VarByte: ").Append(VarByte).Append("\n");
sb.Append(" Date: ").Append(Date).Append("\n"); sb.Append(" Date: ").Append(Date).Append("\n");
sb.Append(" Number: ").Append(Number).Append("\n");
sb.Append(" Password: ").Append(Password).Append("\n");
sb.Append(" Binary: ").Append(Binary).Append("\n");
sb.Append(" DateTime: ").Append(DateTime).Append("\n"); sb.Append(" DateTime: ").Append(DateTime).Append("\n");
sb.Append(" VarDecimal: ").Append(VarDecimal).Append("\n"); sb.Append(" VarDecimal: ").Append(VarDecimal).Append("\n");
sb.Append(" VarDouble: ").Append(VarDouble).Append("\n"); sb.Append(" VarDouble: ").Append(VarDouble).Append("\n");
@ -225,8 +332,6 @@ namespace UseSourceGeneration.Model
sb.Append(" Int32: ").Append(Int32).Append("\n"); sb.Append(" Int32: ").Append(Int32).Append("\n");
sb.Append(" Int64: ").Append(Int64).Append("\n"); sb.Append(" Int64: ").Append(Int64).Append("\n");
sb.Append(" Integer: ").Append(Integer).Append("\n"); sb.Append(" Integer: ").Append(Integer).Append("\n");
sb.Append(" Number: ").Append(Number).Append("\n");
sb.Append(" Password: ").Append(Password).Append("\n");
sb.Append(" PatternWithBackslash: ").Append(PatternWithBackslash).Append("\n"); sb.Append(" PatternWithBackslash: ").Append(PatternWithBackslash).Append("\n");
sb.Append(" PatternWithDigits: ").Append(PatternWithDigits).Append("\n"); sb.Append(" PatternWithDigits: ").Append(PatternWithDigits).Append("\n");
sb.Append(" PatternWithDigitsAndDelimiter: ").Append(PatternWithDigitsAndDelimiter).Append("\n"); sb.Append(" PatternWithDigitsAndDelimiter: ").Append(PatternWithDigitsAndDelimiter).Append("\n");
@ -246,54 +351,6 @@ namespace UseSourceGeneration.Model
/// <returns>Validation Result</returns> /// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{ {
// VarDouble (double) maximum
if (this.VarDouble > (double)123.4)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarDouble, must be a value less than or equal to 123.4.", new [] { "VarDouble" });
}
// VarDouble (double) minimum
if (this.VarDouble < (double)67.8)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarDouble, must be a value greater than or equal to 67.8.", new [] { "VarDouble" });
}
// VarFloat (float) maximum
if (this.VarFloat > (float)987.6)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarFloat, must be a value less than or equal to 987.6.", new [] { "VarFloat" });
}
// VarFloat (float) minimum
if (this.VarFloat < (float)54.3)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarFloat, must be a value greater than or equal to 54.3.", new [] { "VarFloat" });
}
// Int32 (int) maximum
if (this.Int32 > (int)200)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Int32, must be a value less than or equal to 200.", new [] { "Int32" });
}
// Int32 (int) minimum
if (this.Int32 < (int)20)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Int32, must be a value greater than or equal to 20.", new [] { "Int32" });
}
// Integer (int) maximum
if (this.Integer > (int)100)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Integer, must be a value less than or equal to 100.", new [] { "Integer" });
}
// Integer (int) minimum
if (this.Integer < (int)10)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Integer, must be a value greater than or equal to 10.", new [] { "Integer" });
}
// Number (decimal) maximum // Number (decimal) maximum
if (this.Number > (decimal)543.2) if (this.Number > (decimal)543.2)
{ {
@ -318,50 +375,102 @@ namespace UseSourceGeneration.Model
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Password, length must be greater than 10.", new [] { "Password" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Password, length must be greater than 10.", new [] { "Password" });
} }
if (this.PatternWithBackslash != null) { // VarDouble (double) maximum
if (this.VarDoubleOption.IsSet && this.VarDoubleOption.Value > (double)123.4)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarDouble, must be a value less than or equal to 123.4.", new [] { "VarDouble" });
}
// VarDouble (double) minimum
if (this.VarDoubleOption.IsSet && this.VarDoubleOption.Value < (double)67.8)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarDouble, must be a value greater than or equal to 67.8.", new [] { "VarDouble" });
}
// VarFloat (float) maximum
if (this.VarFloatOption.IsSet && this.VarFloatOption.Value > (float)987.6)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarFloat, must be a value less than or equal to 987.6.", new [] { "VarFloat" });
}
// VarFloat (float) minimum
if (this.VarFloatOption.IsSet && this.VarFloatOption.Value < (float)54.3)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarFloat, must be a value greater than or equal to 54.3.", new [] { "VarFloat" });
}
// Int32 (int) maximum
if (this.Int32Option.IsSet && this.Int32Option.Value > (int)200)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Int32, must be a value less than or equal to 200.", new [] { "Int32" });
}
// Int32 (int) minimum
if (this.Int32Option.IsSet && this.Int32Option.Value < (int)20)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Int32, must be a value greater than or equal to 20.", new [] { "Int32" });
}
// Integer (int) maximum
if (this.IntegerOption.IsSet && this.IntegerOption.Value > (int)100)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Integer, must be a value less than or equal to 100.", new [] { "Integer" });
}
// Integer (int) minimum
if (this.IntegerOption.IsSet && this.IntegerOption.Value < (int)10)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Integer, must be a value greater than or equal to 10.", new [] { "Integer" });
}
if (this.PatternWithBackslashOption.Value != null) {
// PatternWithBackslash (string) pattern // PatternWithBackslash (string) pattern
Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant); Regex regexPatternWithBackslash = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$", RegexOptions.CultureInvariant);
if (!regexPatternWithBackslash.Match(this.PatternWithBackslash).Success)
if (this.PatternWithBackslashOption.Value != null &&!regexPatternWithBackslash.Match(this.PatternWithBackslashOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithBackslash, must match a pattern of " + regexPatternWithBackslash, new [] { "PatternWithBackslash" });
} }
} }
if (this.PatternWithDigits != null) { if (this.PatternWithDigitsOption.Value != null) {
// PatternWithDigits (string) pattern // PatternWithDigits (string) pattern
Regex regexPatternWithDigits = new Regex(@"^\d{10}$", RegexOptions.CultureInvariant); Regex regexPatternWithDigits = new Regex(@"^\d{10}$", RegexOptions.CultureInvariant);
if (!regexPatternWithDigits.Match(this.PatternWithDigits).Success)
if (this.PatternWithDigitsOption.Value != null &&!regexPatternWithDigits.Match(this.PatternWithDigitsOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigits, must match a pattern of " + regexPatternWithDigits, new [] { "PatternWithDigits" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigits, must match a pattern of " + regexPatternWithDigits, new [] { "PatternWithDigits" });
} }
} }
if (this.PatternWithDigitsAndDelimiter != null) { if (this.PatternWithDigitsAndDelimiterOption.Value != null) {
// PatternWithDigitsAndDelimiter (string) pattern // PatternWithDigitsAndDelimiter (string) pattern
Regex regexPatternWithDigitsAndDelimiter = new Regex(@"^image_\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); Regex regexPatternWithDigitsAndDelimiter = new Regex(@"^image_\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (!regexPatternWithDigitsAndDelimiter.Match(this.PatternWithDigitsAndDelimiter).Success)
if (this.PatternWithDigitsAndDelimiterOption.Value != null &&!regexPatternWithDigitsAndDelimiter.Match(this.PatternWithDigitsAndDelimiterOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigitsAndDelimiter, must match a pattern of " + regexPatternWithDigitsAndDelimiter, new [] { "PatternWithDigitsAndDelimiter" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigitsAndDelimiter, must match a pattern of " + regexPatternWithDigitsAndDelimiter, new [] { "PatternWithDigitsAndDelimiter" });
} }
} }
if (this.VarString != null) { if (this.VarStringOption.Value != null) {
// VarString (string) pattern // VarString (string) pattern
Regex regexVarString = new Regex(@"[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); Regex regexVarString = new Regex(@"[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (!regexVarString.Match(this.VarString).Success)
if (this.VarStringOption.Value != null &&!regexVarString.Match(this.VarStringOption.Value).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarString, must match a pattern of " + regexVarString, new [] { "VarString" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for VarString, must match a pattern of " + regexVarString, new [] { "VarString" });
} }
} }
// UnsignedInteger (uint) maximum // UnsignedInteger (uint) maximum
if (this.UnsignedInteger > (uint)200) if (this.UnsignedIntegerOption.IsSet && this.UnsignedIntegerOption.Value > (uint)200)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UnsignedInteger, must be a value less than or equal to 200.", new [] { "UnsignedInteger" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UnsignedInteger, must be a value less than or equal to 200.", new [] { "UnsignedInteger" });
} }
// UnsignedInteger (uint) minimum // UnsignedInteger (uint) minimum
if (this.UnsignedInteger < (uint)20) if (this.UnsignedIntegerOption.IsSet && this.UnsignedIntegerOption.Value < (uint)20)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UnsignedInteger, must be a value greater than or equal to 20.", new [] { "UnsignedInteger" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UnsignedInteger, must be a value greater than or equal to 20.", new [] { "UnsignedInteger" });
} }
@ -402,25 +511,25 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
System.IO.Stream? binary = default; Option<byte[]?> varByte = default;
byte[]? varByte = default; Option<DateTime?> date = default;
DateTime? date = default; Option<decimal?> number = default;
DateTime? dateTime = default; Option<string?> password = default;
decimal? varDecimal = default; Option<System.IO.Stream?> binary = default;
double? varDouble = default; Option<DateTime?> dateTime = default;
float? varFloat = default; Option<decimal?> varDecimal = default;
int? int32 = default; Option<double?> varDouble = default;
long? int64 = default; Option<float?> varFloat = default;
int? integer = default; Option<int?> int32 = default;
decimal? number = default; Option<long?> int64 = default;
string? password = default; Option<int?> integer = default;
string? patternWithBackslash = default; Option<string?> patternWithBackslash = default;
string? patternWithDigits = default; Option<string?> patternWithDigits = default;
string? patternWithDigitsAndDelimiter = default; Option<string?> patternWithDigitsAndDelimiter = default;
string? varString = default; Option<string?> varString = default;
uint? unsignedInteger = default; Option<uint?> unsignedInteger = default;
ulong? unsignedLong = default; Option<ulong?> unsignedLong = default;
Guid? uuid = default; Option<Guid?> uuid = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -437,76 +546,76 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "binary":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
binary = JsonSerializer.Deserialize<System.IO.Stream>(ref utf8JsonReader, jsonSerializerOptions);
break;
case "byte": case "byte":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
varByte = JsonSerializer.Deserialize<byte[]>(ref utf8JsonReader, jsonSerializerOptions); varByte = new Option<byte[]?>(JsonSerializer.Deserialize<byte[]>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "date": case "date":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
date = JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions); date = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "dateTime":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateTime = JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions);
break;
case "decimal":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
varDecimal = JsonSerializer.Deserialize<decimal>(ref utf8JsonReader, jsonSerializerOptions);
break;
case "double":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
varDouble = utf8JsonReader.GetDouble();
break;
case "float":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
varFloat = (float)utf8JsonReader.GetDouble();
break;
case "int32":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
int32 = utf8JsonReader.GetInt32();
break;
case "int64":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
int64 = utf8JsonReader.GetInt64();
break;
case "integer":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
integer = utf8JsonReader.GetInt32();
break; break;
case "number": case "number":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
number = utf8JsonReader.GetDecimal(); number = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
case "password": case "password":
password = utf8JsonReader.GetString(); password = new Option<string?>(utf8JsonReader.GetString()!);
break;
case "binary":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
binary = new Option<System.IO.Stream?>(JsonSerializer.Deserialize<System.IO.Stream>(ref utf8JsonReader, jsonSerializerOptions)!);
break;
case "dateTime":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateTime = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "decimal":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
varDecimal = new Option<decimal?>(JsonSerializer.Deserialize<decimal>(ref utf8JsonReader, jsonSerializerOptions)!);
break;
case "double":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
varDouble = new Option<double?>(utf8JsonReader.GetDouble());
break;
case "float":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
varFloat = new Option<float?>((float)utf8JsonReader.GetDouble());
break;
case "int32":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
int32 = new Option<int?>(utf8JsonReader.GetInt32());
break;
case "int64":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
int64 = new Option<long?>(utf8JsonReader.GetInt64());
break;
case "integer":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
integer = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
case "pattern_with_backslash": case "pattern_with_backslash":
patternWithBackslash = utf8JsonReader.GetString(); patternWithBackslash = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "pattern_with_digits": case "pattern_with_digits":
patternWithDigits = utf8JsonReader.GetString(); patternWithDigits = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "pattern_with_digits_and_delimiter": case "pattern_with_digits_and_delimiter":
patternWithDigitsAndDelimiter = utf8JsonReader.GetString(); patternWithDigitsAndDelimiter = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "string": case "string":
varString = utf8JsonReader.GetString(); varString = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "unsigned_integer": case "unsigned_integer":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
unsignedInteger = utf8JsonReader.GetUInt32(); unsignedInteger = new Option<uint?>(utf8JsonReader.GetUInt32());
break; break;
case "unsigned_long": case "unsigned_long":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
unsignedLong = utf8JsonReader.GetUInt64(); unsignedLong = new Option<ulong?>(utf8JsonReader.GetUInt64());
break; break;
case "uuid": case "uuid":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
uuid = utf8JsonReader.GetGuid(); uuid = new Option<Guid?>(utf8JsonReader.GetGuid());
break; break;
default: default:
break; break;
@ -514,64 +623,76 @@ namespace UseSourceGeneration.Model
} }
} }
if (binary == null) if (!varByte.IsSet)
throw new ArgumentNullException(nameof(binary), "Property is required for class FormatTest."); throw new ArgumentException("Property is required for class FormatTest.", nameof(varByte));
if (varByte == null) if (!date.IsSet)
throw new ArgumentNullException(nameof(varByte), "Property is required for class FormatTest."); throw new ArgumentException("Property is required for class FormatTest.", nameof(date));
if (date == null) if (!number.IsSet)
throw new ArgumentNullException(nameof(date), "Property is required for class FormatTest."); throw new ArgumentException("Property is required for class FormatTest.", nameof(number));
if (dateTime == null) if (!password.IsSet)
throw new ArgumentNullException(nameof(dateTime), "Property is required for class FormatTest."); throw new ArgumentException("Property is required for class FormatTest.", nameof(password));
if (varDecimal == null) if (varByte.IsSet && varByte.Value == null)
throw new ArgumentNullException(nameof(varDecimal), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(varByte), "Property is not nullable for class FormatTest.");
if (varDouble == null) if (date.IsSet && date.Value == null)
throw new ArgumentNullException(nameof(varDouble), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(date), "Property is not nullable for class FormatTest.");
if (varFloat == null) if (number.IsSet && number.Value == null)
throw new ArgumentNullException(nameof(varFloat), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(number), "Property is not nullable for class FormatTest.");
if (int32 == null) if (password.IsSet && password.Value == null)
throw new ArgumentNullException(nameof(int32), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(password), "Property is not nullable for class FormatTest.");
if (int64 == null) if (binary.IsSet && binary.Value == null)
throw new ArgumentNullException(nameof(int64), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(binary), "Property is not nullable for class FormatTest.");
if (integer == null) if (dateTime.IsSet && dateTime.Value == null)
throw new ArgumentNullException(nameof(integer), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(dateTime), "Property is not nullable for class FormatTest.");
if (number == null) if (varDecimal.IsSet && varDecimal.Value == null)
throw new ArgumentNullException(nameof(number), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(varDecimal), "Property is not nullable for class FormatTest.");
if (password == null) if (varDouble.IsSet && varDouble.Value == null)
throw new ArgumentNullException(nameof(password), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(varDouble), "Property is not nullable for class FormatTest.");
if (patternWithBackslash == null) if (varFloat.IsSet && varFloat.Value == null)
throw new ArgumentNullException(nameof(patternWithBackslash), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(varFloat), "Property is not nullable for class FormatTest.");
if (patternWithDigits == null) if (int32.IsSet && int32.Value == null)
throw new ArgumentNullException(nameof(patternWithDigits), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(int32), "Property is not nullable for class FormatTest.");
if (patternWithDigitsAndDelimiter == null) if (int64.IsSet && int64.Value == null)
throw new ArgumentNullException(nameof(patternWithDigitsAndDelimiter), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(int64), "Property is not nullable for class FormatTest.");
if (varString == null) if (integer.IsSet && integer.Value == null)
throw new ArgumentNullException(nameof(varString), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(integer), "Property is not nullable for class FormatTest.");
if (unsignedInteger == null) if (patternWithBackslash.IsSet && patternWithBackslash.Value == null)
throw new ArgumentNullException(nameof(unsignedInteger), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(patternWithBackslash), "Property is not nullable for class FormatTest.");
if (unsignedLong == null) if (patternWithDigits.IsSet && patternWithDigits.Value == null)
throw new ArgumentNullException(nameof(unsignedLong), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(patternWithDigits), "Property is not nullable for class FormatTest.");
if (uuid == null) if (patternWithDigitsAndDelimiter.IsSet && patternWithDigitsAndDelimiter.Value == null)
throw new ArgumentNullException(nameof(uuid), "Property is required for class FormatTest."); throw new ArgumentNullException(nameof(patternWithDigitsAndDelimiter), "Property is not nullable for class FormatTest.");
return new FormatTest(binary, varByte, date.Value, dateTime.Value, varDecimal.Value, varDouble.Value, varFloat.Value, int32.Value, int64.Value, integer.Value, number.Value, password, patternWithBackslash, patternWithDigits, patternWithDigitsAndDelimiter, varString, unsignedInteger.Value, unsignedLong.Value, uuid.Value); if (varString.IsSet && varString.Value == null)
throw new ArgumentNullException(nameof(varString), "Property is not nullable for class FormatTest.");
if (unsignedInteger.IsSet && unsignedInteger.Value == null)
throw new ArgumentNullException(nameof(unsignedInteger), "Property is not nullable for class FormatTest.");
if (unsignedLong.IsSet && unsignedLong.Value == null)
throw new ArgumentNullException(nameof(unsignedLong), "Property is not nullable for class FormatTest.");
if (uuid.IsSet && uuid.Value == null)
throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class FormatTest.");
return new FormatTest(varByte.Value!, date.Value!.Value!, number.Value!.Value!, password.Value!, binary, dateTime, varDecimal, varDouble, varFloat, int32, int64, integer, patternWithBackslash, patternWithDigits, patternWithDigitsAndDelimiter, varString, unsignedInteger, unsignedLong, uuid);
} }
/// <summary> /// <summary>
@ -598,28 +719,83 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, FormatTest formatTest, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, FormatTest formatTest, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("binary"); if (formatTest.VarByte == null)
JsonSerializer.Serialize(writer, formatTest.Binary, jsonSerializerOptions); throw new ArgumentNullException(nameof(formatTest.VarByte), "Property is required for class FormatTest.");
if (formatTest.Password == null)
throw new ArgumentNullException(nameof(formatTest.Password), "Property is required for class FormatTest.");
if (formatTest.BinaryOption.IsSet && formatTest.Binary == null)
throw new ArgumentNullException(nameof(formatTest.Binary), "Property is required for class FormatTest.");
if (formatTest.PatternWithBackslashOption.IsSet && formatTest.PatternWithBackslash == null)
throw new ArgumentNullException(nameof(formatTest.PatternWithBackslash), "Property is required for class FormatTest.");
if (formatTest.PatternWithDigitsOption.IsSet && formatTest.PatternWithDigits == null)
throw new ArgumentNullException(nameof(formatTest.PatternWithDigits), "Property is required for class FormatTest.");
if (formatTest.PatternWithDigitsAndDelimiterOption.IsSet && formatTest.PatternWithDigitsAndDelimiter == null)
throw new ArgumentNullException(nameof(formatTest.PatternWithDigitsAndDelimiter), "Property is required for class FormatTest.");
if (formatTest.VarStringOption.IsSet && formatTest.VarString == null)
throw new ArgumentNullException(nameof(formatTest.VarString), "Property is required for class FormatTest.");
writer.WritePropertyName("byte"); writer.WritePropertyName("byte");
JsonSerializer.Serialize(writer, formatTest.VarByte, jsonSerializerOptions); JsonSerializer.Serialize(writer, formatTest.VarByte, jsonSerializerOptions);
writer.WriteString("date", formatTest.Date.ToString(DateFormat)); writer.WriteString("date", formatTest.Date.ToString(DateFormat));
writer.WriteString("dateTime", formatTest.DateTime.ToString(DateTimeFormat));
writer.WritePropertyName("decimal");
JsonSerializer.Serialize(writer, formatTest.VarDecimal, jsonSerializerOptions);
writer.WriteNumber("double", formatTest.VarDouble);
writer.WriteNumber("float", formatTest.VarFloat);
writer.WriteNumber("int32", formatTest.Int32);
writer.WriteNumber("int64", formatTest.Int64);
writer.WriteNumber("integer", formatTest.Integer);
writer.WriteNumber("number", formatTest.Number); writer.WriteNumber("number", formatTest.Number);
writer.WriteString("password", formatTest.Password); writer.WriteString("password", formatTest.Password);
writer.WriteString("pattern_with_backslash", formatTest.PatternWithBackslash);
writer.WriteString("pattern_with_digits", formatTest.PatternWithDigits); if (formatTest.BinaryOption.IsSet)
writer.WriteString("pattern_with_digits_and_delimiter", formatTest.PatternWithDigitsAndDelimiter); {
writer.WriteString("string", formatTest.VarString); writer.WritePropertyName("binary");
writer.WriteNumber("unsigned_integer", formatTest.UnsignedInteger); JsonSerializer.Serialize(writer, formatTest.Binary, jsonSerializerOptions);
writer.WriteNumber("unsigned_long", formatTest.UnsignedLong); }
writer.WriteString("uuid", formatTest.Uuid); if (formatTest.DateTimeOption.IsSet)
writer.WriteString("dateTime", formatTest.DateTimeOption.Value!.Value.ToString(DateTimeFormat));
if (formatTest.VarDecimalOption.IsSet)
{
writer.WritePropertyName("decimal");
JsonSerializer.Serialize(writer, formatTest.VarDecimal, jsonSerializerOptions);
}
if (formatTest.VarDoubleOption.IsSet)
writer.WriteNumber("double", formatTest.VarDoubleOption.Value!.Value);
if (formatTest.VarFloatOption.IsSet)
writer.WriteNumber("float", formatTest.VarFloatOption.Value!.Value);
if (formatTest.Int32Option.IsSet)
writer.WriteNumber("int32", formatTest.Int32Option.Value!.Value);
if (formatTest.Int64Option.IsSet)
writer.WriteNumber("int64", formatTest.Int64Option.Value!.Value);
if (formatTest.IntegerOption.IsSet)
writer.WriteNumber("integer", formatTest.IntegerOption.Value!.Value);
if (formatTest.PatternWithBackslashOption.IsSet)
writer.WriteString("pattern_with_backslash", formatTest.PatternWithBackslash);
if (formatTest.PatternWithDigitsOption.IsSet)
writer.WriteString("pattern_with_digits", formatTest.PatternWithDigits);
if (formatTest.PatternWithDigitsAndDelimiterOption.IsSet)
writer.WriteString("pattern_with_digits_and_delimiter", formatTest.PatternWithDigitsAndDelimiter);
if (formatTest.VarStringOption.IsSet)
writer.WriteString("string", formatTest.VarString);
if (formatTest.UnsignedIntegerOption.IsSet)
writer.WriteNumber("unsigned_integer", formatTest.UnsignedIntegerOption.Value!.Value);
if (formatTest.UnsignedLongOption.IsSet)
writer.WriteNumber("unsigned_long", formatTest.UnsignedLongOption.Value!.Value);
if (formatTest.UuidOption.IsSet)
writer.WriteString("uuid", formatTest.UuidOption.Value!.Value);
} }
} }

View File

@ -37,10 +37,10 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="apple"></param> /// <param name="apple"></param>
/// <param name="color">color</param> /// <param name="color">color</param>
public Fruit(Apple apple, string color) public Fruit(Apple apple, Option<string?> color = default)
{ {
Apple = apple; Apple = apple;
Color = color; ColorOption = color;
OnCreated(); OnCreated();
} }
@ -49,10 +49,10 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="banana"></param> /// <param name="banana"></param>
/// <param name="color">color</param> /// <param name="color">color</param>
public Fruit(Banana banana, string color) public Fruit(Banana banana, Option<string?> color = default)
{ {
Banana = banana; Banana = banana;
Color = color; ColorOption = color;
OnCreated(); OnCreated();
} }
@ -68,11 +68,18 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
public Banana? Banana { get; set; } public Banana? Banana { get; set; }
/// <summary>
/// Used to track the state of Color
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> ColorOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Color /// Gets or Sets Color
/// </summary> /// </summary>
[JsonPropertyName("color")] [JsonPropertyName("color")]
public string Color { get; set; } public string? Color { get { return this. ColorOption; } set { this.ColorOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -120,7 +127,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? color = default; Option<string?> color = default;
Apple? apple = default; Apple? apple = default;
Banana? banana = default; Banana? banana = default;
@ -160,7 +167,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "color": case "color":
color = utf8JsonReader.GetString(); color = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -168,8 +175,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (color == null) if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is required for class Fruit."); throw new ArgumentNullException(nameof(color), "Property is not nullable for class Fruit.");
if (apple != null) if (apple != null)
return new Fruit(apple, color); return new Fruit(apple, color);
@ -204,7 +211,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Fruit fruit, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Fruit fruit, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("color", fruit.Color); if (fruit.ColorOption.IsSet && fruit.Color == null)
throw new ArgumentNullException(nameof(fruit.Color), "Property is required for class Fruit.");
if (fruit.ColorOption.IsSet)
writer.WriteString("color", fruit.Color);
} }
} }

View File

@ -38,31 +38,52 @@ namespace UseSourceGeneration.Model
/// <param name="apple"></param> /// <param name="apple"></param>
/// <param name="banana"></param> /// <param name="banana"></param>
/// <param name="color">color</param> /// <param name="color">color</param>
public GmFruit(Apple? apple, Banana? banana, string color) public GmFruit(Option<Apple?> apple, Option<Banana?> banana, Option<string?> color = default)
{ {
Apple = apple; AppleOption = apple;
Banana = banana; BananaOption = banana;
Color = color; ColorOption = color;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Apple
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Apple?> AppleOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Apple /// Gets or Sets Apple
/// </summary> /// </summary>
public Apple? Apple { get; set; } public Apple? Apple { get { return this.AppleOption; } set { this.AppleOption = new(value); } }
/// <summary>
/// Used to track the state of Banana
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Banana?> BananaOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Banana /// Gets or Sets Banana
/// </summary> /// </summary>
public Banana? Banana { get; set; } public Banana? Banana { get { return this.BananaOption; } set { this.BananaOption = new(value); } }
/// <summary>
/// Used to track the state of Color
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> ColorOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Color /// Gets or Sets Color
/// </summary> /// </summary>
[JsonPropertyName("color")] [JsonPropertyName("color")]
public string Color { get; set; } public string? Color { get { return this. ColorOption; } set { this.ColorOption = new(value); } }
/// <summary> /// <summary>
/// Returns the string presentation of the object /// Returns the string presentation of the object
@ -110,7 +131,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? color = default; Option<string?> color = default;
Apple? apple = default; Apple? apple = default;
Banana? banana = default; Banana? banana = default;
@ -150,7 +171,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "color": case "color":
color = utf8JsonReader.GetString(); color = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -158,10 +179,17 @@ namespace UseSourceGeneration.Model
} }
} }
if (color == null) if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is required for class GmFruit."); throw new ArgumentNullException(nameof(color), "Property is not nullable for class GmFruit.");
return new GmFruit(apple, banana, color); Option<Apple?> appleParsedValue = apple == null
? default
: new Option<Apple?>(apple);
Option<Banana?> bananaParsedValue = banana == null
? default
: new Option<Banana?>(banana);
return new GmFruit(appleParsedValue, bananaParsedValue, color);
} }
/// <summary> /// <summary>
@ -175,16 +203,16 @@ namespace UseSourceGeneration.Model
{ {
writer.WriteStartObject(); writer.WriteStartObject();
if (gmFruit.Apple != null) if (gmFruit.AppleOption.IsSet && gmFruit.AppleOption.Value != null)
{ {
AppleJsonConverter AppleJsonConverter = (AppleJsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert(gmFruit.Apple.GetType())); AppleJsonConverter AppleJsonConverter = (AppleJsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert(gmFruit.AppleOption.Value.GetType()));
AppleJsonConverter.WriteProperties(ref writer, gmFruit.Apple, jsonSerializerOptions); AppleJsonConverter.WriteProperties(ref writer, gmFruit.AppleOption.Value, jsonSerializerOptions);
} }
if (gmFruit.Banana != null) if (gmFruit.BananaOption.IsSet && gmFruit.BananaOption.Value != null)
{ {
BananaJsonConverter BananaJsonConverter = (BananaJsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert(gmFruit.Banana.GetType())); BananaJsonConverter BananaJsonConverter = (BananaJsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert(gmFruit.BananaOption.Value.GetType()));
BananaJsonConverter.WriteProperties(ref writer, gmFruit.Banana, jsonSerializerOptions); BananaJsonConverter.WriteProperties(ref writer, gmFruit.BananaOption.Value, jsonSerializerOptions);
} }
WriteProperties(ref writer, gmFruit, jsonSerializerOptions); WriteProperties(ref writer, gmFruit, jsonSerializerOptions);
@ -200,7 +228,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, GmFruit gmFruit, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, GmFruit gmFruit, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("color", gmFruit.Color); if (gmFruit.ColorOption.IsSet && gmFruit.Color == null)
throw new ArgumentNullException(nameof(gmFruit.Color), "Property is required for class GmFruit.");
if (gmFruit.ColorOption.IsSet)
writer.WriteString("color", gmFruit.Color);
} }
} }

View File

@ -114,7 +114,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? petType = default; Option<string?> petType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -132,7 +132,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "pet_type": case "pet_type":
petType = utf8JsonReader.GetString(); petType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -140,10 +140,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (petType == null) if (!petType.IsSet)
throw new ArgumentNullException(nameof(petType), "Property is required for class GrandparentAnimal."); throw new ArgumentException("Property is required for class GrandparentAnimal.", nameof(petType));
return new GrandparentAnimal(petType); if (petType.IsSet && petType.Value == null)
throw new ArgumentNullException(nameof(petType), "Property is not nullable for class GrandparentAnimal.");
return new GrandparentAnimal(petType.Value!);
} }
/// <summary> /// <summary>
@ -170,6 +173,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, GrandparentAnimal grandparentAnimal, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, GrandparentAnimal grandparentAnimal, JsonSerializerOptions jsonSerializerOptions)
{ {
if (grandparentAnimal.PetType == null)
throw new ArgumentNullException(nameof(grandparentAnimal.PetType), "Property is required for class GrandparentAnimal.");
writer.WriteString("pet_type", grandparentAnimal.PetType); writer.WriteString("pet_type", grandparentAnimal.PetType);
} }
} }

View File

@ -38,26 +38,40 @@ namespace UseSourceGeneration.Model
/// <param name="bar">bar</param> /// <param name="bar">bar</param>
/// <param name="foo">foo</param> /// <param name="foo">foo</param>
[JsonConstructor] [JsonConstructor]
internal HasOnlyReadOnly(string bar, string foo) internal HasOnlyReadOnly(Option<string?> bar = default, Option<string?> foo = default)
{ {
Bar = bar; BarOption = bar;
Foo = foo; FooOption = foo;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Bar
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> BarOption { get; }
/// <summary> /// <summary>
/// Gets or Sets Bar /// Gets or Sets Bar
/// </summary> /// </summary>
[JsonPropertyName("bar")] [JsonPropertyName("bar")]
public string Bar { get; } public string? Bar { get { return this. BarOption; } }
/// <summary>
/// Used to track the state of Foo
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> FooOption { get; }
/// <summary> /// <summary>
/// Gets or Sets Foo /// Gets or Sets Foo
/// </summary> /// </summary>
[JsonPropertyName("foo")] [JsonPropertyName("foo")]
public string Foo { get; } public string? Foo { get { return this. FooOption; } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -109,8 +123,12 @@ namespace UseSourceGeneration.Model
unchecked // Overflow is fine, just wrap unchecked // Overflow is fine, just wrap
{ {
int hashCode = 41; int hashCode = 41;
hashCode = (hashCode * 59) + Bar.GetHashCode(); if (Bar != null)
hashCode = (hashCode * 59) + Foo.GetHashCode(); hashCode = (hashCode * 59) + Bar.GetHashCode();
if (Foo != null)
hashCode = (hashCode * 59) + Foo.GetHashCode();
hashCode = (hashCode * 59) + AdditionalProperties.GetHashCode(); hashCode = (hashCode * 59) + AdditionalProperties.GetHashCode();
return hashCode; return hashCode;
@ -150,8 +168,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? bar = default; Option<string?> bar = default;
string? foo = default; Option<string?> foo = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -169,10 +187,10 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "bar": case "bar":
bar = utf8JsonReader.GetString(); bar = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "foo": case "foo":
foo = utf8JsonReader.GetString(); foo = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -180,11 +198,11 @@ namespace UseSourceGeneration.Model
} }
} }
if (bar == null) if (bar.IsSet && bar.Value == null)
throw new ArgumentNullException(nameof(bar), "Property is required for class HasOnlyReadOnly."); throw new ArgumentNullException(nameof(bar), "Property is not nullable for class HasOnlyReadOnly.");
if (foo == null) if (foo.IsSet && foo.Value == null)
throw new ArgumentNullException(nameof(foo), "Property is required for class HasOnlyReadOnly."); throw new ArgumentNullException(nameof(foo), "Property is not nullable for class HasOnlyReadOnly.");
return new HasOnlyReadOnly(bar, foo); return new HasOnlyReadOnly(bar, foo);
} }
@ -213,8 +231,17 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, HasOnlyReadOnly hasOnlyReadOnly, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, HasOnlyReadOnly hasOnlyReadOnly, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("bar", hasOnlyReadOnly.Bar); if (hasOnlyReadOnly.BarOption.IsSet && hasOnlyReadOnly.Bar == null)
writer.WriteString("foo", hasOnlyReadOnly.Foo); throw new ArgumentNullException(nameof(hasOnlyReadOnly.Bar), "Property is required for class HasOnlyReadOnly.");
if (hasOnlyReadOnly.FooOption.IsSet && hasOnlyReadOnly.Foo == null)
throw new ArgumentNullException(nameof(hasOnlyReadOnly.Foo), "Property is required for class HasOnlyReadOnly.");
if (hasOnlyReadOnly.BarOption.IsSet)
writer.WriteString("bar", hasOnlyReadOnly.Bar);
if (hasOnlyReadOnly.FooOption.IsSet)
writer.WriteString("foo", hasOnlyReadOnly.Foo);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="nullableMessage">nullableMessage</param> /// <param name="nullableMessage">nullableMessage</param>
[JsonConstructor] [JsonConstructor]
public HealthCheckResult(string? nullableMessage = default) public HealthCheckResult(Option<string?> nullableMessage = default)
{ {
NullableMessage = nullableMessage; NullableMessageOption = nullableMessage;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of NullableMessage
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> NullableMessageOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets NullableMessage /// Gets or Sets NullableMessage
/// </summary> /// </summary>
[JsonPropertyName("NullableMessage")] [JsonPropertyName("NullableMessage")]
public string? NullableMessage { get; set; } public string? NullableMessage { get { return this. NullableMessageOption; } set { this.NullableMessageOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? nullableMessage = default; Option<string?> nullableMessage = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +129,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "NullableMessage": case "NullableMessage":
nullableMessage = utf8JsonReader.GetString(); nullableMessage = new Option<string?>(utf8JsonReader.GetString());
break; break;
default: default:
break; break;
@ -157,7 +164,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, HealthCheckResult healthCheckResult, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, HealthCheckResult healthCheckResult, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("NullableMessage", healthCheckResult.NullableMessage); if (healthCheckResult.NullableMessageOption.IsSet)
if (healthCheckResult.NullableMessageOption.Value != null)
writer.WriteString("NullableMessage", healthCheckResult.NullableMessage);
else
writer.WriteNull("NullableMessage");
} }
} }

View File

@ -106,8 +106,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? shapeType = default; Option<string?> shapeType = default;
string? triangleType = default; Option<string?> triangleType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -125,10 +125,10 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "shapeType": case "shapeType":
shapeType = utf8JsonReader.GetString(); shapeType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "triangleType": case "triangleType":
triangleType = utf8JsonReader.GetString(); triangleType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -136,13 +136,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (shapeType == null) if (!shapeType.IsSet)
throw new ArgumentNullException(nameof(shapeType), "Property is required for class IsoscelesTriangle."); throw new ArgumentException("Property is required for class IsoscelesTriangle.", nameof(shapeType));
if (triangleType == null) if (!triangleType.IsSet)
throw new ArgumentNullException(nameof(triangleType), "Property is required for class IsoscelesTriangle."); throw new ArgumentException("Property is required for class IsoscelesTriangle.", nameof(triangleType));
return new IsoscelesTriangle(shapeType, triangleType); if (shapeType.IsSet && shapeType.Value == null)
throw new ArgumentNullException(nameof(shapeType), "Property is not nullable for class IsoscelesTriangle.");
if (triangleType.IsSet && triangleType.Value == null)
throw new ArgumentNullException(nameof(triangleType), "Property is not nullable for class IsoscelesTriangle.");
return new IsoscelesTriangle(shapeType.Value!, triangleType.Value!);
} }
/// <summary> /// <summary>
@ -169,7 +175,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, IsoscelesTriangle isoscelesTriangle, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, IsoscelesTriangle isoscelesTriangle, JsonSerializerOptions jsonSerializerOptions)
{ {
if (isoscelesTriangle.ShapeType == null)
throw new ArgumentNullException(nameof(isoscelesTriangle.ShapeType), "Property is required for class IsoscelesTriangle.");
if (isoscelesTriangle.TriangleType == null)
throw new ArgumentNullException(nameof(isoscelesTriangle.TriangleType), "Property is required for class IsoscelesTriangle.");
writer.WriteString("shapeType", isoscelesTriangle.ShapeType); writer.WriteString("shapeType", isoscelesTriangle.ShapeType);
writer.WriteString("triangleType", isoscelesTriangle.TriangleType); writer.WriteString("triangleType", isoscelesTriangle.TriangleType);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="var123List">var123List</param> /// <param name="var123List">var123List</param>
[JsonConstructor] [JsonConstructor]
public List(string var123List) public List(Option<string?> var123List = default)
{ {
Var123List = var123List; Var123ListOption = var123List;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Var123List
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> Var123ListOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Var123List /// Gets or Sets Var123List
/// </summary> /// </summary>
[JsonPropertyName("123-list")] [JsonPropertyName("123-list")]
public string Var123List { get; set; } public string? Var123List { get { return this. Var123ListOption; } set { this.Var123ListOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? var123List = default; Option<string?> var123List = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +129,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "123-list": case "123-list":
var123List = utf8JsonReader.GetString(); var123List = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,8 +137,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (var123List == null) if (var123List.IsSet && var123List.Value == null)
throw new ArgumentNullException(nameof(var123List), "Property is required for class List."); throw new ArgumentNullException(nameof(var123List), "Property is not nullable for class List.");
return new List(var123List); return new List(var123List);
} }
@ -160,7 +167,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, List list, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, List list, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("123-list", list.Var123List); if (list.Var123ListOption.IsSet && list.Var123List == null)
throw new ArgumentNullException(nameof(list.Var123List), "Property is required for class List.");
if (list.Var123ListOption.IsSet)
writer.WriteString("123-list", list.Var123List);
} }
} }

View File

@ -38,26 +38,40 @@ namespace UseSourceGeneration.Model
/// <param name="escapedLiteralString">escapedLiteralString (default to &quot;C:\\Users\\username&quot;)</param> /// <param name="escapedLiteralString">escapedLiteralString (default to &quot;C:\\Users\\username&quot;)</param>
/// <param name="unescapedLiteralString">unescapedLiteralString (default to &quot;C:\Users\username&quot;)</param> /// <param name="unescapedLiteralString">unescapedLiteralString (default to &quot;C:\Users\username&quot;)</param>
[JsonConstructor] [JsonConstructor]
public LiteralStringClass(string escapedLiteralString = @"C:\\Users\\username", string unescapedLiteralString = @"C:\Users\username") public LiteralStringClass(Option<string?> escapedLiteralString = default, Option<string?> unescapedLiteralString = default)
{ {
EscapedLiteralString = escapedLiteralString; EscapedLiteralStringOption = escapedLiteralString;
UnescapedLiteralString = unescapedLiteralString; UnescapedLiteralStringOption = unescapedLiteralString;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of EscapedLiteralString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> EscapedLiteralStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets EscapedLiteralString /// Gets or Sets EscapedLiteralString
/// </summary> /// </summary>
[JsonPropertyName("escapedLiteralString")] [JsonPropertyName("escapedLiteralString")]
public string EscapedLiteralString { get; set; } public string? EscapedLiteralString { get { return this. EscapedLiteralStringOption; } set { this.EscapedLiteralStringOption = new(value); } }
/// <summary>
/// Used to track the state of UnescapedLiteralString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> UnescapedLiteralStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets UnescapedLiteralString /// Gets or Sets UnescapedLiteralString
/// </summary> /// </summary>
[JsonPropertyName("unescapedLiteralString")] [JsonPropertyName("unescapedLiteralString")]
public string UnescapedLiteralString { get; set; } public string? UnescapedLiteralString { get { return this. UnescapedLiteralStringOption; } set { this.UnescapedLiteralStringOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -113,8 +127,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? escapedLiteralString = default; Option<string?> escapedLiteralString = default;
string? unescapedLiteralString = default; Option<string?> unescapedLiteralString = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -132,10 +146,10 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "escapedLiteralString": case "escapedLiteralString":
escapedLiteralString = utf8JsonReader.GetString(); escapedLiteralString = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "unescapedLiteralString": case "unescapedLiteralString":
unescapedLiteralString = utf8JsonReader.GetString(); unescapedLiteralString = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -143,11 +157,11 @@ namespace UseSourceGeneration.Model
} }
} }
if (escapedLiteralString == null) if (escapedLiteralString.IsSet && escapedLiteralString.Value == null)
throw new ArgumentNullException(nameof(escapedLiteralString), "Property is required for class LiteralStringClass."); throw new ArgumentNullException(nameof(escapedLiteralString), "Property is not nullable for class LiteralStringClass.");
if (unescapedLiteralString == null) if (unescapedLiteralString.IsSet && unescapedLiteralString.Value == null)
throw new ArgumentNullException(nameof(unescapedLiteralString), "Property is required for class LiteralStringClass."); throw new ArgumentNullException(nameof(unescapedLiteralString), "Property is not nullable for class LiteralStringClass.");
return new LiteralStringClass(escapedLiteralString, unescapedLiteralString); return new LiteralStringClass(escapedLiteralString, unescapedLiteralString);
} }
@ -176,8 +190,17 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, LiteralStringClass literalStringClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, LiteralStringClass literalStringClass, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("escapedLiteralString", literalStringClass.EscapedLiteralString); if (literalStringClass.EscapedLiteralStringOption.IsSet && literalStringClass.EscapedLiteralString == null)
writer.WriteString("unescapedLiteralString", literalStringClass.UnescapedLiteralString); throw new ArgumentNullException(nameof(literalStringClass.EscapedLiteralString), "Property is required for class LiteralStringClass.");
if (literalStringClass.UnescapedLiteralStringOption.IsSet && literalStringClass.UnescapedLiteralString == null)
throw new ArgumentNullException(nameof(literalStringClass.UnescapedLiteralString), "Property is required for class LiteralStringClass.");
if (literalStringClass.EscapedLiteralStringOption.IsSet)
writer.WriteString("escapedLiteralString", literalStringClass.EscapedLiteralString);
if (literalStringClass.UnescapedLiteralStringOption.IsSet)
writer.WriteString("unescapedLiteralString", literalStringClass.UnescapedLiteralString);
} }
} }

View File

@ -154,7 +154,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? className = default; Option<string?> className = default;
Pig? pig = null; Pig? pig = null;
Whale? whale = null; Whale? whale = null;
@ -211,7 +211,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -219,17 +219,20 @@ namespace UseSourceGeneration.Model
} }
} }
if (className == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(className), "Property is required for class Mammal."); throw new ArgumentException("Property is required for class Mammal.", nameof(className));
if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(className), "Property is not nullable for class Mammal.");
if (pig != null) if (pig != null)
return new Mammal(pig, className); return new Mammal(pig, className.Value!);
if (whale != null) if (whale != null)
return new Mammal(whale, className); return new Mammal(whale, className.Value!);
if (zebra != null) if (zebra != null)
return new Mammal(zebra, className); return new Mammal(zebra, className.Value!);
throw new JsonException(); throw new JsonException();
} }
@ -273,6 +276,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Mammal mammal, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Mammal mammal, JsonSerializerOptions jsonSerializerOptions)
{ {
if (mammal.ClassName == null)
throw new ArgumentNullException(nameof(mammal.ClassName), "Property is required for class Mammal.");
writer.WriteString("className", mammal.ClassName); writer.WriteString("className", mammal.ClassName);
} }
} }

View File

@ -40,12 +40,12 @@ namespace UseSourceGeneration.Model
/// <param name="mapMapOfString">mapMapOfString</param> /// <param name="mapMapOfString">mapMapOfString</param>
/// <param name="mapOfEnumString">mapOfEnumString</param> /// <param name="mapOfEnumString">mapOfEnumString</param>
[JsonConstructor] [JsonConstructor]
public MapTest(Dictionary<string, bool> directMap, Dictionary<string, bool> indirectMap, Dictionary<string, Dictionary<string, string>> mapMapOfString, Dictionary<string, MapTest.InnerEnum> mapOfEnumString) public MapTest(Option<Dictionary<string, bool>?> directMap = default, Option<Dictionary<string, bool>?> indirectMap = default, Option<Dictionary<string, Dictionary<string, string>>?> mapMapOfString = default, Option<Dictionary<string, MapTest.InnerEnum>?> mapOfEnumString = default)
{ {
DirectMap = directMap; DirectMapOption = directMap;
IndirectMap = indirectMap; IndirectMapOption = indirectMap;
MapMapOfString = mapMapOfString; MapMapOfStringOption = mapMapOfString;
MapOfEnumString = mapOfEnumString; MapOfEnumStringOption = mapOfEnumString;
OnCreated(); OnCreated();
} }
@ -106,9 +106,8 @@ namespace UseSourceGeneration.Model
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public static string InnerEnumToJsonValue(InnerEnum value) public static string InnerEnumToJsonValue(InnerEnum? value)
{ {
if (value == InnerEnum.UPPER) if (value == InnerEnum.UPPER)
return "UPPER"; return "UPPER";
@ -118,29 +117,57 @@ namespace UseSourceGeneration.Model
throw new NotImplementedException($"Value could not be handled: '{value}'"); throw new NotImplementedException($"Value could not be handled: '{value}'");
} }
/// <summary>
/// Used to track the state of DirectMap
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, bool>?> DirectMapOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets DirectMap /// Gets or Sets DirectMap
/// </summary> /// </summary>
[JsonPropertyName("direct_map")] [JsonPropertyName("direct_map")]
public Dictionary<string, bool> DirectMap { get; set; } public Dictionary<string, bool>? DirectMap { get { return this. DirectMapOption; } set { this.DirectMapOption = new(value); } }
/// <summary>
/// Used to track the state of IndirectMap
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, bool>?> IndirectMapOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets IndirectMap /// Gets or Sets IndirectMap
/// </summary> /// </summary>
[JsonPropertyName("indirect_map")] [JsonPropertyName("indirect_map")]
public Dictionary<string, bool> IndirectMap { get; set; } public Dictionary<string, bool>? IndirectMap { get { return this. IndirectMapOption; } set { this.IndirectMapOption = new(value); } }
/// <summary>
/// Used to track the state of MapMapOfString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Dictionary<string, string>>?> MapMapOfStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets MapMapOfString /// Gets or Sets MapMapOfString
/// </summary> /// </summary>
[JsonPropertyName("map_map_of_string")] [JsonPropertyName("map_map_of_string")]
public Dictionary<string, Dictionary<string, string>> MapMapOfString { get; set; } public Dictionary<string, Dictionary<string, string>>? MapMapOfString { get { return this. MapMapOfStringOption; } set { this.MapMapOfStringOption = new(value); } }
/// <summary>
/// Used to track the state of MapOfEnumString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, MapTest.InnerEnum>?> MapOfEnumStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets MapOfEnumString /// Gets or Sets MapOfEnumString
/// </summary> /// </summary>
[JsonPropertyName("map_of_enum_string")] [JsonPropertyName("map_of_enum_string")]
public Dictionary<string, MapTest.InnerEnum> MapOfEnumString { get; set; } public Dictionary<string, MapTest.InnerEnum>? MapOfEnumString { get { return this. MapOfEnumStringOption; } set { this.MapOfEnumStringOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -198,10 +225,10 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Dictionary<string, bool>? directMap = default; Option<Dictionary<string, bool>?> directMap = default;
Dictionary<string, bool>? indirectMap = default; Option<Dictionary<string, bool>?> indirectMap = default;
Dictionary<string, Dictionary<string, string>>? mapMapOfString = default; Option<Dictionary<string, Dictionary<string, string>>?> mapMapOfString = default;
Dictionary<string, MapTest.InnerEnum>? mapOfEnumString = default; Option<Dictionary<string, MapTest.InnerEnum>?> mapOfEnumString = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -220,19 +247,19 @@ namespace UseSourceGeneration.Model
{ {
case "direct_map": case "direct_map":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
directMap = JsonSerializer.Deserialize<Dictionary<string, bool>>(ref utf8JsonReader, jsonSerializerOptions); directMap = new Option<Dictionary<string, bool>?>(JsonSerializer.Deserialize<Dictionary<string, bool>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "indirect_map": case "indirect_map":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
indirectMap = JsonSerializer.Deserialize<Dictionary<string, bool>>(ref utf8JsonReader, jsonSerializerOptions); indirectMap = new Option<Dictionary<string, bool>?>(JsonSerializer.Deserialize<Dictionary<string, bool>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_map_of_string": case "map_map_of_string":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapMapOfString = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(ref utf8JsonReader, jsonSerializerOptions); mapMapOfString = new Option<Dictionary<string, Dictionary<string, string>>?>(JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "map_of_enum_string": case "map_of_enum_string":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
mapOfEnumString = JsonSerializer.Deserialize<Dictionary<string, MapTest.InnerEnum>>(ref utf8JsonReader, jsonSerializerOptions); mapOfEnumString = new Option<Dictionary<string, MapTest.InnerEnum>?>(JsonSerializer.Deserialize<Dictionary<string, MapTest.InnerEnum>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -240,17 +267,17 @@ namespace UseSourceGeneration.Model
} }
} }
if (directMap == null) if (directMap.IsSet && directMap.Value == null)
throw new ArgumentNullException(nameof(directMap), "Property is required for class MapTest."); throw new ArgumentNullException(nameof(directMap), "Property is not nullable for class MapTest.");
if (indirectMap == null) if (indirectMap.IsSet && indirectMap.Value == null)
throw new ArgumentNullException(nameof(indirectMap), "Property is required for class MapTest."); throw new ArgumentNullException(nameof(indirectMap), "Property is not nullable for class MapTest.");
if (mapMapOfString == null) if (mapMapOfString.IsSet && mapMapOfString.Value == null)
throw new ArgumentNullException(nameof(mapMapOfString), "Property is required for class MapTest."); throw new ArgumentNullException(nameof(mapMapOfString), "Property is not nullable for class MapTest.");
if (mapOfEnumString == null) if (mapOfEnumString.IsSet && mapOfEnumString.Value == null)
throw new ArgumentNullException(nameof(mapOfEnumString), "Property is required for class MapTest."); throw new ArgumentNullException(nameof(mapOfEnumString), "Property is not nullable for class MapTest.");
return new MapTest(directMap, indirectMap, mapMapOfString, mapOfEnumString); return new MapTest(directMap, indirectMap, mapMapOfString, mapOfEnumString);
} }
@ -279,14 +306,38 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, MapTest mapTest, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, MapTest mapTest, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("direct_map"); if (mapTest.DirectMapOption.IsSet && mapTest.DirectMap == null)
JsonSerializer.Serialize(writer, mapTest.DirectMap, jsonSerializerOptions); throw new ArgumentNullException(nameof(mapTest.DirectMap), "Property is required for class MapTest.");
writer.WritePropertyName("indirect_map");
JsonSerializer.Serialize(writer, mapTest.IndirectMap, jsonSerializerOptions); if (mapTest.IndirectMapOption.IsSet && mapTest.IndirectMap == null)
writer.WritePropertyName("map_map_of_string"); throw new ArgumentNullException(nameof(mapTest.IndirectMap), "Property is required for class MapTest.");
JsonSerializer.Serialize(writer, mapTest.MapMapOfString, jsonSerializerOptions);
writer.WritePropertyName("map_of_enum_string"); if (mapTest.MapMapOfStringOption.IsSet && mapTest.MapMapOfString == null)
JsonSerializer.Serialize(writer, mapTest.MapOfEnumString, jsonSerializerOptions); throw new ArgumentNullException(nameof(mapTest.MapMapOfString), "Property is required for class MapTest.");
if (mapTest.MapOfEnumStringOption.IsSet && mapTest.MapOfEnumString == null)
throw new ArgumentNullException(nameof(mapTest.MapOfEnumString), "Property is required for class MapTest.");
if (mapTest.DirectMapOption.IsSet)
{
writer.WritePropertyName("direct_map");
JsonSerializer.Serialize(writer, mapTest.DirectMap, jsonSerializerOptions);
}
if (mapTest.IndirectMapOption.IsSet)
{
writer.WritePropertyName("indirect_map");
JsonSerializer.Serialize(writer, mapTest.IndirectMap, jsonSerializerOptions);
}
if (mapTest.MapMapOfStringOption.IsSet)
{
writer.WritePropertyName("map_map_of_string");
JsonSerializer.Serialize(writer, mapTest.MapMapOfString, jsonSerializerOptions);
}
if (mapTest.MapOfEnumStringOption.IsSet)
{
writer.WritePropertyName("map_of_enum_string");
JsonSerializer.Serialize(writer, mapTest.MapOfEnumString, jsonSerializerOptions);
}
} }
} }

View File

@ -40,40 +40,68 @@ namespace UseSourceGeneration.Model
/// <param name="uuid">uuid</param> /// <param name="uuid">uuid</param>
/// <param name="uuidWithPattern">uuidWithPattern</param> /// <param name="uuidWithPattern">uuidWithPattern</param>
[JsonConstructor] [JsonConstructor]
public MixedPropertiesAndAdditionalPropertiesClass(DateTime dateTime, Dictionary<string, Animal> map, Guid uuid, Guid uuidWithPattern) public MixedPropertiesAndAdditionalPropertiesClass(Option<DateTime?> dateTime = default, Option<Dictionary<string, Animal>?> map = default, Option<Guid?> uuid = default, Option<Guid?> uuidWithPattern = default)
{ {
DateTime = dateTime; DateTimeOption = dateTime;
Map = map; MapOption = map;
Uuid = uuid; UuidOption = uuid;
UuidWithPattern = uuidWithPattern; UuidWithPatternOption = uuidWithPattern;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of DateTime
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DateTime?> DateTimeOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets DateTime /// Gets or Sets DateTime
/// </summary> /// </summary>
[JsonPropertyName("dateTime")] [JsonPropertyName("dateTime")]
public DateTime DateTime { get; set; } public DateTime? DateTime { get { return this. DateTimeOption; } set { this.DateTimeOption = new(value); } }
/// <summary>
/// Used to track the state of Map
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Animal>?> MapOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Map /// Gets or Sets Map
/// </summary> /// </summary>
[JsonPropertyName("map")] [JsonPropertyName("map")]
public Dictionary<string, Animal> Map { get; set; } public Dictionary<string, Animal>? Map { get { return this. MapOption; } set { this.MapOption = new(value); } }
/// <summary>
/// Used to track the state of Uuid
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Guid?> UuidOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Uuid /// Gets or Sets Uuid
/// </summary> /// </summary>
[JsonPropertyName("uuid")] [JsonPropertyName("uuid")]
public Guid Uuid { get; set; } public Guid? Uuid { get { return this. UuidOption; } set { this.UuidOption = new(value); } }
/// <summary>
/// Used to track the state of UuidWithPattern
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Guid?> UuidWithPatternOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets UuidWithPattern /// Gets or Sets UuidWithPattern
/// </summary> /// </summary>
[JsonPropertyName("uuid_with_pattern")] [JsonPropertyName("uuid_with_pattern")]
public Guid UuidWithPattern { get; set; } public Guid? UuidWithPattern { get { return this. UuidWithPatternOption; } set { this.UuidWithPatternOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -107,7 +135,8 @@ namespace UseSourceGeneration.Model
{ {
// UuidWithPattern (Guid) pattern // UuidWithPattern (Guid) pattern
Regex regexUuidWithPattern = new Regex(@"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant); Regex regexUuidWithPattern = new Regex(@"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
if (!regexUuidWithPattern.Match(this.UuidWithPattern.ToString()).Success)
if (this.UuidWithPatternOption.Value != null &&!regexUuidWithPattern.Match(this.UuidWithPatternOption.Value.ToString()!).Success)
{ {
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UuidWithPattern, must match a pattern of " + regexUuidWithPattern, new [] { "UuidWithPattern" }); yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UuidWithPattern, must match a pattern of " + regexUuidWithPattern, new [] { "UuidWithPattern" });
} }
@ -142,10 +171,10 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
DateTime? dateTime = default; Option<DateTime?> dateTime = default;
Dictionary<string, Animal>? map = default; Option<Dictionary<string, Animal>?> map = default;
Guid? uuid = default; Option<Guid?> uuid = default;
Guid? uuidWithPattern = default; Option<Guid?> uuidWithPattern = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -164,19 +193,19 @@ namespace UseSourceGeneration.Model
{ {
case "dateTime": case "dateTime":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateTime = JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions); dateTime = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "map": case "map":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
map = JsonSerializer.Deserialize<Dictionary<string, Animal>>(ref utf8JsonReader, jsonSerializerOptions); map = new Option<Dictionary<string, Animal>?>(JsonSerializer.Deserialize<Dictionary<string, Animal>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "uuid": case "uuid":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
uuid = utf8JsonReader.GetGuid(); uuid = new Option<Guid?>(utf8JsonReader.GetGuid());
break; break;
case "uuid_with_pattern": case "uuid_with_pattern":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
uuidWithPattern = utf8JsonReader.GetGuid(); uuidWithPattern = new Option<Guid?>(utf8JsonReader.GetGuid());
break; break;
default: default:
break; break;
@ -184,19 +213,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (dateTime == null) if (dateTime.IsSet && dateTime.Value == null)
throw new ArgumentNullException(nameof(dateTime), "Property is required for class MixedPropertiesAndAdditionalPropertiesClass."); throw new ArgumentNullException(nameof(dateTime), "Property is not nullable for class MixedPropertiesAndAdditionalPropertiesClass.");
if (map == null) if (map.IsSet && map.Value == null)
throw new ArgumentNullException(nameof(map), "Property is required for class MixedPropertiesAndAdditionalPropertiesClass."); throw new ArgumentNullException(nameof(map), "Property is not nullable for class MixedPropertiesAndAdditionalPropertiesClass.");
if (uuid == null) if (uuid.IsSet && uuid.Value == null)
throw new ArgumentNullException(nameof(uuid), "Property is required for class MixedPropertiesAndAdditionalPropertiesClass."); throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class MixedPropertiesAndAdditionalPropertiesClass.");
if (uuidWithPattern == null) if (uuidWithPattern.IsSet && uuidWithPattern.Value == null)
throw new ArgumentNullException(nameof(uuidWithPattern), "Property is required for class MixedPropertiesAndAdditionalPropertiesClass."); throw new ArgumentNullException(nameof(uuidWithPattern), "Property is not nullable for class MixedPropertiesAndAdditionalPropertiesClass.");
return new MixedPropertiesAndAdditionalPropertiesClass(dateTime.Value, map, uuid.Value, uuidWithPattern.Value); return new MixedPropertiesAndAdditionalPropertiesClass(dateTime, map, uuid, uuidWithPattern);
} }
/// <summary> /// <summary>
@ -223,11 +252,22 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, MixedPropertiesAndAdditionalPropertiesClass mixedPropertiesAndAdditionalPropertiesClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, MixedPropertiesAndAdditionalPropertiesClass mixedPropertiesAndAdditionalPropertiesClass, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("dateTime", mixedPropertiesAndAdditionalPropertiesClass.DateTime.ToString(DateTimeFormat)); if (mixedPropertiesAndAdditionalPropertiesClass.MapOption.IsSet && mixedPropertiesAndAdditionalPropertiesClass.Map == null)
writer.WritePropertyName("map"); throw new ArgumentNullException(nameof(mixedPropertiesAndAdditionalPropertiesClass.Map), "Property is required for class MixedPropertiesAndAdditionalPropertiesClass.");
JsonSerializer.Serialize(writer, mixedPropertiesAndAdditionalPropertiesClass.Map, jsonSerializerOptions);
writer.WriteString("uuid", mixedPropertiesAndAdditionalPropertiesClass.Uuid); if (mixedPropertiesAndAdditionalPropertiesClass.DateTimeOption.IsSet)
writer.WriteString("uuid_with_pattern", mixedPropertiesAndAdditionalPropertiesClass.UuidWithPattern); writer.WriteString("dateTime", mixedPropertiesAndAdditionalPropertiesClass.DateTimeOption.Value!.Value.ToString(DateTimeFormat));
if (mixedPropertiesAndAdditionalPropertiesClass.MapOption.IsSet)
{
writer.WritePropertyName("map");
JsonSerializer.Serialize(writer, mixedPropertiesAndAdditionalPropertiesClass.Map, jsonSerializerOptions);
}
if (mixedPropertiesAndAdditionalPropertiesClass.UuidOption.IsSet)
writer.WriteString("uuid", mixedPropertiesAndAdditionalPropertiesClass.UuidOption.Value!.Value);
if (mixedPropertiesAndAdditionalPropertiesClass.UuidWithPatternOption.IsSet)
writer.WriteString("uuid_with_pattern", mixedPropertiesAndAdditionalPropertiesClass.UuidWithPatternOption.Value!.Value);
} }
} }

View File

@ -38,26 +38,40 @@ namespace UseSourceGeneration.Model
/// <param name="varClass">varClass</param> /// <param name="varClass">varClass</param>
/// <param name="name">name</param> /// <param name="name">name</param>
[JsonConstructor] [JsonConstructor]
public Model200Response(string varClass, int name) public Model200Response(Option<string?> varClass = default, Option<int?> name = default)
{ {
VarClass = varClass; VarClassOption = varClass;
Name = name; NameOption = name;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of VarClass
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> VarClassOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets VarClass /// Gets or Sets VarClass
/// </summary> /// </summary>
[JsonPropertyName("class")] [JsonPropertyName("class")]
public string VarClass { get; set; } public string? VarClass { get { return this. VarClassOption; } set { this.VarClassOption = new(value); } }
/// <summary>
/// Used to track the state of Name
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> NameOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Name /// Gets or Sets Name
/// </summary> /// </summary>
[JsonPropertyName("name")] [JsonPropertyName("name")]
public int Name { get; set; } public int? Name { get { return this. NameOption; } set { this.NameOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -113,8 +127,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? varClass = default; Option<string?> varClass = default;
int? name = default; Option<int?> name = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -132,11 +146,11 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "class": case "class":
varClass = utf8JsonReader.GetString(); varClass = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "name": case "name":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
name = utf8JsonReader.GetInt32(); name = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
default: default:
break; break;
@ -144,13 +158,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (varClass == null) if (varClass.IsSet && varClass.Value == null)
throw new ArgumentNullException(nameof(varClass), "Property is required for class Model200Response."); throw new ArgumentNullException(nameof(varClass), "Property is not nullable for class Model200Response.");
if (name == null) if (name.IsSet && name.Value == null)
throw new ArgumentNullException(nameof(name), "Property is required for class Model200Response."); throw new ArgumentNullException(nameof(name), "Property is not nullable for class Model200Response.");
return new Model200Response(varClass, name.Value); return new Model200Response(varClass, name);
} }
/// <summary> /// <summary>
@ -177,8 +191,14 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Model200Response model200Response, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Model200Response model200Response, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("class", model200Response.VarClass); if (model200Response.VarClassOption.IsSet && model200Response.VarClass == null)
writer.WriteNumber("name", model200Response.Name); throw new ArgumentNullException(nameof(model200Response.VarClass), "Property is required for class Model200Response.");
if (model200Response.VarClassOption.IsSet)
writer.WriteString("class", model200Response.VarClass);
if (model200Response.NameOption.IsSet)
writer.WriteNumber("name", model200Response.NameOption.Value!.Value);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="varClient">varClient</param> /// <param name="varClient">varClient</param>
[JsonConstructor] [JsonConstructor]
public ModelClient(string varClient) public ModelClient(Option<string?> varClient = default)
{ {
VarClient = varClient; VarClientOption = varClient;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of VarClient
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> VarClientOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets VarClient /// Gets or Sets VarClient
/// </summary> /// </summary>
[JsonPropertyName("client")] [JsonPropertyName("client")]
public string VarClient { get; set; } public string? VarClient { get { return this. VarClientOption; } set { this.VarClientOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? varClient = default; Option<string?> varClient = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +129,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "client": case "client":
varClient = utf8JsonReader.GetString(); varClient = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,8 +137,8 @@ namespace UseSourceGeneration.Model
} }
} }
if (varClient == null) if (varClient.IsSet && varClient.Value == null)
throw new ArgumentNullException(nameof(varClient), "Property is required for class ModelClient."); throw new ArgumentNullException(nameof(varClient), "Property is not nullable for class ModelClient.");
return new ModelClient(varClient); return new ModelClient(varClient);
} }
@ -160,7 +167,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ModelClient modelClient, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ModelClient modelClient, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteString("client", modelClient.VarClient); if (modelClient.VarClientOption.IsSet && modelClient.VarClient == null)
throw new ArgumentNullException(nameof(modelClient.VarClient), "Property is required for class ModelClient.");
if (modelClient.VarClientOption.IsSet)
writer.WriteString("client", modelClient.VarClient);
} }
} }

View File

@ -40,12 +40,12 @@ namespace UseSourceGeneration.Model
/// <param name="snakeCase">snakeCase</param> /// <param name="snakeCase">snakeCase</param>
/// <param name="var123Number">var123Number</param> /// <param name="var123Number">var123Number</param>
[JsonConstructor] [JsonConstructor]
public Name(int varName, string property, int snakeCase, int var123Number) public Name(int varName, Option<string?> property = default, Option<int?> snakeCase = default, Option<int?> var123Number = default)
{ {
VarName = varName; VarName = varName;
Property = property; PropertyOption = property;
SnakeCase = snakeCase; SnakeCaseOption = snakeCase;
Var123Number = var123Number; Var123NumberOption = var123Number;
OnCreated(); OnCreated();
} }
@ -57,23 +57,44 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("name")] [JsonPropertyName("name")]
public int VarName { get; set; } public int VarName { get; set; }
/// <summary>
/// Used to track the state of Property
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> PropertyOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Property /// Gets or Sets Property
/// </summary> /// </summary>
[JsonPropertyName("property")] [JsonPropertyName("property")]
public string Property { get; set; } public string? Property { get { return this. PropertyOption; } set { this.PropertyOption = new(value); } }
/// <summary>
/// Used to track the state of SnakeCase
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> SnakeCaseOption { get; }
/// <summary> /// <summary>
/// Gets or Sets SnakeCase /// Gets or Sets SnakeCase
/// </summary> /// </summary>
[JsonPropertyName("snake_case")] [JsonPropertyName("snake_case")]
public int SnakeCase { get; } public int? SnakeCase { get { return this. SnakeCaseOption; } }
/// <summary>
/// Used to track the state of Var123Number
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> Var123NumberOption { get; }
/// <summary> /// <summary>
/// Gets or Sets Var123Number /// Gets or Sets Var123Number
/// </summary> /// </summary>
[JsonPropertyName("123Number")] [JsonPropertyName("123Number")]
public int Var123Number { get; } public int? Var123Number { get { return this. Var123NumberOption; } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -127,8 +148,12 @@ namespace UseSourceGeneration.Model
unchecked // Overflow is fine, just wrap unchecked // Overflow is fine, just wrap
{ {
int hashCode = 41; int hashCode = 41;
hashCode = (hashCode * 59) + SnakeCase.GetHashCode(); if (SnakeCase != null)
hashCode = (hashCode * 59) + Var123Number.GetHashCode(); hashCode = (hashCode * 59) + SnakeCase.GetHashCode();
if (Var123Number != null)
hashCode = (hashCode * 59) + Var123Number.GetHashCode();
hashCode = (hashCode * 59) + AdditionalProperties.GetHashCode(); hashCode = (hashCode * 59) + AdditionalProperties.GetHashCode();
return hashCode; return hashCode;
@ -168,10 +193,10 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
int? varName = default; Option<int?> varName = default;
string? property = default; Option<string?> property = default;
int? snakeCase = default; Option<int?> snakeCase = default;
int? var123Number = default; Option<int?> var123Number = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -190,18 +215,18 @@ namespace UseSourceGeneration.Model
{ {
case "name": case "name":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
varName = utf8JsonReader.GetInt32(); varName = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
case "property": case "property":
property = utf8JsonReader.GetString(); property = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "snake_case": case "snake_case":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
snakeCase = utf8JsonReader.GetInt32(); snakeCase = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
case "123Number": case "123Number":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
var123Number = utf8JsonReader.GetInt32(); var123Number = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
default: default:
break; break;
@ -209,19 +234,22 @@ namespace UseSourceGeneration.Model
} }
} }
if (varName == null) if (!varName.IsSet)
throw new ArgumentNullException(nameof(varName), "Property is required for class Name."); throw new ArgumentException("Property is required for class Name.", nameof(varName));
if (property == null) if (varName.IsSet && varName.Value == null)
throw new ArgumentNullException(nameof(property), "Property is required for class Name."); throw new ArgumentNullException(nameof(varName), "Property is not nullable for class Name.");
if (snakeCase == null) if (property.IsSet && property.Value == null)
throw new ArgumentNullException(nameof(snakeCase), "Property is required for class Name."); throw new ArgumentNullException(nameof(property), "Property is not nullable for class Name.");
if (var123Number == null) if (snakeCase.IsSet && snakeCase.Value == null)
throw new ArgumentNullException(nameof(var123Number), "Property is required for class Name."); throw new ArgumentNullException(nameof(snakeCase), "Property is not nullable for class Name.");
return new Name(varName.Value, property, snakeCase.Value, var123Number.Value); if (var123Number.IsSet && var123Number.Value == null)
throw new ArgumentNullException(nameof(var123Number), "Property is not nullable for class Name.");
return new Name(varName.Value!.Value!, property, snakeCase, var123Number);
} }
/// <summary> /// <summary>
@ -248,10 +276,19 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Name name, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Name name, JsonSerializerOptions jsonSerializerOptions)
{ {
if (name.PropertyOption.IsSet && name.Property == null)
throw new ArgumentNullException(nameof(name.Property), "Property is required for class Name.");
writer.WriteNumber("name", name.VarName); writer.WriteNumber("name", name.VarName);
writer.WriteString("property", name.Property);
writer.WriteNumber("snake_case", name.SnakeCase); if (name.PropertyOption.IsSet)
writer.WriteNumber("123Number", name.Var123Number); writer.WriteString("property", name.Property);
if (name.SnakeCaseOption.IsSet)
writer.WriteNumber("snake_case", name.SnakeCaseOption.Value!.Value);
if (name.Var123NumberOption.IsSet)
writer.WriteNumber("123Number", name.Var123NumberOption.Value!.Value);
} }
} }

View File

@ -113,8 +113,8 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<Dictionary<string, Object>>? aObjVariableobject = default; Option<List<Dictionary<string, Object>>?> aObjVariableobject = default;
int? pkiNotificationtestID = default; Option<int?> pkiNotificationtestID = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -133,11 +133,11 @@ namespace UseSourceGeneration.Model
{ {
case "a_objVariableobject": case "a_objVariableobject":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
aObjVariableobject = JsonSerializer.Deserialize<List<Dictionary<string, Object>>>(ref utf8JsonReader, jsonSerializerOptions); aObjVariableobject = new Option<List<Dictionary<string, Object>>?>(JsonSerializer.Deserialize<List<Dictionary<string, Object>>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "pkiNotificationtestID": case "pkiNotificationtestID":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
pkiNotificationtestID = utf8JsonReader.GetInt32(); pkiNotificationtestID = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
default: default:
break; break;
@ -145,13 +145,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (aObjVariableobject == null) if (!aObjVariableobject.IsSet)
throw new ArgumentNullException(nameof(aObjVariableobject), "Property is required for class NotificationtestGetElementsV1ResponseMPayload."); throw new ArgumentException("Property is required for class NotificationtestGetElementsV1ResponseMPayload.", nameof(aObjVariableobject));
if (pkiNotificationtestID == null) if (!pkiNotificationtestID.IsSet)
throw new ArgumentNullException(nameof(pkiNotificationtestID), "Property is required for class NotificationtestGetElementsV1ResponseMPayload."); throw new ArgumentException("Property is required for class NotificationtestGetElementsV1ResponseMPayload.", nameof(pkiNotificationtestID));
return new NotificationtestGetElementsV1ResponseMPayload(aObjVariableobject, pkiNotificationtestID.Value); if (aObjVariableobject.IsSet && aObjVariableobject.Value == null)
throw new ArgumentNullException(nameof(aObjVariableobject), "Property is not nullable for class NotificationtestGetElementsV1ResponseMPayload.");
if (pkiNotificationtestID.IsSet && pkiNotificationtestID.Value == null)
throw new ArgumentNullException(nameof(pkiNotificationtestID), "Property is not nullable for class NotificationtestGetElementsV1ResponseMPayload.");
return new NotificationtestGetElementsV1ResponseMPayload(aObjVariableobject.Value!, pkiNotificationtestID.Value!.Value!);
} }
/// <summary> /// <summary>
@ -178,6 +184,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, NotificationtestGetElementsV1ResponseMPayload notificationtestGetElementsV1ResponseMPayload, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, NotificationtestGetElementsV1ResponseMPayload notificationtestGetElementsV1ResponseMPayload, JsonSerializerOptions jsonSerializerOptions)
{ {
if (notificationtestGetElementsV1ResponseMPayload.AObjVariableobject == null)
throw new ArgumentNullException(nameof(notificationtestGetElementsV1ResponseMPayload.AObjVariableobject), "Property is required for class NotificationtestGetElementsV1ResponseMPayload.");
writer.WritePropertyName("a_objVariableobject"); writer.WritePropertyName("a_objVariableobject");
JsonSerializer.Serialize(writer, notificationtestGetElementsV1ResponseMPayload.AObjVariableobject, jsonSerializerOptions); JsonSerializer.Serialize(writer, notificationtestGetElementsV1ResponseMPayload.AObjVariableobject, jsonSerializerOptions);
writer.WriteNumber("pkiNotificationtestID", notificationtestGetElementsV1ResponseMPayload.PkiNotificationtestID); writer.WriteNumber("pkiNotificationtestID", notificationtestGetElementsV1ResponseMPayload.PkiNotificationtestID);

View File

@ -35,9 +35,8 @@ namespace UseSourceGeneration.Model
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="NullableClass" /> class. /// Initializes a new instance of the <see cref="NullableClass" /> class.
/// </summary> /// </summary>
/// <param name="arrayItemsNullable">arrayItemsNullable</param>
/// <param name="objectItemsNullable">objectItemsNullable</param>
/// <param name="arrayAndItemsNullableProp">arrayAndItemsNullableProp</param> /// <param name="arrayAndItemsNullableProp">arrayAndItemsNullableProp</param>
/// <param name="arrayItemsNullable">arrayItemsNullable</param>
/// <param name="arrayNullableProp">arrayNullableProp</param> /// <param name="arrayNullableProp">arrayNullableProp</param>
/// <param name="booleanProp">booleanProp</param> /// <param name="booleanProp">booleanProp</param>
/// <param name="dateProp">dateProp</param> /// <param name="dateProp">dateProp</param>
@ -45,99 +44,184 @@ namespace UseSourceGeneration.Model
/// <param name="integerProp">integerProp</param> /// <param name="integerProp">integerProp</param>
/// <param name="numberProp">numberProp</param> /// <param name="numberProp">numberProp</param>
/// <param name="objectAndItemsNullableProp">objectAndItemsNullableProp</param> /// <param name="objectAndItemsNullableProp">objectAndItemsNullableProp</param>
/// <param name="objectItemsNullable">objectItemsNullable</param>
/// <param name="objectNullableProp">objectNullableProp</param> /// <param name="objectNullableProp">objectNullableProp</param>
/// <param name="stringProp">stringProp</param> /// <param name="stringProp">stringProp</param>
[JsonConstructor] [JsonConstructor]
public NullableClass(List<Object> arrayItemsNullable, Dictionary<string, Object> objectItemsNullable, List<Object>? arrayAndItemsNullableProp = default, List<Object>? arrayNullableProp = default, bool? booleanProp = default, DateTime? dateProp = default, DateTime? datetimeProp = default, int? integerProp = default, decimal? numberProp = default, Dictionary<string, Object>? objectAndItemsNullableProp = default, Dictionary<string, Object>? objectNullableProp = default, string? stringProp = default) : base() public NullableClass(Option<List<Object>?> arrayAndItemsNullableProp = default, Option<List<Object>?> arrayItemsNullable = default, Option<List<Object>?> arrayNullableProp = default, Option<bool?> booleanProp = default, Option<DateTime?> dateProp = default, Option<DateTime?> datetimeProp = default, Option<int?> integerProp = default, Option<decimal?> numberProp = default, Option<Dictionary<string, Object>?> objectAndItemsNullableProp = default, Option<Dictionary<string, Object>?> objectItemsNullable = default, Option<Dictionary<string, Object>?> objectNullableProp = default, Option<string?> stringProp = default) : base()
{ {
ArrayItemsNullable = arrayItemsNullable; ArrayAndItemsNullablePropOption = arrayAndItemsNullableProp;
ObjectItemsNullable = objectItemsNullable; ArrayItemsNullableOption = arrayItemsNullable;
ArrayAndItemsNullableProp = arrayAndItemsNullableProp; ArrayNullablePropOption = arrayNullableProp;
ArrayNullableProp = arrayNullableProp; BooleanPropOption = booleanProp;
BooleanProp = booleanProp; DatePropOption = dateProp;
DateProp = dateProp; DatetimePropOption = datetimeProp;
DatetimeProp = datetimeProp; IntegerPropOption = integerProp;
IntegerProp = integerProp; NumberPropOption = numberProp;
NumberProp = numberProp; ObjectAndItemsNullablePropOption = objectAndItemsNullableProp;
ObjectAndItemsNullableProp = objectAndItemsNullableProp; ObjectItemsNullableOption = objectItemsNullable;
ObjectNullableProp = objectNullableProp; ObjectNullablePropOption = objectNullableProp;
StringProp = stringProp; StringPropOption = stringProp;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary> /// <summary>
/// Gets or Sets ArrayItemsNullable /// Used to track the state of ArrayAndItemsNullableProp
/// </summary> /// </summary>
[JsonPropertyName("array_items_nullable")] [JsonIgnore]
public List<Object> ArrayItemsNullable { get; set; } [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<Object>?> ArrayAndItemsNullablePropOption { get; private set; }
/// <summary>
/// Gets or Sets ObjectItemsNullable
/// </summary>
[JsonPropertyName("object_items_nullable")]
public Dictionary<string, Object> ObjectItemsNullable { get; set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayAndItemsNullableProp /// Gets or Sets ArrayAndItemsNullableProp
/// </summary> /// </summary>
[JsonPropertyName("array_and_items_nullable_prop")] [JsonPropertyName("array_and_items_nullable_prop")]
public List<Object>? ArrayAndItemsNullableProp { get; set; } public List<Object>? ArrayAndItemsNullableProp { get { return this. ArrayAndItemsNullablePropOption; } set { this.ArrayAndItemsNullablePropOption = new(value); } }
/// <summary>
/// Used to track the state of ArrayItemsNullable
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<Object>?> ArrayItemsNullableOption { get; private set; }
/// <summary>
/// Gets or Sets ArrayItemsNullable
/// </summary>
[JsonPropertyName("array_items_nullable")]
public List<Object>? ArrayItemsNullable { get { return this. ArrayItemsNullableOption; } set { this.ArrayItemsNullableOption = new(value); } }
/// <summary>
/// Used to track the state of ArrayNullableProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<Object>?> ArrayNullablePropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ArrayNullableProp /// Gets or Sets ArrayNullableProp
/// </summary> /// </summary>
[JsonPropertyName("array_nullable_prop")] [JsonPropertyName("array_nullable_prop")]
public List<Object>? ArrayNullableProp { get; set; } public List<Object>? ArrayNullableProp { get { return this. ArrayNullablePropOption; } set { this.ArrayNullablePropOption = new(value); } }
/// <summary>
/// Used to track the state of BooleanProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<bool?> BooleanPropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets BooleanProp /// Gets or Sets BooleanProp
/// </summary> /// </summary>
[JsonPropertyName("boolean_prop")] [JsonPropertyName("boolean_prop")]
public bool? BooleanProp { get; set; } public bool? BooleanProp { get { return this. BooleanPropOption; } set { this.BooleanPropOption = new(value); } }
/// <summary>
/// Used to track the state of DateProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DateTime?> DatePropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets DateProp /// Gets or Sets DateProp
/// </summary> /// </summary>
[JsonPropertyName("date_prop")] [JsonPropertyName("date_prop")]
public DateTime? DateProp { get; set; } public DateTime? DateProp { get { return this. DatePropOption; } set { this.DatePropOption = new(value); } }
/// <summary>
/// Used to track the state of DatetimeProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DateTime?> DatetimePropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets DatetimeProp /// Gets or Sets DatetimeProp
/// </summary> /// </summary>
[JsonPropertyName("datetime_prop")] [JsonPropertyName("datetime_prop")]
public DateTime? DatetimeProp { get; set; } public DateTime? DatetimeProp { get { return this. DatetimePropOption; } set { this.DatetimePropOption = new(value); } }
/// <summary>
/// Used to track the state of IntegerProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> IntegerPropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets IntegerProp /// Gets or Sets IntegerProp
/// </summary> /// </summary>
[JsonPropertyName("integer_prop")] [JsonPropertyName("integer_prop")]
public int? IntegerProp { get; set; } public int? IntegerProp { get { return this. IntegerPropOption; } set { this.IntegerPropOption = new(value); } }
/// <summary>
/// Used to track the state of NumberProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<decimal?> NumberPropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets NumberProp /// Gets or Sets NumberProp
/// </summary> /// </summary>
[JsonPropertyName("number_prop")] [JsonPropertyName("number_prop")]
public decimal? NumberProp { get; set; } public decimal? NumberProp { get { return this. NumberPropOption; } set { this.NumberPropOption = new(value); } }
/// <summary>
/// Used to track the state of ObjectAndItemsNullableProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Object>?> ObjectAndItemsNullablePropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ObjectAndItemsNullableProp /// Gets or Sets ObjectAndItemsNullableProp
/// </summary> /// </summary>
[JsonPropertyName("object_and_items_nullable_prop")] [JsonPropertyName("object_and_items_nullable_prop")]
public Dictionary<string, Object>? ObjectAndItemsNullableProp { get; set; } public Dictionary<string, Object>? ObjectAndItemsNullableProp { get { return this. ObjectAndItemsNullablePropOption; } set { this.ObjectAndItemsNullablePropOption = new(value); } }
/// <summary>
/// Used to track the state of ObjectItemsNullable
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Object>?> ObjectItemsNullableOption { get; private set; }
/// <summary>
/// Gets or Sets ObjectItemsNullable
/// </summary>
[JsonPropertyName("object_items_nullable")]
public Dictionary<string, Object>? ObjectItemsNullable { get { return this. ObjectItemsNullableOption; } set { this.ObjectItemsNullableOption = new(value); } }
/// <summary>
/// Used to track the state of ObjectNullableProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Dictionary<string, Object>?> ObjectNullablePropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ObjectNullableProp /// Gets or Sets ObjectNullableProp
/// </summary> /// </summary>
[JsonPropertyName("object_nullable_prop")] [JsonPropertyName("object_nullable_prop")]
public Dictionary<string, Object>? ObjectNullableProp { get; set; } public Dictionary<string, Object>? ObjectNullableProp { get { return this. ObjectNullablePropOption; } set { this.ObjectNullablePropOption = new(value); } }
/// <summary>
/// Used to track the state of StringProp
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> StringPropOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets StringProp /// Gets or Sets StringProp
/// </summary> /// </summary>
[JsonPropertyName("string_prop")] [JsonPropertyName("string_prop")]
public string? StringProp { get; set; } public string? StringProp { get { return this. StringPropOption; } set { this.StringPropOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -154,9 +238,8 @@ namespace UseSourceGeneration.Model
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("class NullableClass {\n"); sb.Append("class NullableClass {\n");
sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n");
sb.Append(" ArrayItemsNullable: ").Append(ArrayItemsNullable).Append("\n");
sb.Append(" ObjectItemsNullable: ").Append(ObjectItemsNullable).Append("\n");
sb.Append(" ArrayAndItemsNullableProp: ").Append(ArrayAndItemsNullableProp).Append("\n"); sb.Append(" ArrayAndItemsNullableProp: ").Append(ArrayAndItemsNullableProp).Append("\n");
sb.Append(" ArrayItemsNullable: ").Append(ArrayItemsNullable).Append("\n");
sb.Append(" ArrayNullableProp: ").Append(ArrayNullableProp).Append("\n"); sb.Append(" ArrayNullableProp: ").Append(ArrayNullableProp).Append("\n");
sb.Append(" BooleanProp: ").Append(BooleanProp).Append("\n"); sb.Append(" BooleanProp: ").Append(BooleanProp).Append("\n");
sb.Append(" DateProp: ").Append(DateProp).Append("\n"); sb.Append(" DateProp: ").Append(DateProp).Append("\n");
@ -164,6 +247,7 @@ namespace UseSourceGeneration.Model
sb.Append(" IntegerProp: ").Append(IntegerProp).Append("\n"); sb.Append(" IntegerProp: ").Append(IntegerProp).Append("\n");
sb.Append(" NumberProp: ").Append(NumberProp).Append("\n"); sb.Append(" NumberProp: ").Append(NumberProp).Append("\n");
sb.Append(" ObjectAndItemsNullableProp: ").Append(ObjectAndItemsNullableProp).Append("\n"); sb.Append(" ObjectAndItemsNullableProp: ").Append(ObjectAndItemsNullableProp).Append("\n");
sb.Append(" ObjectItemsNullable: ").Append(ObjectItemsNullable).Append("\n");
sb.Append(" ObjectNullableProp: ").Append(ObjectNullableProp).Append("\n"); sb.Append(" ObjectNullableProp: ").Append(ObjectNullableProp).Append("\n");
sb.Append(" StringProp: ").Append(StringProp).Append("\n"); sb.Append(" StringProp: ").Append(StringProp).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
@ -224,18 +308,18 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<Object>? arrayItemsNullable = default; Option<List<Object>?> arrayAndItemsNullableProp = default;
Dictionary<string, Object>? objectItemsNullable = default; Option<List<Object>?> arrayItemsNullable = default;
List<Object>? arrayAndItemsNullableProp = default; Option<List<Object>?> arrayNullableProp = default;
List<Object>? arrayNullableProp = default; Option<bool?> booleanProp = default;
bool? booleanProp = default; Option<DateTime?> dateProp = default;
DateTime? dateProp = default; Option<DateTime?> datetimeProp = default;
DateTime? datetimeProp = default; Option<int?> integerProp = default;
int? integerProp = default; Option<decimal?> numberProp = default;
decimal? numberProp = default; Option<Dictionary<string, Object>?> objectAndItemsNullableProp = default;
Dictionary<string, Object>? objectAndItemsNullableProp = default; Option<Dictionary<string, Object>?> objectItemsNullable = default;
Dictionary<string, Object>? objectNullableProp = default; Option<Dictionary<string, Object>?> objectNullableProp = default;
string? stringProp = default; Option<string?> stringProp = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -252,52 +336,52 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "array_items_nullable":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayItemsNullable = JsonSerializer.Deserialize<List<Object>>(ref utf8JsonReader, jsonSerializerOptions);
break;
case "object_items_nullable":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
objectItemsNullable = JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions);
break;
case "array_and_items_nullable_prop": case "array_and_items_nullable_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayAndItemsNullableProp = JsonSerializer.Deserialize<List<Object>>(ref utf8JsonReader, jsonSerializerOptions); arrayAndItemsNullableProp = new Option<List<Object>?>(JsonSerializer.Deserialize<List<Object>>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "array_items_nullable":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayItemsNullable = new Option<List<Object>?>(JsonSerializer.Deserialize<List<Object>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "array_nullable_prop": case "array_nullable_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
arrayNullableProp = JsonSerializer.Deserialize<List<Object>>(ref utf8JsonReader, jsonSerializerOptions); arrayNullableProp = new Option<List<Object>?>(JsonSerializer.Deserialize<List<Object>>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "boolean_prop": case "boolean_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
booleanProp = utf8JsonReader.GetBoolean(); booleanProp = new Option<bool?>(utf8JsonReader.GetBoolean());
break; break;
case "date_prop": case "date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateProp = JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions); dateProp = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "datetime_prop": case "datetime_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
datetimeProp = JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions); datetimeProp = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "integer_prop": case "integer_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
integerProp = utf8JsonReader.GetInt32(); integerProp = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
case "number_prop": case "number_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
numberProp = utf8JsonReader.GetDecimal(); numberProp = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
case "object_and_items_nullable_prop": case "object_and_items_nullable_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
objectAndItemsNullableProp = JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions); objectAndItemsNullableProp = new Option<Dictionary<string, Object>?>(JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "object_items_nullable":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
objectItemsNullable = new Option<Dictionary<string, Object>?>(JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "object_nullable_prop": case "object_nullable_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
objectNullableProp = JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions); objectNullableProp = new Option<Dictionary<string, Object>?>(JsonSerializer.Deserialize<Dictionary<string, Object>>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "string_prop": case "string_prop":
stringProp = utf8JsonReader.GetString(); stringProp = new Option<string?>(utf8JsonReader.GetString());
break; break;
default: default:
break; break;
@ -305,13 +389,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (arrayItemsNullable == null) if (arrayItemsNullable.IsSet && arrayItemsNullable.Value == null)
throw new ArgumentNullException(nameof(arrayItemsNullable), "Property is required for class NullableClass."); throw new ArgumentNullException(nameof(arrayItemsNullable), "Property is not nullable for class NullableClass.");
if (objectItemsNullable == null) if (objectItemsNullable.IsSet && objectItemsNullable.Value == null)
throw new ArgumentNullException(nameof(objectItemsNullable), "Property is required for class NullableClass."); throw new ArgumentNullException(nameof(objectItemsNullable), "Property is not nullable for class NullableClass.");
return new NullableClass(arrayItemsNullable, objectItemsNullable, arrayAndItemsNullableProp, arrayNullableProp, booleanProp, dateProp, datetimeProp, integerProp, numberProp, objectAndItemsNullableProp, objectNullableProp, stringProp); return new NullableClass(arrayAndItemsNullableProp, arrayItemsNullable, arrayNullableProp, booleanProp, dateProp, datetimeProp, integerProp, numberProp, objectAndItemsNullableProp, objectItemsNullable, objectNullableProp, stringProp);
} }
/// <summary> /// <summary>
@ -338,45 +422,89 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, NullableClass nullableClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, NullableClass nullableClass, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("array_items_nullable"); if (nullableClass.ArrayItemsNullableOption.IsSet && nullableClass.ArrayItemsNullable == null)
JsonSerializer.Serialize(writer, nullableClass.ArrayItemsNullable, jsonSerializerOptions); throw new ArgumentNullException(nameof(nullableClass.ArrayItemsNullable), "Property is required for class NullableClass.");
writer.WritePropertyName("object_items_nullable");
JsonSerializer.Serialize(writer, nullableClass.ObjectItemsNullable, jsonSerializerOptions);
writer.WritePropertyName("array_and_items_nullable_prop");
JsonSerializer.Serialize(writer, nullableClass.ArrayAndItemsNullableProp, jsonSerializerOptions);
writer.WritePropertyName("array_nullable_prop");
JsonSerializer.Serialize(writer, nullableClass.ArrayNullableProp, jsonSerializerOptions);
if (nullableClass.BooleanProp != null) if (nullableClass.ObjectItemsNullableOption.IsSet && nullableClass.ObjectItemsNullable == null)
writer.WriteBoolean("boolean_prop", nullableClass.BooleanProp.Value); throw new ArgumentNullException(nameof(nullableClass.ObjectItemsNullable), "Property is required for class NullableClass.");
else
writer.WriteNull("boolean_prop");
if (nullableClass.DateProp != null) if (nullableClass.ArrayAndItemsNullablePropOption.IsSet)
writer.WriteString("date_prop", nullableClass.DateProp.Value.ToString(DatePropFormat)); if (nullableClass.ArrayAndItemsNullablePropOption.Value != null)
else {
writer.WriteNull("date_prop"); writer.WritePropertyName("array_and_items_nullable_prop");
JsonSerializer.Serialize(writer, nullableClass.ArrayAndItemsNullableProp, jsonSerializerOptions);
}
else
writer.WriteNull("array_and_items_nullable_prop");
if (nullableClass.ArrayItemsNullableOption.IsSet)
{
writer.WritePropertyName("array_items_nullable");
JsonSerializer.Serialize(writer, nullableClass.ArrayItemsNullable, jsonSerializerOptions);
}
if (nullableClass.ArrayNullablePropOption.IsSet)
if (nullableClass.ArrayNullablePropOption.Value != null)
{
writer.WritePropertyName("array_nullable_prop");
JsonSerializer.Serialize(writer, nullableClass.ArrayNullableProp, jsonSerializerOptions);
}
else
writer.WriteNull("array_nullable_prop");
if (nullableClass.BooleanPropOption.IsSet)
if (nullableClass.BooleanPropOption.Value != null)
writer.WriteBoolean("boolean_prop", nullableClass.BooleanPropOption.Value!.Value);
else
writer.WriteNull("boolean_prop");
if (nullableClass.DatetimeProp != null) if (nullableClass.DatePropOption.IsSet)
writer.WriteString("datetime_prop", nullableClass.DatetimeProp.Value.ToString(DatetimePropFormat)); if (nullableClass.DatePropOption.Value != null)
else writer.WriteString("date_prop", nullableClass.DatePropOption.Value!.Value.ToString(DatePropFormat));
writer.WriteNull("datetime_prop"); else
writer.WriteNull("date_prop");
if (nullableClass.IntegerProp != null) if (nullableClass.DatetimePropOption.IsSet)
writer.WriteNumber("integer_prop", nullableClass.IntegerProp.Value); if (nullableClass.DatetimePropOption.Value != null)
else writer.WriteString("datetime_prop", nullableClass.DatetimePropOption.Value!.Value.ToString(DatetimePropFormat));
writer.WriteNull("integer_prop"); else
writer.WriteNull("datetime_prop");
if (nullableClass.NumberProp != null) if (nullableClass.IntegerPropOption.IsSet)
writer.WriteNumber("number_prop", nullableClass.NumberProp.Value); if (nullableClass.IntegerPropOption.Value != null)
else writer.WriteNumber("integer_prop", nullableClass.IntegerPropOption.Value!.Value);
writer.WriteNull("number_prop"); else
writer.WriteNull("integer_prop");
writer.WritePropertyName("object_and_items_nullable_prop"); if (nullableClass.NumberPropOption.IsSet)
JsonSerializer.Serialize(writer, nullableClass.ObjectAndItemsNullableProp, jsonSerializerOptions); if (nullableClass.NumberPropOption.Value != null)
writer.WritePropertyName("object_nullable_prop"); writer.WriteNumber("number_prop", nullableClass.NumberPropOption.Value!.Value);
JsonSerializer.Serialize(writer, nullableClass.ObjectNullableProp, jsonSerializerOptions); else
writer.WriteString("string_prop", nullableClass.StringProp); writer.WriteNull("number_prop");
if (nullableClass.ObjectAndItemsNullablePropOption.IsSet)
if (nullableClass.ObjectAndItemsNullablePropOption.Value != null)
{
writer.WritePropertyName("object_and_items_nullable_prop");
JsonSerializer.Serialize(writer, nullableClass.ObjectAndItemsNullableProp, jsonSerializerOptions);
}
else
writer.WriteNull("object_and_items_nullable_prop");
if (nullableClass.ObjectItemsNullableOption.IsSet)
{
writer.WritePropertyName("object_items_nullable");
JsonSerializer.Serialize(writer, nullableClass.ObjectItemsNullable, jsonSerializerOptions);
}
if (nullableClass.ObjectNullablePropOption.IsSet)
if (nullableClass.ObjectNullablePropOption.Value != null)
{
writer.WritePropertyName("object_nullable_prop");
JsonSerializer.Serialize(writer, nullableClass.ObjectNullableProp, jsonSerializerOptions);
}
else
writer.WriteNull("object_nullable_prop");
if (nullableClass.StringPropOption.IsSet)
if (nullableClass.StringPropOption.Value != null)
writer.WriteString("string_prop", nullableClass.StringProp);
else
writer.WriteNull("string_prop");
} }
} }

View File

@ -37,20 +37,27 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="uuid">uuid</param> /// <param name="uuid">uuid</param>
[JsonConstructor] [JsonConstructor]
public NullableGuidClass(Guid? uuid = default) public NullableGuidClass(Option<Guid?> uuid = default)
{ {
Uuid = uuid; UuidOption = uuid;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Uuid
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Guid?> UuidOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Uuid /// Gets or Sets Uuid
/// </summary> /// </summary>
/// <example>72f98069-206d-4f12-9f12-3d1e525a8e84</example> /// <example>72f98069-206d-4f12-9f12-3d1e525a8e84</example>
[JsonPropertyName("uuid")] [JsonPropertyName("uuid")]
public Guid? Uuid { get; set; } public Guid? Uuid { get { return this. UuidOption; } set { this.UuidOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -105,7 +112,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Guid? uuid = default; Option<Guid?> uuid = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -124,7 +131,7 @@ namespace UseSourceGeneration.Model
{ {
case "uuid": case "uuid":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
uuid = utf8JsonReader.GetGuid(); uuid = new Option<Guid?>(utf8JsonReader.GetGuid());
break; break;
default: default:
break; break;
@ -159,11 +166,11 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, NullableGuidClass nullableGuidClass, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, NullableGuidClass nullableGuidClass, JsonSerializerOptions jsonSerializerOptions)
{ {
if (nullableGuidClass.UuidOption.IsSet)
if (nullableGuidClass.Uuid == null) if (nullableGuidClass.UuidOption.Value != null)
writer.WriteNull("uuid"); writer.WriteString("uuid", nullableGuidClass.UuidOption.Value!.Value);
else else
writer.WriteString("uuid", nullableGuidClass.Uuid.Value); writer.WriteNull("uuid");
} }
} }

View File

@ -137,7 +137,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? shapeType = default; Option<string?> shapeType = default;
Quadrilateral? quadrilateral = null; Quadrilateral? quadrilateral = null;
Triangle? triangle = null; Triangle? triangle = null;
@ -188,7 +188,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "shapeType": case "shapeType":
shapeType = utf8JsonReader.GetString(); shapeType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -196,14 +196,17 @@ namespace UseSourceGeneration.Model
} }
} }
if (shapeType == null) if (!shapeType.IsSet)
throw new ArgumentNullException(nameof(shapeType), "Property is required for class NullableShape."); throw new ArgumentException("Property is required for class NullableShape.", nameof(shapeType));
if (shapeType.IsSet && shapeType.Value == null)
throw new ArgumentNullException(nameof(shapeType), "Property is not nullable for class NullableShape.");
if (quadrilateral != null) if (quadrilateral != null)
return new NullableShape(quadrilateral, shapeType); return new NullableShape(quadrilateral, shapeType.Value!);
if (triangle != null) if (triangle != null)
return new NullableShape(triangle, shapeType); return new NullableShape(triangle, shapeType.Value!);
throw new JsonException(); throw new JsonException();
} }
@ -242,6 +245,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, NullableShape nullableShape, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, NullableShape nullableShape, JsonSerializerOptions jsonSerializerOptions)
{ {
if (nullableShape.ShapeType == null)
throw new ArgumentNullException(nameof(nullableShape.ShapeType), "Property is required for class NullableShape.");
writer.WriteString("shapeType", nullableShape.ShapeType); writer.WriteString("shapeType", nullableShape.ShapeType);
} }
} }

View File

@ -37,19 +37,26 @@ namespace UseSourceGeneration.Model
/// </summary> /// </summary>
/// <param name="justNumber">justNumber</param> /// <param name="justNumber">justNumber</param>
[JsonConstructor] [JsonConstructor]
public NumberOnly(decimal justNumber) public NumberOnly(Option<decimal?> justNumber = default)
{ {
JustNumber = justNumber; JustNumberOption = justNumber;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of JustNumber
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<decimal?> JustNumberOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets JustNumber /// Gets or Sets JustNumber
/// </summary> /// </summary>
[JsonPropertyName("JustNumber")] [JsonPropertyName("JustNumber")]
public decimal JustNumber { get; set; } public decimal? JustNumber { get { return this. JustNumberOption; } set { this.JustNumberOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -104,7 +111,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
decimal? justNumber = default; Option<decimal?> justNumber = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -123,7 +130,7 @@ namespace UseSourceGeneration.Model
{ {
case "JustNumber": case "JustNumber":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
justNumber = utf8JsonReader.GetDecimal(); justNumber = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
default: default:
break; break;
@ -131,10 +138,10 @@ namespace UseSourceGeneration.Model
} }
} }
if (justNumber == null) if (justNumber.IsSet && justNumber.Value == null)
throw new ArgumentNullException(nameof(justNumber), "Property is required for class NumberOnly."); throw new ArgumentNullException(nameof(justNumber), "Property is not nullable for class NumberOnly.");
return new NumberOnly(justNumber.Value); return new NumberOnly(justNumber);
} }
/// <summary> /// <summary>
@ -161,7 +168,8 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, NumberOnly numberOnly, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, NumberOnly numberOnly, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteNumber("JustNumber", numberOnly.JustNumber); if (numberOnly.JustNumberOption.IsSet)
writer.WriteNumber("JustNumber", numberOnly.JustNumberOption.Value!.Value);
} }
} }

View File

@ -40,43 +40,71 @@ namespace UseSourceGeneration.Model
/// <param name="id">id</param> /// <param name="id">id</param>
/// <param name="uuid">uuid</param> /// <param name="uuid">uuid</param>
[JsonConstructor] [JsonConstructor]
public ObjectWithDeprecatedFields(List<string> bars, DeprecatedObject deprecatedRef, decimal id, string uuid) public ObjectWithDeprecatedFields(Option<List<string>?> bars = default, Option<DeprecatedObject?> deprecatedRef = default, Option<decimal?> id = default, Option<string?> uuid = default)
{ {
Bars = bars; BarsOption = bars;
DeprecatedRef = deprecatedRef; DeprecatedRefOption = deprecatedRef;
Id = id; IdOption = id;
Uuid = uuid; UuidOption = uuid;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of Bars
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<string>?> BarsOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Bars /// Gets or Sets Bars
/// </summary> /// </summary>
[JsonPropertyName("bars")] [JsonPropertyName("bars")]
[Obsolete] [Obsolete]
public List<string> Bars { get; set; } public List<string>? Bars { get { return this. BarsOption; } set { this.BarsOption = new(value); } }
/// <summary>
/// Used to track the state of DeprecatedRef
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DeprecatedObject?> DeprecatedRefOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets DeprecatedRef /// Gets or Sets DeprecatedRef
/// </summary> /// </summary>
[JsonPropertyName("deprecatedRef")] [JsonPropertyName("deprecatedRef")]
[Obsolete] [Obsolete]
public DeprecatedObject DeprecatedRef { get; set; } public DeprecatedObject? DeprecatedRef { get { return this. DeprecatedRefOption; } set { this.DeprecatedRefOption = new(value); } }
/// <summary>
/// Used to track the state of Id
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<decimal?> IdOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Id /// Gets or Sets Id
/// </summary> /// </summary>
[JsonPropertyName("id")] [JsonPropertyName("id")]
[Obsolete] [Obsolete]
public decimal Id { get; set; } public decimal? Id { get { return this. IdOption; } set { this.IdOption = new(value); } }
/// <summary>
/// Used to track the state of Uuid
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> UuidOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Uuid /// Gets or Sets Uuid
/// </summary> /// </summary>
[JsonPropertyName("uuid")] [JsonPropertyName("uuid")]
public string Uuid { get; set; } public string? Uuid { get { return this. UuidOption; } set { this.UuidOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -134,10 +162,10 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
List<string>? bars = default; Option<List<string>?> bars = default;
DeprecatedObject? deprecatedRef = default; Option<DeprecatedObject?> deprecatedRef = default;
decimal? id = default; Option<decimal?> id = default;
string? uuid = default; Option<string?> uuid = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -156,18 +184,18 @@ namespace UseSourceGeneration.Model
{ {
case "bars": case "bars":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
bars = JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions); bars = new Option<List<string>?>(JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "deprecatedRef": case "deprecatedRef":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
deprecatedRef = JsonSerializer.Deserialize<DeprecatedObject>(ref utf8JsonReader, jsonSerializerOptions); deprecatedRef = new Option<DeprecatedObject?>(JsonSerializer.Deserialize<DeprecatedObject>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
case "id": case "id":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
id = utf8JsonReader.GetDecimal(); id = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
case "uuid": case "uuid":
uuid = utf8JsonReader.GetString(); uuid = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -175,19 +203,19 @@ namespace UseSourceGeneration.Model
} }
} }
if (bars == null) if (bars.IsSet && bars.Value == null)
throw new ArgumentNullException(nameof(bars), "Property is required for class ObjectWithDeprecatedFields."); throw new ArgumentNullException(nameof(bars), "Property is not nullable for class ObjectWithDeprecatedFields.");
if (deprecatedRef == null) if (deprecatedRef.IsSet && deprecatedRef.Value == null)
throw new ArgumentNullException(nameof(deprecatedRef), "Property is required for class ObjectWithDeprecatedFields."); throw new ArgumentNullException(nameof(deprecatedRef), "Property is not nullable for class ObjectWithDeprecatedFields.");
if (id == null) if (id.IsSet && id.Value == null)
throw new ArgumentNullException(nameof(id), "Property is required for class ObjectWithDeprecatedFields."); throw new ArgumentNullException(nameof(id), "Property is not nullable for class ObjectWithDeprecatedFields.");
if (uuid == null) if (uuid.IsSet && uuid.Value == null)
throw new ArgumentNullException(nameof(uuid), "Property is required for class ObjectWithDeprecatedFields."); throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class ObjectWithDeprecatedFields.");
return new ObjectWithDeprecatedFields(bars, deprecatedRef, id.Value, uuid); return new ObjectWithDeprecatedFields(bars, deprecatedRef, id, uuid);
} }
/// <summary> /// <summary>
@ -214,12 +242,30 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ObjectWithDeprecatedFields objectWithDeprecatedFields, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ObjectWithDeprecatedFields objectWithDeprecatedFields, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("bars"); if (objectWithDeprecatedFields.BarsOption.IsSet && objectWithDeprecatedFields.Bars == null)
JsonSerializer.Serialize(writer, objectWithDeprecatedFields.Bars, jsonSerializerOptions); throw new ArgumentNullException(nameof(objectWithDeprecatedFields.Bars), "Property is required for class ObjectWithDeprecatedFields.");
writer.WritePropertyName("deprecatedRef");
JsonSerializer.Serialize(writer, objectWithDeprecatedFields.DeprecatedRef, jsonSerializerOptions); if (objectWithDeprecatedFields.DeprecatedRefOption.IsSet && objectWithDeprecatedFields.DeprecatedRef == null)
writer.WriteNumber("id", objectWithDeprecatedFields.Id); throw new ArgumentNullException(nameof(objectWithDeprecatedFields.DeprecatedRef), "Property is required for class ObjectWithDeprecatedFields.");
writer.WriteString("uuid", objectWithDeprecatedFields.Uuid);
if (objectWithDeprecatedFields.UuidOption.IsSet && objectWithDeprecatedFields.Uuid == null)
throw new ArgumentNullException(nameof(objectWithDeprecatedFields.Uuid), "Property is required for class ObjectWithDeprecatedFields.");
if (objectWithDeprecatedFields.BarsOption.IsSet)
{
writer.WritePropertyName("bars");
JsonSerializer.Serialize(writer, objectWithDeprecatedFields.Bars, jsonSerializerOptions);
}
if (objectWithDeprecatedFields.DeprecatedRefOption.IsSet)
{
writer.WritePropertyName("deprecatedRef");
JsonSerializer.Serialize(writer, objectWithDeprecatedFields.DeprecatedRef, jsonSerializerOptions);
}
if (objectWithDeprecatedFields.IdOption.IsSet)
writer.WriteNumber("id", objectWithDeprecatedFields.IdOption.Value!.Value);
if (objectWithDeprecatedFields.UuidOption.IsSet)
writer.WriteString("uuid", objectWithDeprecatedFields.Uuid);
} }
} }

View File

@ -35,21 +35,21 @@ namespace UseSourceGeneration.Model
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Order" /> class. /// Initializes a new instance of the <see cref="Order" /> class.
/// </summary> /// </summary>
/// <param name="complete">complete (default to false)</param>
/// <param name="id">id</param> /// <param name="id">id</param>
/// <param name="petId">petId</param> /// <param name="petId">petId</param>
/// <param name="quantity">quantity</param> /// <param name="quantity">quantity</param>
/// <param name="shipDate">shipDate</param> /// <param name="shipDate">shipDate</param>
/// <param name="status">Order Status</param> /// <param name="status">Order Status</param>
/// <param name="complete">complete (default to false)</param>
[JsonConstructor] [JsonConstructor]
public Order(long id, long petId, int quantity, DateTime shipDate, StatusEnum status, bool complete = false) public Order(Option<bool?> complete = default, Option<long?> id = default, Option<long?> petId = default, Option<int?> quantity = default, Option<DateTime?> shipDate = default, Option<StatusEnum?> status = default)
{ {
Id = id; CompleteOption = complete;
PetId = petId; IdOption = id;
Quantity = quantity; PetIdOption = petId;
ShipDate = shipDate; QuantityOption = quantity;
Status = status; ShipDateOption = shipDate;
Complete = complete; StatusOption = status;
OnCreated(); OnCreated();
} }
@ -122,9 +122,8 @@ namespace UseSourceGeneration.Model
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public static string StatusEnumToJsonValue(StatusEnum value) public static string StatusEnumToJsonValue(StatusEnum? value)
{ {
if (value == StatusEnum.Placed) if (value == StatusEnum.Placed)
return "placed"; return "placed";
@ -137,43 +136,85 @@ namespace UseSourceGeneration.Model
throw new NotImplementedException($"Value could not be handled: '{value}'"); throw new NotImplementedException($"Value could not be handled: '{value}'");
} }
/// <summary>
/// Used to track the state of Status
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<StatusEnum?> StatusOption { get; private set; }
/// <summary> /// <summary>
/// Order Status /// Order Status
/// </summary> /// </summary>
/// <value>Order Status</value> /// <value>Order Status</value>
[JsonPropertyName("status")] [JsonPropertyName("status")]
public StatusEnum Status { get; set; } public StatusEnum? Status { get { return this.StatusOption; } set { this.StatusOption = new(value); } }
/// <summary>
/// Used to track the state of Complete
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<bool?> CompleteOption { get; private set; }
/// <summary>
/// Gets or Sets Complete
/// </summary>
[JsonPropertyName("complete")]
public bool? Complete { get { return this. CompleteOption; } set { this.CompleteOption = new(value); } }
/// <summary>
/// Used to track the state of Id
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<long?> IdOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Id /// Gets or Sets Id
/// </summary> /// </summary>
[JsonPropertyName("id")] [JsonPropertyName("id")]
public long Id { get; set; } public long? Id { get { return this. IdOption; } set { this.IdOption = new(value); } }
/// <summary>
/// Used to track the state of PetId
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<long?> PetIdOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets PetId /// Gets or Sets PetId
/// </summary> /// </summary>
[JsonPropertyName("petId")] [JsonPropertyName("petId")]
public long PetId { get; set; } public long? PetId { get { return this. PetIdOption; } set { this.PetIdOption = new(value); } }
/// <summary>
/// Used to track the state of Quantity
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<int?> QuantityOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Quantity /// Gets or Sets Quantity
/// </summary> /// </summary>
[JsonPropertyName("quantity")] [JsonPropertyName("quantity")]
public int Quantity { get; set; } public int? Quantity { get { return this. QuantityOption; } set { this.QuantityOption = new(value); } }
/// <summary>
/// Used to track the state of ShipDate
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<DateTime?> ShipDateOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets ShipDate /// Gets or Sets ShipDate
/// </summary> /// </summary>
/// <example>2020-02-02T20:20:20.000222Z</example> /// <example>2020-02-02T20:20:20.000222Z</example>
[JsonPropertyName("shipDate")] [JsonPropertyName("shipDate")]
public DateTime ShipDate { get; set; } public DateTime? ShipDate { get { return this. ShipDateOption; } set { this.ShipDateOption = new(value); } }
/// <summary>
/// Gets or Sets Complete
/// </summary>
[JsonPropertyName("complete")]
public bool Complete { get; set; }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -189,12 +230,12 @@ namespace UseSourceGeneration.Model
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("class Order {\n"); sb.Append("class Order {\n");
sb.Append(" Complete: ").Append(Complete).Append("\n");
sb.Append(" Id: ").Append(Id).Append("\n"); sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" PetId: ").Append(PetId).Append("\n"); sb.Append(" PetId: ").Append(PetId).Append("\n");
sb.Append(" Quantity: ").Append(Quantity).Append("\n"); sb.Append(" Quantity: ").Append(Quantity).Append("\n");
sb.Append(" ShipDate: ").Append(ShipDate).Append("\n"); sb.Append(" ShipDate: ").Append(ShipDate).Append("\n");
sb.Append(" Status: ").Append(Status).Append("\n"); sb.Append(" Status: ").Append(Status).Append("\n");
sb.Append(" Complete: ").Append(Complete).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append("}\n"); sb.Append("}\n");
return sb.ToString(); return sb.ToString();
@ -238,12 +279,12 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
long? id = default; Option<bool?> complete = default;
long? petId = default; Option<long?> id = default;
int? quantity = default; Option<long?> petId = default;
DateTime? shipDate = default; Option<int?> quantity = default;
Order.StatusEnum? status = default; Option<DateTime?> shipDate = default;
bool? complete = default; Option<Order.StatusEnum?> status = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -260,31 +301,30 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "complete":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
complete = new Option<bool?>(utf8JsonReader.GetBoolean());
break;
case "id": case "id":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
id = utf8JsonReader.GetInt64(); id = new Option<long?>(utf8JsonReader.GetInt64());
break; break;
case "petId": case "petId":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
petId = utf8JsonReader.GetInt64(); petId = new Option<long?>(utf8JsonReader.GetInt64());
break; break;
case "quantity": case "quantity":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
quantity = utf8JsonReader.GetInt32(); quantity = new Option<int?>(utf8JsonReader.GetInt32());
break; break;
case "shipDate": case "shipDate":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
shipDate = JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions); shipDate = new Option<DateTime?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
break; break;
case "status": case "status":
string? statusRawValue = utf8JsonReader.GetString(); string? statusRawValue = utf8JsonReader.GetString();
status = statusRawValue == null if (statusRawValue != null)
? null status = new Option<Order.StatusEnum?>(Order.StatusEnumFromStringOrDefault(statusRawValue));
: Order.StatusEnumFromStringOrDefault(statusRawValue);
break;
case "complete":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
complete = utf8JsonReader.GetBoolean();
break; break;
default: default:
break; break;
@ -292,25 +332,25 @@ namespace UseSourceGeneration.Model
} }
} }
if (id == null) if (complete.IsSet && complete.Value == null)
throw new ArgumentNullException(nameof(id), "Property is required for class Order."); throw new ArgumentNullException(nameof(complete), "Property is not nullable for class Order.");
if (petId == null) if (id.IsSet && id.Value == null)
throw new ArgumentNullException(nameof(petId), "Property is required for class Order."); throw new ArgumentNullException(nameof(id), "Property is not nullable for class Order.");
if (quantity == null) if (petId.IsSet && petId.Value == null)
throw new ArgumentNullException(nameof(quantity), "Property is required for class Order."); throw new ArgumentNullException(nameof(petId), "Property is not nullable for class Order.");
if (shipDate == null) if (quantity.IsSet && quantity.Value == null)
throw new ArgumentNullException(nameof(shipDate), "Property is required for class Order."); throw new ArgumentNullException(nameof(quantity), "Property is not nullable for class Order.");
if (status == null) if (shipDate.IsSet && shipDate.Value == null)
throw new ArgumentNullException(nameof(status), "Property is required for class Order."); throw new ArgumentNullException(nameof(shipDate), "Property is not nullable for class Order.");
if (complete == null) if (status.IsSet && status.Value == null)
throw new ArgumentNullException(nameof(complete), "Property is required for class Order."); throw new ArgumentNullException(nameof(status), "Property is not nullable for class Order.");
return new Order(id.Value, petId.Value, quantity.Value, shipDate.Value, status.Value, complete.Value); return new Order(complete, id, petId, quantity, shipDate, status);
} }
/// <summary> /// <summary>
@ -337,18 +377,26 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Order order, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Order order, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteNumber("id", order.Id); if (order.CompleteOption.IsSet)
writer.WriteNumber("petId", order.PetId); writer.WriteBoolean("complete", order.CompleteOption.Value!.Value);
writer.WriteNumber("quantity", order.Quantity);
writer.WriteString("shipDate", order.ShipDate.ToString(ShipDateFormat));
var statusRawValue = Order.StatusEnumToJsonValue(order.Status); if (order.IdOption.IsSet)
writer.WriteNumber("id", order.IdOption.Value!.Value);
if (order.PetIdOption.IsSet)
writer.WriteNumber("petId", order.PetIdOption.Value!.Value);
if (order.QuantityOption.IsSet)
writer.WriteNumber("quantity", order.QuantityOption.Value!.Value);
if (order.ShipDateOption.IsSet)
writer.WriteString("shipDate", order.ShipDateOption.Value!.Value.ToString(ShipDateFormat));
var statusRawValue = Order.StatusEnumToJsonValue(order.StatusOption.Value!.Value);
if (statusRawValue != null) if (statusRawValue != null)
writer.WriteString("status", statusRawValue); writer.WriteString("status", statusRawValue);
else else
writer.WriteNull("status"); writer.WriteNull("status");
writer.WriteBoolean("complete", order.Complete);
} }
} }

View File

@ -39,33 +39,54 @@ namespace UseSourceGeneration.Model
/// <param name="myNumber">myNumber</param> /// <param name="myNumber">myNumber</param>
/// <param name="myString">myString</param> /// <param name="myString">myString</param>
[JsonConstructor] [JsonConstructor]
public OuterComposite(bool myBoolean, decimal myNumber, string myString) public OuterComposite(Option<bool?> myBoolean = default, Option<decimal?> myNumber = default, Option<string?> myString = default)
{ {
MyBoolean = myBoolean; MyBooleanOption = myBoolean;
MyNumber = myNumber; MyNumberOption = myNumber;
MyString = myString; MyStringOption = myString;
OnCreated(); OnCreated();
} }
partial void OnCreated(); partial void OnCreated();
/// <summary>
/// Used to track the state of MyBoolean
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<bool?> MyBooleanOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets MyBoolean /// Gets or Sets MyBoolean
/// </summary> /// </summary>
[JsonPropertyName("my_boolean")] [JsonPropertyName("my_boolean")]
public bool MyBoolean { get; set; } public bool? MyBoolean { get { return this. MyBooleanOption; } set { this.MyBooleanOption = new(value); } }
/// <summary>
/// Used to track the state of MyNumber
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<decimal?> MyNumberOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets MyNumber /// Gets or Sets MyNumber
/// </summary> /// </summary>
[JsonPropertyName("my_number")] [JsonPropertyName("my_number")]
public decimal MyNumber { get; set; } public decimal? MyNumber { get { return this. MyNumberOption; } set { this.MyNumberOption = new(value); } }
/// <summary>
/// Used to track the state of MyString
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<string?> MyStringOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets MyString /// Gets or Sets MyString
/// </summary> /// </summary>
[JsonPropertyName("my_string")] [JsonPropertyName("my_string")]
public string MyString { get; set; } public string? MyString { get { return this. MyStringOption; } set { this.MyStringOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -122,9 +143,9 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
bool? myBoolean = default; Option<bool?> myBoolean = default;
decimal? myNumber = default; Option<decimal?> myNumber = default;
string? myString = default; Option<string?> myString = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -143,14 +164,14 @@ namespace UseSourceGeneration.Model
{ {
case "my_boolean": case "my_boolean":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
myBoolean = utf8JsonReader.GetBoolean(); myBoolean = new Option<bool?>(utf8JsonReader.GetBoolean());
break; break;
case "my_number": case "my_number":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
myNumber = utf8JsonReader.GetDecimal(); myNumber = new Option<decimal?>(utf8JsonReader.GetDecimal());
break; break;
case "my_string": case "my_string":
myString = utf8JsonReader.GetString(); myString = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -158,16 +179,16 @@ namespace UseSourceGeneration.Model
} }
} }
if (myBoolean == null) if (myBoolean.IsSet && myBoolean.Value == null)
throw new ArgumentNullException(nameof(myBoolean), "Property is required for class OuterComposite."); throw new ArgumentNullException(nameof(myBoolean), "Property is not nullable for class OuterComposite.");
if (myNumber == null) if (myNumber.IsSet && myNumber.Value == null)
throw new ArgumentNullException(nameof(myNumber), "Property is required for class OuterComposite."); throw new ArgumentNullException(nameof(myNumber), "Property is not nullable for class OuterComposite.");
if (myString == null) if (myString.IsSet && myString.Value == null)
throw new ArgumentNullException(nameof(myString), "Property is required for class OuterComposite."); throw new ArgumentNullException(nameof(myString), "Property is not nullable for class OuterComposite.");
return new OuterComposite(myBoolean.Value, myNumber.Value, myString); return new OuterComposite(myBoolean, myNumber, myString);
} }
/// <summary> /// <summary>
@ -194,9 +215,17 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, OuterComposite outerComposite, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, OuterComposite outerComposite, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WriteBoolean("my_boolean", outerComposite.MyBoolean); if (outerComposite.MyStringOption.IsSet && outerComposite.MyString == null)
writer.WriteNumber("my_number", outerComposite.MyNumber); throw new ArgumentNullException(nameof(outerComposite.MyString), "Property is required for class OuterComposite.");
writer.WriteString("my_string", outerComposite.MyString);
if (outerComposite.MyBooleanOption.IsSet)
writer.WriteBoolean("my_boolean", outerComposite.MyBooleanOption.Value!.Value);
if (outerComposite.MyNumberOption.IsSet)
writer.WriteNumber("my_number", outerComposite.MyNumberOption.Value!.Value);
if (outerComposite.MyStringOption.IsSet)
writer.WriteString("my_string", outerComposite.MyString);
} }
} }

View File

@ -80,7 +80,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? petType = default; Option<string?> petType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -98,7 +98,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "pet_type": case "pet_type":
petType = utf8JsonReader.GetString(); petType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -106,10 +106,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (petType == null) if (!petType.IsSet)
throw new ArgumentNullException(nameof(petType), "Property is required for class ParentPet."); throw new ArgumentException("Property is required for class ParentPet.", nameof(petType));
return new ParentPet(petType); if (petType.IsSet && petType.Value == null)
throw new ArgumentNullException(nameof(petType), "Property is not nullable for class ParentPet.");
return new ParentPet(petType.Value!);
} }
/// <summary> /// <summary>
@ -136,6 +139,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, ParentPet parentPet, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, ParentPet parentPet, JsonSerializerOptions jsonSerializerOptions)
{ {
if (parentPet.PetType == null)
throw new ArgumentNullException(nameof(parentPet.PetType), "Property is required for class ParentPet.");
writer.WriteString("pet_type", parentPet.PetType); writer.WriteString("pet_type", parentPet.PetType);
} }
} }

View File

@ -35,21 +35,21 @@ namespace UseSourceGeneration.Model
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pet" /> class. /// Initializes a new instance of the <see cref="Pet" /> class.
/// </summary> /// </summary>
/// <param name="category">category</param>
/// <param name="id">id</param>
/// <param name="name">name</param> /// <param name="name">name</param>
/// <param name="photoUrls">photoUrls</param> /// <param name="photoUrls">photoUrls</param>
/// <param name="category">category</param>
/// <param name="id">id</param>
/// <param name="status">pet status in the store</param> /// <param name="status">pet status in the store</param>
/// <param name="tags">tags</param> /// <param name="tags">tags</param>
[JsonConstructor] [JsonConstructor]
public Pet(Category category, long id, string name, List<string> photoUrls, StatusEnum status, List<Tag> tags) public Pet(string name, List<string> photoUrls, Option<Category?> category = default, Option<long?> id = default, Option<StatusEnum?> status = default, Option<List<Tag>?> tags = default)
{ {
Category = category;
Id = id;
Name = name; Name = name;
PhotoUrls = photoUrls; PhotoUrls = photoUrls;
Status = status; CategoryOption = category;
Tags = tags; IdOption = id;
StatusOption = status;
TagsOption = tags;
OnCreated(); OnCreated();
} }
@ -122,9 +122,8 @@ namespace UseSourceGeneration.Model
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public static string StatusEnumToJsonValue(StatusEnum value) public static string StatusEnumToJsonValue(StatusEnum? value)
{ {
if (value == StatusEnum.Available) if (value == StatusEnum.Available)
return "available"; return "available";
@ -137,24 +136,19 @@ namespace UseSourceGeneration.Model
throw new NotImplementedException($"Value could not be handled: '{value}'"); throw new NotImplementedException($"Value could not be handled: '{value}'");
} }
/// <summary>
/// Used to track the state of Status
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<StatusEnum?> StatusOption { get; private set; }
/// <summary> /// <summary>
/// pet status in the store /// pet status in the store
/// </summary> /// </summary>
/// <value>pet status in the store</value> /// <value>pet status in the store</value>
[JsonPropertyName("status")] [JsonPropertyName("status")]
public StatusEnum Status { get; set; } public StatusEnum? Status { get { return this.StatusOption; } set { this.StatusOption = new(value); } }
/// <summary>
/// Gets or Sets Category
/// </summary>
[JsonPropertyName("category")]
public Category Category { get; set; }
/// <summary>
/// Gets or Sets Id
/// </summary>
[JsonPropertyName("id")]
public long Id { get; set; }
/// <summary> /// <summary>
/// Gets or Sets Name /// Gets or Sets Name
@ -169,11 +163,44 @@ namespace UseSourceGeneration.Model
[JsonPropertyName("photoUrls")] [JsonPropertyName("photoUrls")]
public List<string> PhotoUrls { get; set; } public List<string> PhotoUrls { get; set; }
/// <summary>
/// Used to track the state of Category
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<Category?> CategoryOption { get; private set; }
/// <summary>
/// Gets or Sets Category
/// </summary>
[JsonPropertyName("category")]
public Category? Category { get { return this. CategoryOption; } set { this.CategoryOption = new(value); } }
/// <summary>
/// Used to track the state of Id
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<long?> IdOption { get; private set; }
/// <summary>
/// Gets or Sets Id
/// </summary>
[JsonPropertyName("id")]
public long? Id { get { return this. IdOption; } set { this.IdOption = new(value); } }
/// <summary>
/// Used to track the state of Tags
/// </summary>
[JsonIgnore]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public Option<List<Tag>?> TagsOption { get; private set; }
/// <summary> /// <summary>
/// Gets or Sets Tags /// Gets or Sets Tags
/// </summary> /// </summary>
[JsonPropertyName("tags")] [JsonPropertyName("tags")]
public List<Tag> Tags { get; set; } public List<Tag>? Tags { get { return this. TagsOption; } set { this.TagsOption = new(value); } }
/// <summary> /// <summary>
/// Gets or Sets additional properties /// Gets or Sets additional properties
@ -189,10 +216,10 @@ namespace UseSourceGeneration.Model
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("class Pet {\n"); sb.Append("class Pet {\n");
sb.Append(" Category: ").Append(Category).Append("\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Name: ").Append(Name).Append("\n"); sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n"); sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n");
sb.Append(" Category: ").Append(Category).Append("\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Status: ").Append(Status).Append("\n"); sb.Append(" Status: ").Append(Status).Append("\n");
sb.Append(" Tags: ").Append(Tags).Append("\n"); sb.Append(" Tags: ").Append(Tags).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
@ -233,12 +260,12 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Category? category = default; Option<string?> name = default;
long? id = default; Option<List<string>?> photoUrls = default;
string? name = default; Option<Category?> category = default;
List<string>? photoUrls = default; Option<long?> id = default;
Pet.StatusEnum? status = default; Option<Pet.StatusEnum?> status = default;
List<Tag>? tags = default; Option<List<Tag>?> tags = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -255,30 +282,29 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "category":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
category = JsonSerializer.Deserialize<Category>(ref utf8JsonReader, jsonSerializerOptions);
break;
case "id":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
id = utf8JsonReader.GetInt64();
break;
case "name": case "name":
name = utf8JsonReader.GetString(); name = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
case "photoUrls": case "photoUrls":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
photoUrls = JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions); photoUrls = new Option<List<string>?>(JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions)!);
break;
case "category":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
category = new Option<Category?>(JsonSerializer.Deserialize<Category>(ref utf8JsonReader, jsonSerializerOptions)!);
break;
case "id":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
id = new Option<long?>(utf8JsonReader.GetInt64());
break; break;
case "status": case "status":
string? statusRawValue = utf8JsonReader.GetString(); string? statusRawValue = utf8JsonReader.GetString();
status = statusRawValue == null if (statusRawValue != null)
? null status = new Option<Pet.StatusEnum?>(Pet.StatusEnumFromStringOrDefault(statusRawValue));
: Pet.StatusEnumFromStringOrDefault(statusRawValue);
break; break;
case "tags": case "tags":
if (utf8JsonReader.TokenType != JsonTokenType.Null) if (utf8JsonReader.TokenType != JsonTokenType.Null)
tags = JsonSerializer.Deserialize<List<Tag>>(ref utf8JsonReader, jsonSerializerOptions); tags = new Option<List<Tag>?>(JsonSerializer.Deserialize<List<Tag>>(ref utf8JsonReader, jsonSerializerOptions)!);
break; break;
default: default:
break; break;
@ -286,25 +312,31 @@ namespace UseSourceGeneration.Model
} }
} }
if (category == null) if (!name.IsSet)
throw new ArgumentNullException(nameof(category), "Property is required for class Pet."); throw new ArgumentException("Property is required for class Pet.", nameof(name));
if (id == null) if (!photoUrls.IsSet)
throw new ArgumentNullException(nameof(id), "Property is required for class Pet."); throw new ArgumentException("Property is required for class Pet.", nameof(photoUrls));
if (name == null) if (name.IsSet && name.Value == null)
throw new ArgumentNullException(nameof(name), "Property is required for class Pet."); throw new ArgumentNullException(nameof(name), "Property is not nullable for class Pet.");
if (photoUrls == null) if (photoUrls.IsSet && photoUrls.Value == null)
throw new ArgumentNullException(nameof(photoUrls), "Property is required for class Pet."); throw new ArgumentNullException(nameof(photoUrls), "Property is not nullable for class Pet.");
if (status == null) if (category.IsSet && category.Value == null)
throw new ArgumentNullException(nameof(status), "Property is required for class Pet."); throw new ArgumentNullException(nameof(category), "Property is not nullable for class Pet.");
if (tags == null) if (id.IsSet && id.Value == null)
throw new ArgumentNullException(nameof(tags), "Property is required for class Pet."); throw new ArgumentNullException(nameof(id), "Property is not nullable for class Pet.");
return new Pet(category, id.Value, name, photoUrls, status.Value, tags); if (status.IsSet && status.Value == null)
throw new ArgumentNullException(nameof(status), "Property is not nullable for class Pet.");
if (tags.IsSet && tags.Value == null)
throw new ArgumentNullException(nameof(tags), "Property is not nullable for class Pet.");
return new Pet(name.Value!, photoUrls.Value!, category, id, status, tags);
} }
/// <summary> /// <summary>
@ -331,21 +363,41 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Pet pet, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Pet pet, JsonSerializerOptions jsonSerializerOptions)
{ {
writer.WritePropertyName("category"); if (pet.Name == null)
JsonSerializer.Serialize(writer, pet.Category, jsonSerializerOptions); throw new ArgumentNullException(nameof(pet.Name), "Property is required for class Pet.");
writer.WriteNumber("id", pet.Id);
if (pet.PhotoUrls == null)
throw new ArgumentNullException(nameof(pet.PhotoUrls), "Property is required for class Pet.");
if (pet.CategoryOption.IsSet && pet.Category == null)
throw new ArgumentNullException(nameof(pet.Category), "Property is required for class Pet.");
if (pet.TagsOption.IsSet && pet.Tags == null)
throw new ArgumentNullException(nameof(pet.Tags), "Property is required for class Pet.");
writer.WriteString("name", pet.Name); writer.WriteString("name", pet.Name);
writer.WritePropertyName("photoUrls"); writer.WritePropertyName("photoUrls");
JsonSerializer.Serialize(writer, pet.PhotoUrls, jsonSerializerOptions); JsonSerializer.Serialize(writer, pet.PhotoUrls, jsonSerializerOptions);
if (pet.CategoryOption.IsSet)
{
writer.WritePropertyName("category");
JsonSerializer.Serialize(writer, pet.Category, jsonSerializerOptions);
}
if (pet.IdOption.IsSet)
writer.WriteNumber("id", pet.IdOption.Value!.Value);
var statusRawValue = Pet.StatusEnumToJsonValue(pet.Status); var statusRawValue = Pet.StatusEnumToJsonValue(pet.StatusOption.Value!.Value);
if (statusRawValue != null) if (statusRawValue != null)
writer.WriteString("status", statusRawValue); writer.WriteString("status", statusRawValue);
else else
writer.WriteNull("status"); writer.WriteNull("status");
writer.WritePropertyName("tags"); if (pet.TagsOption.IsSet)
JsonSerializer.Serialize(writer, pet.Tags, jsonSerializerOptions); {
writer.WritePropertyName("tags");
JsonSerializer.Serialize(writer, pet.Tags, jsonSerializerOptions);
}
} }
} }

View File

@ -137,7 +137,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? className = default; Option<string?> className = default;
BasquePig? basquePig = null; BasquePig? basquePig = null;
DanishPig? danishPig = null; DanishPig? danishPig = null;
@ -188,7 +188,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "className": case "className":
className = utf8JsonReader.GetString(); className = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -196,14 +196,17 @@ namespace UseSourceGeneration.Model
} }
} }
if (className == null) if (!className.IsSet)
throw new ArgumentNullException(nameof(className), "Property is required for class Pig."); throw new ArgumentException("Property is required for class Pig.", nameof(className));
if (className.IsSet && className.Value == null)
throw new ArgumentNullException(nameof(className), "Property is not nullable for class Pig.");
if (basquePig != null) if (basquePig != null)
return new Pig(basquePig, className); return new Pig(basquePig, className.Value!);
if (danishPig != null) if (danishPig != null)
return new Pig(danishPig, className); return new Pig(danishPig, className.Value!);
throw new JsonException(); throw new JsonException();
} }
@ -242,6 +245,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Pig pig, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Pig pig, JsonSerializerOptions jsonSerializerOptions)
{ {
if (pig.ClassName == null)
throw new ArgumentNullException(nameof(pig.ClassName), "Property is required for class Pig.");
writer.WriteString("className", pig.ClassName); writer.WriteString("className", pig.ClassName);
} }
} }

View File

@ -137,7 +137,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? quadrilateralType = default; Option<string?> quadrilateralType = default;
ComplexQuadrilateral? complexQuadrilateral = null; ComplexQuadrilateral? complexQuadrilateral = null;
SimpleQuadrilateral? simpleQuadrilateral = null; SimpleQuadrilateral? simpleQuadrilateral = null;
@ -188,7 +188,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "quadrilateralType": case "quadrilateralType":
quadrilateralType = utf8JsonReader.GetString(); quadrilateralType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -196,14 +196,17 @@ namespace UseSourceGeneration.Model
} }
} }
if (quadrilateralType == null) if (!quadrilateralType.IsSet)
throw new ArgumentNullException(nameof(quadrilateralType), "Property is required for class Quadrilateral."); throw new ArgumentException("Property is required for class Quadrilateral.", nameof(quadrilateralType));
if (quadrilateralType.IsSet && quadrilateralType.Value == null)
throw new ArgumentNullException(nameof(quadrilateralType), "Property is not nullable for class Quadrilateral.");
if (complexQuadrilateral != null) if (complexQuadrilateral != null)
return new Quadrilateral(complexQuadrilateral, quadrilateralType); return new Quadrilateral(complexQuadrilateral, quadrilateralType.Value!);
if (simpleQuadrilateral != null) if (simpleQuadrilateral != null)
return new Quadrilateral(simpleQuadrilateral, quadrilateralType); return new Quadrilateral(simpleQuadrilateral, quadrilateralType.Value!);
throw new JsonException(); throw new JsonException();
} }
@ -242,6 +245,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, Quadrilateral quadrilateral, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, Quadrilateral quadrilateral, JsonSerializerOptions jsonSerializerOptions)
{ {
if (quadrilateral.QuadrilateralType == null)
throw new ArgumentNullException(nameof(quadrilateral.QuadrilateralType), "Property is required for class Quadrilateral.");
writer.WriteString("quadrilateralType", quadrilateral.QuadrilateralType); writer.WriteString("quadrilateralType", quadrilateral.QuadrilateralType);
} }
} }

View File

@ -104,7 +104,7 @@ namespace UseSourceGeneration.Model
JsonTokenType startingTokenType = utf8JsonReader.TokenType; JsonTokenType startingTokenType = utf8JsonReader.TokenType;
string? quadrilateralType = default; Option<string?> quadrilateralType = default;
while (utf8JsonReader.Read()) while (utf8JsonReader.Read())
{ {
@ -122,7 +122,7 @@ namespace UseSourceGeneration.Model
switch (localVarJsonPropertyName) switch (localVarJsonPropertyName)
{ {
case "quadrilateralType": case "quadrilateralType":
quadrilateralType = utf8JsonReader.GetString(); quadrilateralType = new Option<string?>(utf8JsonReader.GetString()!);
break; break;
default: default:
break; break;
@ -130,10 +130,13 @@ namespace UseSourceGeneration.Model
} }
} }
if (quadrilateralType == null) if (!quadrilateralType.IsSet)
throw new ArgumentNullException(nameof(quadrilateralType), "Property is required for class QuadrilateralInterface."); throw new ArgumentException("Property is required for class QuadrilateralInterface.", nameof(quadrilateralType));
return new QuadrilateralInterface(quadrilateralType); if (quadrilateralType.IsSet && quadrilateralType.Value == null)
throw new ArgumentNullException(nameof(quadrilateralType), "Property is not nullable for class QuadrilateralInterface.");
return new QuadrilateralInterface(quadrilateralType.Value!);
} }
/// <summary> /// <summary>
@ -160,6 +163,9 @@ namespace UseSourceGeneration.Model
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
public void WriteProperties(ref Utf8JsonWriter writer, QuadrilateralInterface quadrilateralInterface, JsonSerializerOptions jsonSerializerOptions) public void WriteProperties(ref Utf8JsonWriter writer, QuadrilateralInterface quadrilateralInterface, JsonSerializerOptions jsonSerializerOptions)
{ {
if (quadrilateralInterface.QuadrilateralType == null)
throw new ArgumentNullException(nameof(quadrilateralInterface.QuadrilateralType), "Property is required for class QuadrilateralInterface.");
writer.WriteString("quadrilateralType", quadrilateralInterface.QuadrilateralType); writer.WriteString("quadrilateralType", quadrilateralInterface.QuadrilateralType);
} }
} }

Some files were not shown because too many files have changed in this diff Show More