Skip to content

Commit

Permalink
fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
Anakael committed Dec 30, 2023
1 parent 8cb0da6 commit cb9e68e
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ protected boolean isValueType(CodegenProperty var) {

protected boolean useNet60OrLater() { return false; }

private boolean useDateOnly() {
protected boolean useDateOnly() {
return useNet60OrLater() && !useDateTimeForDateFlag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
protected boolean supportsAsync = Boolean.TRUE;
protected boolean netStandard = Boolean.FALSE;
protected boolean supportsFileParameters = Boolean.TRUE;
protected boolean supportsDateOnly = Boolean.FALSE;

protected boolean validatable = Boolean.TRUE;
protected boolean equatable = Boolean.FALSE;
Expand Down Expand Up @@ -791,6 +792,7 @@ public void processOpts() {
syncBooleanProperty(additionalProperties, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup, this.useOneOfDiscriminatorLookup);
syncBooleanProperty(additionalProperties, "supportsFileParameters", this::setSupportsFileParameters, this.supportsFileParameters);
syncBooleanProperty(additionalProperties, "useSourceGeneration", this::setUseSourceGeneration, this.useSourceGeneration);
syncBooleanProperty(additionalProperties, "supportsDateOnly", this::setSupportsDateOnly, this.supportsDateOnly);

final String testPackageName = testPackageName();
String packageFolder = sourceFolder + File.separator + packageName;
Expand Down Expand Up @@ -852,6 +854,10 @@ public void processOpts() {
}
}

if (useDateOnly()) {
setSupportsDateOnly(true);
additionalProperties.put("supportsDateOnly", true);
}
// include the spec in the output
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));

Expand Down Expand Up @@ -1101,6 +1107,10 @@ public void setSupportsFileParameters(Boolean supportsFileParameters) {
this.supportsFileParameters = supportsFileParameters;
}

public void setSupportsDateOnly(Boolean supportsDateOnly) {
this.supportsDateOnly = supportsDateOnly;
}

public void setSupportsRetry(Boolean supportsRetry) {
this.supportsRetry = supportsRetry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
{{/isNumeric}}
{{#isDate}}
if (utf8JsonReader.TokenType != JsonTokenType.Null)
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<{{#supportsDateOnly}}DateOnly{{/supportsDateOnly}}{{^supportsDateOnly}}DateTime{{/supportsDateOnly}}{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
{{/isDate}}
{{#isDateTime}}
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down Expand Up @@ -577,4 +577,4 @@
{{/lambda.trimLineBreaks}}
{{/lambda.trimTrailingWithNewLine}}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{#useSourceGeneration}}

/// <summary>
/// The {{classname}}SerializationContext
/// </summary>
[JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)]
[JsonSerializable(typeof({{classname}}))]
{{>visibility}} partial class {{classname}}SerializationContext : JsonSerializerContext { }
{{/useSourceGeneration}}
{{/useSourceGeneration}}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override DateOnlyClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
{
case "dateOnlyProperty":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateOnlyProperty = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
dateOnlyProperty = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public override void Write(Utf8JsonWriter writer, EnumClass? enumClass, JsonSeri
}
}


/// <summary>
/// The EnumClassSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
break;
case "date":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
date = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
date = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "number":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public override NullableClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
dateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "datetime_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public override void Write(Utf8JsonWriter writer, OuterEnum? outerEnum, JsonSeri
}
}


/// <summary>
/// The OuterEnumSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public override void Write(Utf8JsonWriter writer, OuterEnumDefaultValue? outerEn
}
}


/// <summary>
/// The OuterEnumDefaultValueSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public override void Write(Utf8JsonWriter writer, OuterEnumInteger? outerEnumInt
}
}


/// <summary>
/// The OuterEnumIntegerSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public override void Write(Utf8JsonWriter writer, OuterEnumIntegerDefaultValue?
}
}


/// <summary>
/// The OuterEnumIntegerDefaultValueSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ public override void Write(Utf8JsonWriter writer, OuterEnumTest? outerEnumTest,
}
}


/// <summary>
/// The OuterEnumTestSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ public override RequiredClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
{
case "required_not_nullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
requiredNotNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
requiredNotNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "required_notnullable_array_of_string":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down Expand Up @@ -1882,7 +1882,7 @@ public override RequiredClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "required_nullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
requiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
requiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "required_nullable_datetime_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down Expand Up @@ -1919,15 +1919,15 @@ public override RequiredClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "not_required_notnullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
notRequiredNotnullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
notRequiredNotnullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "not_required_notnullableinteger_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
notRequiredNotnullableintegerProp = new Option<int?>(utf8JsonReader.GetInt32());
break;
case "not_required_nullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
notRequiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
notRequiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "not_required_nullable_integer_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public override void Write(Utf8JsonWriter writer, ZeroBasedEnum? zeroBasedEnum,
}
}


/// <summary>
/// The ZeroBasedEnumSerializationContext
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override DateOnlyClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
{
case "dateOnlyProperty":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateOnlyProperty = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
dateOnlyProperty = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
break;
case "date":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
date = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
date = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "number":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public override NullableClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
dateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "datetime_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ public override RequiredClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
{
case "required_not_nullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
requiredNotNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
requiredNotNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "required_notnullable_array_of_string":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down Expand Up @@ -1881,7 +1881,7 @@ public override RequiredClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "required_nullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
requiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
requiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "required_nullable_datetime_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down Expand Up @@ -1918,15 +1918,15 @@ public override RequiredClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "not_required_notnullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
notRequiredNotnullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
notRequiredNotnullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "not_required_notnullableinteger_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
notRequiredNotnullableintegerProp = new Option<int?>(utf8JsonReader.GetInt32());
break;
case "not_required_nullable_date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
notRequiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
notRequiredNullableDateProp = new Option<DateOnly?>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "not_required_nullable_integer_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public override DateOnlyClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
{
case "dateOnlyProperty":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateOnlyProperty = new Option<DateOnly>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
dateOnlyProperty = new Option<DateOnly>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
break;
case "date":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
date = new Option<DateOnly>(JsonSerializer.Deserialize<DateTime>(ref utf8JsonReader, jsonSerializerOptions));
date = new Option<DateOnly>(JsonSerializer.Deserialize<DateOnly>(ref utf8JsonReader, jsonSerializerOptions));
break;
case "number":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public override NullableClass Read(ref Utf8JsonReader utf8JsonReader, Type typeT
break;
case "date_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
dateProp = new Option<DateOnly>(JsonSerializer.Deserialize<DateTime?>(ref utf8JsonReader, jsonSerializerOptions));
dateProp = new Option<DateOnly>(JsonSerializer.Deserialize<DateOnly?>(ref utf8JsonReader, jsonSerializerOptions));

Check failure on line 343 in samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0/src/Org.OpenAPITools/Model/NullableClass.cs

View workflow job for this annotation

GitHub Actions / Build .Net projects (samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0)

Argument 1: cannot convert from 'System.DateOnly?' to 'System.DateOnly'

Check failure on line 343 in samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0/src/Org.OpenAPITools/Model/NullableClass.cs

View workflow job for this annotation

GitHub Actions / Build .Net projects (samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0)

Argument 1: cannot convert from 'System.DateOnly?' to 'System.DateOnly'
break;
case "datetime_prop":
if (utf8JsonReader.TokenType != JsonTokenType.Null)
Expand Down
Loading

0 comments on commit cb9e68e

Please sign in to comment.