diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java index 36e64c9d6a2..e29848c187c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java @@ -669,7 +669,35 @@ public class OpenAPINormalizer { } /** - * If the schema is oneOf and the sub-schemas is null, set `nullable: true` instead. + * Check if the schema is of type 'null' + * + * Return true if the schema's type is 'null' or not specified + * + * @param schema Schema + */ + private boolean isNullTypeSchema(Schema schema) { + if (schema == null) { + return true; + } + + if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) { + return true; + } + + // convert referenced enum of null only to `nullable:true` + Schema referencedSchema = ModelUtils.getReferencedSchema(openAPI, schema); + if (referencedSchema.getEnum() != null && referencedSchema.getEnum().size() == 1) { + if ("null".equals(String.valueOf(referencedSchema.getEnum().get(0)))) { + return true; + } + } + + return false; + } + + /** + * If the schema is oneOf and the sub-schemas is null, set `nullable: true` + * instead. * If there's only one sub-schema, simply return the sub-schema directly. * * @param schema Schema @@ -680,35 +708,19 @@ public class OpenAPINormalizer { return schema; } - if (schema.getOneOf() != null && !schema.getOneOf().isEmpty()) { - for (int i = 0; i < schema.getOneOf().size(); i++) { - // convert null sub-schema to `nullable: true` - if (schema.getOneOf().get(i) == null || - (((Schema) schema.getOneOf().get(i)).getType() == null && - ((Schema) schema.getOneOf().get(i)).get$ref() == null)) { - schema.getOneOf().remove(i); - schema.setNullable(true); - continue; - } + List oneOfSchemas = schema.getOneOf(); + if (oneOfSchemas != null) { + if (oneOfSchemas.removeIf(oneOf -> isNullTypeSchema(oneOf))) { + schema.setNullable(true); - // convert enum of null only to `nullable:true` - Schema oneOfElement = ModelUtils.getReferencedSchema(openAPI, (Schema) schema.getOneOf().get(i)); - if (oneOfElement.getEnum() != null && oneOfElement.getEnum().size() == 1) { - if ("null".equals(String.valueOf(oneOfElement.getEnum().get(0)))) { - schema.setNullable(true); - schema.getOneOf().remove(i); - continue; + // if only one element left, simplify to just the element (schema) + if (oneOfSchemas.size() == 1) { + if (Boolean.TRUE.equals(schema.getNullable())) { // retain nullable setting + ((Schema) oneOfSchemas.get(0)).setNullable(true); } + return (Schema) oneOfSchemas.get(0); } } - - // if only one element left, simplify to just the element (schema) - if (schema.getOneOf().size() == 1) { - if (Boolean.TRUE.equals(schema.getNullable())) { // retain nullable setting - ((Schema) schema.getOneOf().get(0)).setNullable(true); - } - return (Schema) schema.getOneOf().get(0); - } } return schema; @@ -726,34 +738,18 @@ public class OpenAPINormalizer { return schema; } - if (schema.getAnyOf() != null && !schema.getAnyOf().isEmpty()) { - for (int i = 0; i < schema.getAnyOf().size(); i++) { - // convert null sub-schema to `nullable: true` - if (schema.getAnyOf().get(i) == null || - (((Schema) schema.getAnyOf().get(i)).getType() == null && - ((Schema) schema.getAnyOf().get(i)).get$ref() == null)) { - schema.getAnyOf().remove(i); - schema.setNullable(true); - continue; - } - - // convert enum of null only to `nullable:true` - Schema anyOfElement = ModelUtils.getReferencedSchema(openAPI, (Schema) schema.getAnyOf().get(i)); - if (anyOfElement.getEnum() != null && anyOfElement.getEnum().size() == 1) { - if ("null".equals(String.valueOf(anyOfElement.getEnum().get(0)))) { - schema.setNullable(true); - schema.getAnyOf().remove(i); - continue; - } - } + List anyOfSchemas = schema.getAnyOf(); + if (anyOfSchemas != null) { + if (anyOfSchemas.removeIf(anyOf -> isNullTypeSchema(anyOf))) { + schema.setNullable(true); } // if only one element left, simplify to just the element (schema) - if (schema.getAnyOf().size() == 1) { + if (anyOfSchemas.size() == 1) { if (Boolean.TRUE.equals(schema.getNullable())) { // retain nullable setting - ((Schema) schema.getAnyOf().get(0)).setNullable(true); + ((Schema) anyOfSchemas.get(0)).setNullable(true); } - return (Schema) schema.getAnyOf().get(0); + return (Schema) anyOfSchemas.get(0); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java index a51c30f2ce1..28f6abf540e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java @@ -141,11 +141,11 @@ public class OpenAPINormalizerTest { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/simplifyOneOfAnyOf_test.yaml"); Schema schema = openAPI.getComponents().getSchemas().get("AnyOfTest"); - assertEquals(schema.getAnyOf().size(), 2); + assertEquals(schema.getAnyOf().size(), 4); assertNull(schema.getNullable()); Schema schema2 = openAPI.getComponents().getSchemas().get("OneOfTest"); - assertEquals(schema2.getOneOf().size(), 2); + assertEquals(schema2.getOneOf().size(), 4); assertNull(schema2.getNullable()); Schema schema5 = openAPI.getComponents().getSchemas().get("OneOfNullableTest"); @@ -168,6 +168,7 @@ public class OpenAPINormalizerTest { Schema schema4 = openAPI.getComponents().getSchemas().get("OneOfTest"); assertNull(schema4.getOneOf()); assertTrue(schema4 instanceof IntegerSchema); + assertTrue(schema4.getNullable()); Schema schema6 = openAPI.getComponents().getSchemas().get("OneOfNullableTest"); assertEquals(schema6.getOneOf().size(), 2); @@ -273,7 +274,7 @@ public class OpenAPINormalizerTest { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/convertEnumNullToNullable_test.yaml"); Schema schema = openAPI.getComponents().getSchemas().get("AnyOfTest"); - assertEquals(schema.getAnyOf().size(), 3); + assertEquals(schema.getAnyOf().size(), 4); assertNull(schema.getNullable()); Map options = new HashMap<>(); @@ -292,7 +293,7 @@ public class OpenAPINormalizerTest { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/convertEnumNullToNullable_test.yaml"); Schema schema = openAPI.getComponents().getSchemas().get("AnyOfTest"); - assertEquals(schema.getAnyOf().size(), 3); + assertEquals(schema.getAnyOf().size(), 4); assertNull(schema.getNullable()); Map options = new HashMap<>(); @@ -313,7 +314,7 @@ public class OpenAPINormalizerTest { // before test Schema schema = openAPI.getComponents().getSchemas().get("AnyOfTest"); - assertEquals(schema.getAnyOf().size(), 3); + assertEquals(schema.getAnyOf().size(), 4); assertNull(schema.getNullable()); Map options = new HashMap<>(); @@ -323,7 +324,7 @@ public class OpenAPINormalizerTest { // checks should be the same after test Schema schema3 = openAPI.getComponents().getSchemas().get("AnyOfTest"); - assertEquals(schema3.getAnyOf().size(), 3); + assertEquals(schema3.getAnyOf().size(), 4); assertNull(schema3.getNullable()); } diff --git a/modules/openapi-generator/src/test/resources/3_0/convertEnumNullToNullable_test.yaml b/modules/openapi-generator/src/test/resources/3_0/convertEnumNullToNullable_test.yaml index ab97e13abbd..ad4bd77a6f3 100644 --- a/modules/openapi-generator/src/test/resources/3_0/convertEnumNullToNullable_test.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/convertEnumNullToNullable_test.yaml @@ -31,12 +31,17 @@ components: anyOf: - type: string - $ref: '#/components/schemas/EnumString' + - $ref: '#/components/schemas/EnumNullString' - $ref: '#/components/schemas/EnumNull' EnumString: type: string enum: - A - B + EnumNullString: + type: string + enum: + - 'null' EnumNull: type: string enum: diff --git a/modules/openapi-generator/src/test/resources/3_0/simplifyOneOfAnyOf_test.yaml b/modules/openapi-generator/src/test/resources/3_0/simplifyOneOfAnyOf_test.yaml index 7130fa9ba9a..9b3ae6acd61 100644 --- a/modules/openapi-generator/src/test/resources/3_0/simplifyOneOfAnyOf_test.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/simplifyOneOfAnyOf_test.yaml @@ -30,11 +30,15 @@ components: description: to test anyOf anyOf: - type: string + - type: 'null' - type: null + - $ref: null OneOfTest: description: to test oneOf oneOf: - type: integer + - type: 'null' + - type: null - $ref: null OneOfNullableTest: description: to test oneOf nullable diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/Drawing.cs index f52bb31aab2..48b90884333 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Model/Drawing.cs @@ -90,7 +90,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get{ return _ShapeOrNull;} diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/docs/models/Drawing.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/docs/models/Drawing.md index fcee9662afb..215793515f6 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/docs/models/Drawing.md +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/docs/models/Drawing.md @@ -5,9 +5,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **MainShape** | [**Shape**](Shape.md) | | [optional] -**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.md) | | [optional] **Shapes** | [**List<Shape>**](Shape.md) | | [optional] **NullableShape** | [**NullableShape**](NullableShape.md) | | [optional] +**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.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) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Model/Drawing.cs index 26ebf63a684..f21f1f207db 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Model/Drawing.cs @@ -34,16 +34,16 @@ namespace Org.OpenAPITools.Model /// Initializes a new instance of the class. /// /// mainShape - /// shapeOrNull /// shapes /// nullableShape + /// shapeOrNull [JsonConstructor] - public Drawing(Shape mainShape, ShapeOrNull shapeOrNull, List shapes, NullableShape? nullableShape = default) : base() + public Drawing(Shape mainShape, List shapes, NullableShape? nullableShape = default, ShapeOrNull? shapeOrNull = default) : base() { MainShape = mainShape; - ShapeOrNull = shapeOrNull; Shapes = shapes; NullableShape = nullableShape; + ShapeOrNull = shapeOrNull; OnCreated(); } @@ -55,12 +55,6 @@ namespace Org.OpenAPITools.Model [JsonPropertyName("mainShape")] public Shape MainShape { get; set; } - /// - /// Gets or Sets ShapeOrNull - /// - [JsonPropertyName("shapeOrNull")] - public ShapeOrNull ShapeOrNull { get; set; } - /// /// Gets or Sets Shapes /// @@ -73,6 +67,12 @@ namespace Org.OpenAPITools.Model [JsonPropertyName("nullableShape")] public NullableShape? NullableShape { get; set; } + /// + /// Gets or Sets ShapeOrNull + /// + [JsonPropertyName("shapeOrNull")] + public ShapeOrNull? ShapeOrNull { get; set; } + /// /// Returns the string presentation of the object /// @@ -83,9 +83,9 @@ namespace Org.OpenAPITools.Model sb.Append("class Drawing {\n"); sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); sb.Append(" MainShape: ").Append(MainShape).Append("\n"); - sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append(" Shapes: ").Append(Shapes).Append("\n"); sb.Append(" NullableShape: ").Append(NullableShape).Append("\n"); + sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append("}\n"); return sb.ToString(); } @@ -124,9 +124,9 @@ namespace Org.OpenAPITools.Model JsonTokenType startingTokenType = utf8JsonReader.TokenType; Shape? mainShape = default; - ShapeOrNull? shapeOrNull = default; List? shapes = default; NullableShape? nullableShape = default; + ShapeOrNull? shapeOrNull = default; while (utf8JsonReader.Read()) { @@ -147,10 +147,6 @@ namespace Org.OpenAPITools.Model if (utf8JsonReader.TokenType != JsonTokenType.Null) mainShape = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); break; - case "shapeOrNull": - if (utf8JsonReader.TokenType != JsonTokenType.Null) - shapeOrNull = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); - break; case "shapes": if (utf8JsonReader.TokenType != JsonTokenType.Null) shapes = JsonSerializer.Deserialize>(ref utf8JsonReader, jsonSerializerOptions); @@ -159,6 +155,10 @@ namespace Org.OpenAPITools.Model if (utf8JsonReader.TokenType != JsonTokenType.Null) nullableShape = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); break; + case "shapeOrNull": + if (utf8JsonReader.TokenType != JsonTokenType.Null) + shapeOrNull = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); + break; default: break; } @@ -168,13 +168,10 @@ namespace Org.OpenAPITools.Model if (mainShape == null) throw new ArgumentNullException(nameof(mainShape), "Property is required for class Drawing."); - if (shapeOrNull == null) - throw new ArgumentNullException(nameof(shapeOrNull), "Property is required for class Drawing."); - if (shapes == null) throw new ArgumentNullException(nameof(shapes), "Property is required for class Drawing."); - return new Drawing(mainShape, shapeOrNull, shapes, nullableShape); + return new Drawing(mainShape, shapes, nullableShape, shapeOrNull); } /// @@ -190,12 +187,12 @@ namespace Org.OpenAPITools.Model writer.WritePropertyName("mainShape"); JsonSerializer.Serialize(writer, drawing.MainShape, jsonSerializerOptions); - writer.WritePropertyName("shapeOrNull"); - JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); writer.WritePropertyName("shapes"); JsonSerializer.Serialize(writer, drawing.Shapes, jsonSerializerOptions); writer.WritePropertyName("nullableShape"); JsonSerializer.Serialize(writer, drawing.NullableShape, jsonSerializerOptions); + writer.WritePropertyName("shapeOrNull"); + JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); writer.WriteEndObject(); } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/docs/models/Drawing.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/docs/models/Drawing.md index fcee9662afb..215793515f6 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/docs/models/Drawing.md +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/docs/models/Drawing.md @@ -5,9 +5,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **MainShape** | [**Shape**](Shape.md) | | [optional] -**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.md) | | [optional] **Shapes** | [**List<Shape>**](Shape.md) | | [optional] **NullableShape** | [**NullableShape**](NullableShape.md) | | [optional] +**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.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) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/src/Org.OpenAPITools/Model/Drawing.cs index 32f83dd034b..c1d26496fc7 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0/src/Org.OpenAPITools/Model/Drawing.cs @@ -32,16 +32,16 @@ namespace Org.OpenAPITools.Model /// Initializes a new instance of the class. /// /// mainShape - /// shapeOrNull /// shapes /// nullableShape + /// shapeOrNull [JsonConstructor] - public Drawing(Shape mainShape, ShapeOrNull shapeOrNull, List shapes, NullableShape nullableShape = default) : base() + public Drawing(Shape mainShape, List shapes, NullableShape nullableShape = default, ShapeOrNull shapeOrNull = default) : base() { MainShape = mainShape; - ShapeOrNull = shapeOrNull; Shapes = shapes; NullableShape = nullableShape; + ShapeOrNull = shapeOrNull; OnCreated(); } @@ -53,12 +53,6 @@ namespace Org.OpenAPITools.Model [JsonPropertyName("mainShape")] public Shape MainShape { get; set; } - /// - /// Gets or Sets ShapeOrNull - /// - [JsonPropertyName("shapeOrNull")] - public ShapeOrNull ShapeOrNull { get; set; } - /// /// Gets or Sets Shapes /// @@ -71,6 +65,12 @@ namespace Org.OpenAPITools.Model [JsonPropertyName("nullableShape")] public NullableShape NullableShape { get; set; } + /// + /// Gets or Sets ShapeOrNull + /// + [JsonPropertyName("shapeOrNull")] + public ShapeOrNull ShapeOrNull { get; set; } + /// /// Returns the string presentation of the object /// @@ -81,9 +81,9 @@ namespace Org.OpenAPITools.Model sb.Append("class Drawing {\n"); sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); sb.Append(" MainShape: ").Append(MainShape).Append("\n"); - sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append(" Shapes: ").Append(Shapes).Append("\n"); sb.Append(" NullableShape: ").Append(NullableShape).Append("\n"); + sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append("}\n"); return sb.ToString(); } @@ -122,9 +122,9 @@ namespace Org.OpenAPITools.Model JsonTokenType startingTokenType = utf8JsonReader.TokenType; Shape mainShape = default; - ShapeOrNull shapeOrNull = default; List shapes = default; NullableShape nullableShape = default; + ShapeOrNull shapeOrNull = default; while (utf8JsonReader.Read()) { @@ -145,10 +145,6 @@ namespace Org.OpenAPITools.Model if (utf8JsonReader.TokenType != JsonTokenType.Null) mainShape = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); break; - case "shapeOrNull": - if (utf8JsonReader.TokenType != JsonTokenType.Null) - shapeOrNull = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); - break; case "shapes": if (utf8JsonReader.TokenType != JsonTokenType.Null) shapes = JsonSerializer.Deserialize>(ref utf8JsonReader, jsonSerializerOptions); @@ -157,6 +153,10 @@ namespace Org.OpenAPITools.Model if (utf8JsonReader.TokenType != JsonTokenType.Null) nullableShape = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); break; + case "shapeOrNull": + if (utf8JsonReader.TokenType != JsonTokenType.Null) + shapeOrNull = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); + break; default: break; } @@ -166,13 +166,10 @@ namespace Org.OpenAPITools.Model if (mainShape == null) throw new ArgumentNullException(nameof(mainShape), "Property is required for class Drawing."); - if (shapeOrNull == null) - throw new ArgumentNullException(nameof(shapeOrNull), "Property is required for class Drawing."); - if (shapes == null) throw new ArgumentNullException(nameof(shapes), "Property is required for class Drawing."); - return new Drawing(mainShape, shapeOrNull, shapes, nullableShape); + return new Drawing(mainShape, shapes, nullableShape, shapeOrNull); } /// @@ -188,12 +185,12 @@ namespace Org.OpenAPITools.Model writer.WritePropertyName("mainShape"); JsonSerializer.Serialize(writer, drawing.MainShape, jsonSerializerOptions); - writer.WritePropertyName("shapeOrNull"); - JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); writer.WritePropertyName("shapes"); JsonSerializer.Serialize(writer, drawing.Shapes, jsonSerializerOptions); writer.WritePropertyName("nullableShape"); JsonSerializer.Serialize(writer, drawing.NullableShape, jsonSerializerOptions); + writer.WritePropertyName("shapeOrNull"); + JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); writer.WriteEndObject(); } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/docs/models/Drawing.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/docs/models/Drawing.md index fcee9662afb..215793515f6 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/docs/models/Drawing.md +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/docs/models/Drawing.md @@ -5,9 +5,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **MainShape** | [**Shape**](Shape.md) | | [optional] -**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.md) | | [optional] **Shapes** | [**List<Shape>**](Shape.md) | | [optional] **NullableShape** | [**NullableShape**](NullableShape.md) | | [optional] +**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.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) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/src/Org.OpenAPITools/Model/Drawing.cs index 32f83dd034b..c1d26496fc7 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0/src/Org.OpenAPITools/Model/Drawing.cs @@ -32,16 +32,16 @@ namespace Org.OpenAPITools.Model /// Initializes a new instance of the class. /// /// mainShape - /// shapeOrNull /// shapes /// nullableShape + /// shapeOrNull [JsonConstructor] - public Drawing(Shape mainShape, ShapeOrNull shapeOrNull, List shapes, NullableShape nullableShape = default) : base() + public Drawing(Shape mainShape, List shapes, NullableShape nullableShape = default, ShapeOrNull shapeOrNull = default) : base() { MainShape = mainShape; - ShapeOrNull = shapeOrNull; Shapes = shapes; NullableShape = nullableShape; + ShapeOrNull = shapeOrNull; OnCreated(); } @@ -53,12 +53,6 @@ namespace Org.OpenAPITools.Model [JsonPropertyName("mainShape")] public Shape MainShape { get; set; } - /// - /// Gets or Sets ShapeOrNull - /// - [JsonPropertyName("shapeOrNull")] - public ShapeOrNull ShapeOrNull { get; set; } - /// /// Gets or Sets Shapes /// @@ -71,6 +65,12 @@ namespace Org.OpenAPITools.Model [JsonPropertyName("nullableShape")] public NullableShape NullableShape { get; set; } + /// + /// Gets or Sets ShapeOrNull + /// + [JsonPropertyName("shapeOrNull")] + public ShapeOrNull ShapeOrNull { get; set; } + /// /// Returns the string presentation of the object /// @@ -81,9 +81,9 @@ namespace Org.OpenAPITools.Model sb.Append("class Drawing {\n"); sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); sb.Append(" MainShape: ").Append(MainShape).Append("\n"); - sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append(" Shapes: ").Append(Shapes).Append("\n"); sb.Append(" NullableShape: ").Append(NullableShape).Append("\n"); + sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n"); sb.Append("}\n"); return sb.ToString(); } @@ -122,9 +122,9 @@ namespace Org.OpenAPITools.Model JsonTokenType startingTokenType = utf8JsonReader.TokenType; Shape mainShape = default; - ShapeOrNull shapeOrNull = default; List shapes = default; NullableShape nullableShape = default; + ShapeOrNull shapeOrNull = default; while (utf8JsonReader.Read()) { @@ -145,10 +145,6 @@ namespace Org.OpenAPITools.Model if (utf8JsonReader.TokenType != JsonTokenType.Null) mainShape = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); break; - case "shapeOrNull": - if (utf8JsonReader.TokenType != JsonTokenType.Null) - shapeOrNull = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); - break; case "shapes": if (utf8JsonReader.TokenType != JsonTokenType.Null) shapes = JsonSerializer.Deserialize>(ref utf8JsonReader, jsonSerializerOptions); @@ -157,6 +153,10 @@ namespace Org.OpenAPITools.Model if (utf8JsonReader.TokenType != JsonTokenType.Null) nullableShape = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); break; + case "shapeOrNull": + if (utf8JsonReader.TokenType != JsonTokenType.Null) + shapeOrNull = JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions); + break; default: break; } @@ -166,13 +166,10 @@ namespace Org.OpenAPITools.Model if (mainShape == null) throw new ArgumentNullException(nameof(mainShape), "Property is required for class Drawing."); - if (shapeOrNull == null) - throw new ArgumentNullException(nameof(shapeOrNull), "Property is required for class Drawing."); - if (shapes == null) throw new ArgumentNullException(nameof(shapes), "Property is required for class Drawing."); - return new Drawing(mainShape, shapeOrNull, shapes, nullableShape); + return new Drawing(mainShape, shapes, nullableShape, shapeOrNull); } /// @@ -188,12 +185,12 @@ namespace Org.OpenAPITools.Model writer.WritePropertyName("mainShape"); JsonSerializer.Serialize(writer, drawing.MainShape, jsonSerializerOptions); - writer.WritePropertyName("shapeOrNull"); - JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); writer.WritePropertyName("shapes"); JsonSerializer.Serialize(writer, drawing.Shapes, jsonSerializerOptions); writer.WritePropertyName("nullableShape"); JsonSerializer.Serialize(writer, drawing.NullableShape, jsonSerializerOptions); + writer.WritePropertyName("shapeOrNull"); + JsonSerializer.Serialize(writer, drawing.ShapeOrNull, jsonSerializerOptions); writer.WriteEndObject(); } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/Drawing.cs index ae441f94c69..47ce8968ddd 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Model/Drawing.cs @@ -57,7 +57,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/Drawing.cs index 0a759b37b3b..3663c769fc2 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net47/src/Org.OpenAPITools/Model/Drawing.cs @@ -56,7 +56,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/src/Org.OpenAPITools/Model/Drawing.cs index 0a759b37b3b..3663c769fc2 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net48/src/Org.OpenAPITools/Model/Drawing.cs @@ -56,7 +56,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/Drawing.cs index 0a759b37b3b..3663c769fc2 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0/src/Org.OpenAPITools/Model/Drawing.cs @@ -56,7 +56,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Drawing.cs index 7ceaa0ce3b1..0d19d8d09ed 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Drawing.cs @@ -54,7 +54,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClient/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Drawing.cs index 0a759b37b3b..3663c769fc2 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Model/Drawing.cs @@ -56,7 +56,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/api/openapi.yaml b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/api/openapi.yaml index 22e8da5234e..ba9171e6cbe 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/api/openapi.yaml +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/api/openapi.yaml @@ -1971,8 +1971,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2021,8 +2021,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/Drawing.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/Drawing.cs index 0a759b37b3b..3663c769fc2 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/Drawing.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Model/Drawing.cs @@ -56,7 +56,7 @@ namespace Org.OpenAPITools.Model /// /// Gets or Sets ShapeOrNull /// - [DataMember(Name = "shapeOrNull", EmitDefaultValue = false)] + [DataMember(Name = "shapeOrNull", EmitDefaultValue = true)] public ShapeOrNull ShapeOrNull { get; set; } /// diff --git a/samples/client/petstore/java/jersey3/api/openapi.yaml b/samples/client/petstore/java/jersey3/api/openapi.yaml index 3e2a497d7a8..b02c0b26cb7 100644 --- a/samples/client/petstore/java/jersey3/api/openapi.yaml +++ b/samples/client/petstore/java/jersey3/api/openapi.yaml @@ -1973,8 +1973,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2023,8 +2023,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Drawing.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Drawing.java index d9dd5f94e52..55534b1e127 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Drawing.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Drawing.java @@ -55,7 +55,7 @@ public class Drawing { private Shape mainShape; public static final String JSON_PROPERTY_SHAPE_OR_NULL = "shapeOrNull"; - private ShapeOrNull shapeOrNull; + private JsonNullable shapeOrNull = JsonNullable.undefined(); public static final String JSON_PROPERTY_NULLABLE_SHAPE = "nullableShape"; private JsonNullable nullableShape = JsonNullable.undefined(); @@ -92,7 +92,7 @@ public class Drawing { public Drawing shapeOrNull(ShapeOrNull shapeOrNull) { - this.shapeOrNull = shapeOrNull; + this.shapeOrNull = JsonNullable.of(shapeOrNull); return this; } @@ -101,20 +101,28 @@ public class Drawing { * @return shapeOrNull **/ @jakarta.annotation.Nullable - @JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @JsonIgnore public ShapeOrNull getShapeOrNull() { - return shapeOrNull; + return shapeOrNull.orElse(null); } - @JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setShapeOrNull(ShapeOrNull shapeOrNull) { + + public JsonNullable getShapeOrNull_JsonNullable() { + return shapeOrNull; + } + + @JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL) + public void setShapeOrNull_JsonNullable(JsonNullable shapeOrNull) { this.shapeOrNull = shapeOrNull; } + public void setShapeOrNull(ShapeOrNull shapeOrNull) { + this.shapeOrNull = JsonNullable.of(shapeOrNull); + } + public Drawing nullableShape(NullableShape nullableShape) { this.nullableShape = JsonNullable.of(nullableShape); @@ -232,7 +240,7 @@ public class Drawing { } Drawing drawing = (Drawing) o; return Objects.equals(this.mainShape, drawing.mainShape) && - Objects.equals(this.shapeOrNull, drawing.shapeOrNull) && + equalsNullable(this.shapeOrNull, drawing.shapeOrNull) && equalsNullable(this.nullableShape, drawing.nullableShape) && Objects.equals(this.shapes, drawing.shapes)&& Objects.equals(this.additionalProperties, drawing.additionalProperties); @@ -244,7 +252,7 @@ public class Drawing { @Override public int hashCode() { - return Objects.hash(mainShape, shapeOrNull, hashCodeNullable(nullableShape), shapes, additionalProperties); + return Objects.hash(mainShape, hashCodeNullable(shapeOrNull), hashCodeNullable(nullableShape), shapes, additionalProperties); } private static int hashCodeNullable(JsonNullable a) { diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index 954401cb158..a879895762c 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -1973,8 +1973,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2023,8 +2023,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/client/petstore/typescript-axios/builds/test-petstore/api.ts b/samples/client/petstore/typescript-axios/builds/test-petstore/api.ts index c0951271f3d..647afdc57dc 100644 --- a/samples/client/petstore/typescript-axios/builds/test-petstore/api.ts +++ b/samples/client/petstore/typescript-axios/builds/test-petstore/api.ts @@ -512,7 +512,7 @@ export interface Drawing { * @type {ShapeOrNull} * @memberof Drawing */ - 'shapeOrNull'?: ShapeOrNull; + 'shapeOrNull'?: ShapeOrNull | null; /** * * @type {NullableShape} @@ -846,7 +846,7 @@ export type Fruit = Apple | Banana; * @type FruitReq * @export */ -export type FruitReq = AppleReq | BananaReq | Null; +export type FruitReq = AppleReq | BananaReq; /** * @@ -1520,7 +1520,7 @@ export interface ShapeInterface { * The value may be a shape or the \'null\' value. This is introduced in OAS schema >= 3.1. * @export */ -export type ShapeOrNull = Null | Quadrilateral | Triangle; +export type ShapeOrNull = Quadrilateral | Triangle; /** * diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml b/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml index 3e2a497d7a8..b02c0b26cb7 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml +++ b/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml @@ -1973,8 +1973,8 @@ components: type: string fruitReq: additionalProperties: false + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: @@ -2023,8 +2023,8 @@ components: in OAS schema >= 3.1. discriminator: propertyName: shapeType + nullable: true oneOf: - - type: "null" - $ref: '#/components/schemas/Triangle' - $ref: '#/components/schemas/Quadrilateral' NullableShape: diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Drawing.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Drawing.java index ac0adc5d30f..aecf20e2fbb 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Drawing.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Drawing.java @@ -55,7 +55,7 @@ public class Drawing { private Shape mainShape; public static final String JSON_PROPERTY_SHAPE_OR_NULL = "shapeOrNull"; - private ShapeOrNull shapeOrNull; + private JsonNullable shapeOrNull = JsonNullable.undefined(); public static final String JSON_PROPERTY_NULLABLE_SHAPE = "nullableShape"; private JsonNullable nullableShape = JsonNullable.undefined(); @@ -92,7 +92,7 @@ public class Drawing { public Drawing shapeOrNull(ShapeOrNull shapeOrNull) { - this.shapeOrNull = shapeOrNull; + this.shapeOrNull = JsonNullable.of(shapeOrNull); return this; } @@ -101,20 +101,28 @@ public class Drawing { * @return shapeOrNull **/ @javax.annotation.Nullable - @JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @JsonIgnore public ShapeOrNull getShapeOrNull() { - return shapeOrNull; + return shapeOrNull.orElse(null); } - @JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setShapeOrNull(ShapeOrNull shapeOrNull) { + + public JsonNullable getShapeOrNull_JsonNullable() { + return shapeOrNull; + } + + @JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL) + public void setShapeOrNull_JsonNullable(JsonNullable shapeOrNull) { this.shapeOrNull = shapeOrNull; } + public void setShapeOrNull(ShapeOrNull shapeOrNull) { + this.shapeOrNull = JsonNullable.of(shapeOrNull); + } + public Drawing nullableShape(NullableShape nullableShape) { this.nullableShape = JsonNullable.of(nullableShape); @@ -232,7 +240,7 @@ public class Drawing { } Drawing drawing = (Drawing) o; return Objects.equals(this.mainShape, drawing.mainShape) && - Objects.equals(this.shapeOrNull, drawing.shapeOrNull) && + equalsNullable(this.shapeOrNull, drawing.shapeOrNull) && equalsNullable(this.nullableShape, drawing.nullableShape) && Objects.equals(this.shapes, drawing.shapes)&& Objects.equals(this.additionalProperties, drawing.additionalProperties); @@ -244,7 +252,7 @@ public class Drawing { @Override public int hashCode() { - return Objects.hash(mainShape, shapeOrNull, hashCodeNullable(nullableShape), shapes, additionalProperties); + return Objects.hash(mainShape, hashCodeNullable(shapeOrNull), hashCodeNullable(nullableShape), shapes, additionalProperties); } private static int hashCodeNullable(JsonNullable a) {