Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,18 @@
{{/allVars}}
{{#allVars}}
{{^isNullable}}
{{#required}}
if ({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.IsSet && {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.Value == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its required, I don't think it is an option, so the IsSet can go away. Curious that the samples could build.

throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}), "Property is not nullable for class {{classname}}.");

{{/required}}
{{^required}}
{{^nrt}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to use vendorExtensions.x-is-nullable-type which is true for any value type or if nrt is enabled. Also, should ^ be # instead?

if ({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.IsSet && {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}.Value == null)
throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}), "Property is not nullable for class {{classname}}.");

{{/nrt}}
{{/required}}
{{/isNullable}}
{{/allVars}}
{{^vendorExtensions.x-duplicated-data-type}}
Expand Down Expand Up @@ -430,9 +439,18 @@
{{^isDiscriminator}}
{{^isNullable}}
{{#vendorExtensions.x-is-reference-type}}
if ({{^required}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.IsSet && {{/required}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null)
{{#required}}
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null)
throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}), "Property is required for class {{classname}}.");

{{/required}}
{{^required}}
{{^nrt}}
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.IsSet && {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null)
throw new ArgumentNullException(nameof({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}), "Property is required for class {{classname}}.");

{{/nrt}}
{{/required}}
{{/vendorExtensions.x-is-reference-type}}
{{/isNullable}}
{{/isDiscriminator}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ else
writer.WriteNull("{{baseName}}");
{{/isNullable}}
{{^isNullable}}
{{^required}}
{{#nrt}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace nrt and x-is-value-type with vendorExtensions.x-is-nullable-type

{{#vendorExtensions.x-is-value-type}}
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value != null)
{{#lambda.paste}}{{/lambda.paste}}
else
writer.WriteNull("{{baseName}}");
{{/vendorExtensions.x-is-value-type}}
{{^vendorExtensions.x-is-value-type}}
{{#lambda.paste}}
{{/lambda.paste}}
{{/vendorExtensions.x-is-value-type}}
{{/nrt}}
{{^nrt}}
{{#lambda.paste}}
{{/lambda.paste}}
{{/nrt}}
{{/required}}
{{#required}}
{{#lambda.paste}}
{{/lambda.paste}}
{{/required}}
{{/isNullable}}
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public override HelloWorldPostRequest Read(ref Utf8JsonReader utf8JsonReader, Ty
}
}

if (message.IsSet && message.Value == null)
throw new ArgumentNullException(nameof(message), "Property is not nullable for class HelloWorldPostRequest.");

return new HelloWorldPostRequest(message);
}

Expand Down Expand Up @@ -158,9 +155,6 @@ public override void Write(Utf8JsonWriter writer, HelloWorldPostRequest helloWor
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, HelloWorldPostRequest helloWorldPostRequest, JsonSerializerOptions jsonSerializerOptions)
{
if (helloWorldPostRequest.MessageOption.IsSet && helloWorldPostRequest.Message == null)
throw new ArgumentNullException(nameof(helloWorldPostRequest.Message), "Property is required for class HelloWorldPostRequest.");

if (helloWorldPostRequest.MessageOption.IsSet)
writer.WriteString("message", helloWorldPostRequest.Message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public override Foo Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert,
}
}

if (bar.IsSet && bar.Value == null)
throw new ArgumentNullException(nameof(bar), "Property is not nullable for class Foo.");

return new Foo(bar);
}

Expand Down Expand Up @@ -158,9 +155,6 @@ public override void Write(Utf8JsonWriter writer, Foo foo, JsonSerializerOptions
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Foo foo, JsonSerializerOptions jsonSerializerOptions)
{
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public override IconsDefaultResponse Read(ref Utf8JsonReader utf8JsonReader, Typ
}
}

if (varString.IsSet && varString.Value == null)
throw new ArgumentNullException(nameof(varString), "Property is not nullable for class IconsDefaultResponse.");

return new IconsDefaultResponse(varString);
}

Expand Down Expand Up @@ -158,9 +155,6 @@ public override void Write(Utf8JsonWriter writer, IconsDefaultResponse iconsDefa
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, IconsDefaultResponse iconsDefaultResponse, JsonSerializerOptions jsonSerializerOptions)
{
if (iconsDefaultResponse.StringOption.IsSet && iconsDefaultResponse.String == null)
throw new ArgumentNullException(nameof(iconsDefaultResponse.String), "Property is required for class IconsDefaultResponse.");

if (iconsDefaultResponse.StringOption.IsSet)
{
writer.WritePropertyName("string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public override TestObject Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
}
}

if (name.IsSet && name.Value == null)
throw new ArgumentNullException(nameof(name), "Property is not nullable for class TestObject.");

return new TestObject(name);
}

Expand Down Expand Up @@ -158,9 +155,6 @@ public override void Write(Utf8JsonWriter writer, TestObject testObject, JsonSer
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, TestObject testObject, JsonSerializerOptions jsonSerializerOptions)
{
if (testObject.NameOption.IsSet && testObject.Name == null)
throw new ArgumentNullException(nameof(testObject.Name), "Property is required for class TestObject.");

if (testObject.NameOption.IsSet)
writer.WriteString("name", testObject.Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ public override Adult Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
}
}

if (children.IsSet && children.Value == null)
throw new ArgumentNullException(nameof(children), "Property is not nullable for class Adult.");

if (firstName.IsSet && firstName.Value == null)
throw new ArgumentNullException(nameof(firstName), "Property is not nullable for class Adult.");

if (lastName.IsSet && lastName.Value == null)
throw new ArgumentNullException(nameof(lastName), "Property is not nullable for class Adult.");

if (type.IsSet && type.Value == null)
throw new ArgumentNullException(nameof(type), "Property is not nullable for class Adult.");

return new Adult(children, firstName, lastName);
}

Expand Down Expand Up @@ -173,15 +161,6 @@ public override void Write(Utf8JsonWriter writer, Adult adult, JsonSerializerOpt
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Adult adult, JsonSerializerOptions jsonSerializerOptions)
{
if (adult.ChildrenOption.IsSet && adult.Children == null)
throw new ArgumentNullException(nameof(adult.Children), "Property is required for class Adult.");

if (adult.FirstNameOption.IsSet && adult.FirstName == null)
throw new ArgumentNullException(nameof(adult.FirstName), "Property is required for class Adult.");

if (adult.LastNameOption.IsSet && adult.LastName == null)
throw new ArgumentNullException(nameof(adult.LastName), "Property is required for class Adult.");

if (adult.ChildrenOption.IsSet)
{
writer.WritePropertyName("children");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,6 @@ public override Child Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
}
}

if (age.IsSet && age.Value == null)
throw new ArgumentNullException(nameof(age), "Property is not nullable for class Child.");

if (boosterSeat.IsSet && boosterSeat.Value == null)
throw new ArgumentNullException(nameof(boosterSeat), "Property is not nullable for class Child.");

if (firstName.IsSet && firstName.Value == null)
throw new ArgumentNullException(nameof(firstName), "Property is not nullable for class Child.");

if (lastName.IsSet && lastName.Value == null)
throw new ArgumentNullException(nameof(lastName), "Property is not nullable for class Child.");

if (type.IsSet && type.Value == null)
throw new ArgumentNullException(nameof(type), "Property is not nullable for class Child.");

return new Child(age, boosterSeat, firstName, lastName);
}

Expand Down Expand Up @@ -196,17 +181,17 @@ public override void Write(Utf8JsonWriter writer, Child child, JsonSerializerOpt
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Child child, JsonSerializerOptions jsonSerializerOptions)
{
if (child.FirstNameOption.IsSet && child.FirstName == null)
throw new ArgumentNullException(nameof(child.FirstName), "Property is required for class Child.");

if (child.LastNameOption.IsSet && child.LastName == null)
throw new ArgumentNullException(nameof(child.LastName), "Property is required for class Child.");

if (child.AgeOption.IsSet)
writer.WriteNumber("age", child.AgeOption.Value!.Value);
if (child.AgeOption.Value != null)
writer.WriteNumber("age", child.AgeOption.Value!.Value);
else
writer.WriteNull("age");

if (child.BoosterSeatOption.IsSet)
writer.WriteBoolean("boosterSeat", child.BoosterSeatOption.Value!.Value);
if (child.BoosterSeatOption.Value != null)
writer.WriteBoolean("boosterSeat", child.BoosterSeatOption.Value!.Value);
else
writer.WriteNull("boosterSeat");

if (child.FirstNameOption.IsSet)
writer.WriteString("firstName", child.FirstName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,6 @@ public override Person Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
}
}

if (firstName.IsSet && firstName.Value == null)
throw new ArgumentNullException(nameof(firstName), "Property is not nullable for class Person.");

if (lastName.IsSet && lastName.Value == null)
throw new ArgumentNullException(nameof(lastName), "Property is not nullable for class Person.");

if (type.IsSet && type.Value == null)
throw new ArgumentNullException(nameof(type), "Property is not nullable for class Person.");

return new Person(firstName, lastName);
}

Expand Down Expand Up @@ -232,12 +223,6 @@ public override void Write(Utf8JsonWriter writer, Person person, JsonSerializerO
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Person person, JsonSerializerOptions jsonSerializerOptions)
{
if (person.FirstNameOption.IsSet && person.FirstName == null)
throw new ArgumentNullException(nameof(person.FirstName), "Property is required for class Person.");

if (person.LastNameOption.IsSet && person.LastName == null)
throw new ArgumentNullException(nameof(person.LastName), "Property is required for class Person.");

if (person.FirstNameOption.IsSet)
writer.WriteString("firstName", person.FirstName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ public override Apple Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
}
}

if (kind.IsSet && kind.Value == null)
throw new ArgumentNullException(nameof(kind), "Property is not nullable for class Apple.");

return new Apple(kind);
}

Expand Down Expand Up @@ -166,9 +163,6 @@ public override void Write(Utf8JsonWriter writer, Apple apple, JsonSerializerOpt
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Apple apple, JsonSerializerOptions jsonSerializerOptions)
{
if (apple.KindOption.IsSet && apple.Kind == null)
throw new ArgumentNullException(nameof(apple.Kind), "Property is required for class Apple.");

if (apple.KindOption.IsSet)
writer.WriteString("kind", apple.Kind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ public override Banana Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
}
}

if (count.IsSet && count.Value == null)
throw new ArgumentNullException(nameof(count), "Property is not nullable for class Banana.");

return new Banana(count);
}

Expand Down Expand Up @@ -167,7 +164,10 @@ public override void Write(Utf8JsonWriter writer, Banana banana, JsonSerializerO
public void WriteProperties(Utf8JsonWriter writer, Banana banana, JsonSerializerOptions jsonSerializerOptions)
{
if (banana.CountOption.IsSet)
writer.WriteNumber("count", banana.CountOption.Value!.Value);
if (banana.CountOption.Value != null)
writer.WriteNumber("count", banana.CountOption.Value!.Value);
else
writer.WriteNull("count");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ public override Fruit Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
}
}

if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is not nullable for class Fruit.");

Option<Apple?> appleParsedValue = apple == null
? default
: new Option<Apple?>(apple);
Expand Down Expand Up @@ -234,9 +231,6 @@ public override void Write(Utf8JsonWriter writer, Fruit fruit, JsonSerializerOpt
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Fruit fruit, JsonSerializerOptions jsonSerializerOptions)
{
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ public override Apple Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
}
}

if (kind.IsSet && kind.Value == null)
throw new ArgumentNullException(nameof(kind), "Property is not nullable for class Apple.");

return new Apple(kind);
}

Expand Down Expand Up @@ -165,9 +162,6 @@ public override void Write(Utf8JsonWriter writer, Apple apple, JsonSerializerOpt
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Apple apple, JsonSerializerOptions jsonSerializerOptions)
{
if (apple.KindOption.IsSet && apple.Kind == null)
throw new ArgumentNullException(nameof(apple.Kind), "Property is required for class Apple.");

if (apple.KindOption.IsSet)
writer.WriteString("kind", apple.Kind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ public override Banana Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
}
}

if (count.IsSet && count.Value == null)
throw new ArgumentNullException(nameof(count), "Property is not nullable for class Banana.");

return new Banana(count);
}

Expand Down Expand Up @@ -166,7 +163,10 @@ public override void Write(Utf8JsonWriter writer, Banana banana, JsonSerializerO
public void WriteProperties(Utf8JsonWriter writer, Banana banana, JsonSerializerOptions jsonSerializerOptions)
{
if (banana.CountOption.IsSet)
writer.WriteNumber("count", banana.CountOption.Value!.Value);
if (banana.CountOption.Value != null)
writer.WriteNumber("count", banana.CountOption.Value!.Value);
else
writer.WriteNull("count");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ public override Fruit Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert
}
}

if (color.IsSet && color.Value == null)
throw new ArgumentNullException(nameof(color), "Property is not nullable for class Fruit.");

Option<Apple?> appleParsedValue = apple == null
? default
: new Option<Apple?>(apple);
Expand Down Expand Up @@ -233,9 +230,6 @@ public override void Write(Utf8JsonWriter writer, Fruit fruit, JsonSerializerOpt
/// <exception cref="NotImplementedException"></exception>
public void WriteProperties(Utf8JsonWriter writer, Fruit fruit, JsonSerializerOptions jsonSerializerOptions)
{
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);
}
Expand Down
Loading
Loading