diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 3f0fd0f3585f..79431c0d1f60 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -555,7 +555,7 @@ private boolean codegenPropertyIsNew(CodegenModel model, CodegenProperty propert ? false : model.parentModel.allVars.stream().anyMatch(p -> p.name.equals(property.name) && - (p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false || p.isDiscriminator)); + (p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false)); } /** diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java index 02043c013d9a..5de2517effb6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java @@ -720,6 +720,10 @@ private void patchPropertyVendorExtensions(CodegenProperty property) { property.vendorExtensions.put("x-is-value-type", isValueType); property.vendorExtensions.put("x-is-reference-type", !isValueType); property.vendorExtensions.put("x-is-nullable-type", this.getNullableReferencesTypes() || isValueType); + property.vendorExtensions.put("x-is-base-or-new-discriminator", (property.isDiscriminator && !property.isInherited) || (property.isDiscriminator && property.isNew)); + } + + protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) { } protected void patchProperty(Map enumRefs, CodegenModel model, CodegenProperty property) { @@ -735,6 +739,8 @@ protected void patchProperty(Map enumRefs, CodegenModel mo property.isPrimitiveType = true; } + this.patchPropertyIsInherited(model, property); + patchPropertyVendorExtensions(property); property.name = patchPropertyName(model, property.name); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java index 1fe2a272caf0..7dc618fe9f06 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java @@ -1590,6 +1590,18 @@ public String toInstantiationType(Schema schema) { } } + @Override + protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) { + if (GENERICHOST.equals(getLibrary())) { + // the isInherited property is not always correct + // fixing it here causes a breaking change in some generators + // only do this in generators that are prepared for the improvement + if (model.parentModel != null && model.parentModel.allVars.stream().anyMatch(v -> v.baseName.equals(property.baseName))) { + property.isInherited = true; + } + } + } + @Override protected void patchProperty(Map enumRefs, CodegenModel model, CodegenProperty property) { super.patchProperty(enumRefs, model, property); @@ -1598,10 +1610,6 @@ protected void patchProperty(Map enumRefs, CodegenModel mo if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) { property.vendorExtensions.put("x-csharp-value-type", true); } - } else { - if (model.parentModel != null && model.parentModel.allVars.stream().anyMatch(v -> v.baseName.equals(property.baseName))) { - property.isInherited = true; - } } } diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache index 1405dd77c79d..0ff2753e33a3 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache @@ -439,7 +439,7 @@ {{#isDiscriminator}} {{^model.composedSchemas.anyOf}} {{^model.composedSchemas.oneOf}} - writer.WriteString("{{baseName}}", {{^isEnum}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{/isEnum}}{{#isNew}}{{#isEnum}}{{#isInnerEnum}}{{classname}}.{{{datatypeWithEnum}}}ToJsonValue{{/isInnerEnum}}{{^isInnerEnum}}{{{datatypeWithEnum}}}ValueConverter.ToJsonValue{{/isInnerEnum}}({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}.Value{{/required}}){{/isEnum}}{{/isNew}}); + writer.WriteString("{{baseName}}", {{^isEnum}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{/isEnum}}{{#isEnum}}{{#isInnerEnum}}{{classname}}.{{{datatypeWithEnum}}}ToJsonValue{{/isInnerEnum}}{{^isInnerEnum}}{{{datatypeWithEnum}}}ValueConverter.ToJsonValue{{/isInnerEnum}}({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}.Value{{/required}}){{/isEnum}}); {{/model.composedSchemas.oneOf}} {{/model.composedSchemas.anyOf}} diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache index fe8e1e24d95c..04fb37138629 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache @@ -34,6 +34,13 @@ {{/isNew}} {{/isInherited}} {{/isDiscriminator}} + {{#vendorExtensions.x-is-base-or-new-discriminator}} + {{^model.composedSchemas.anyOf}} + {{^model.composedSchemas.oneOf}} + {{name}} = {{^isEnum}}this.GetType().Name{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), this.GetType().Name){{/isEnum}}; + {{/model.composedSchemas.oneOf}} + {{/model.composedSchemas.anyOf}} + {{/vendorExtensions.x-is-base-or-new-discriminator}} {{/allVars}} OnCreated(); } @@ -71,6 +78,13 @@ {{/isNew}} {{/isInherited}} {{/isDiscriminator}} + {{#vendorExtensions.x-is-base-or-new-discriminator}} + {{^model.composedSchemas.anyOf}} + {{^model.composedSchemas.oneOf}} + {{name}} = {{^isEnum}}this.GetType().Name{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), this.GetType().Name){{/isEnum}}; + {{/model.composedSchemas.oneOf}} + {{/model.composedSchemas.anyOf}} + {{/vendorExtensions.x-is-base-or-new-discriminator}} {{/allVars}} OnCreated(); } @@ -162,7 +176,7 @@ {{/vendorExtensions.x-duplicated-data-type}} {{/composedSchemas.oneOf}} {{#allVars}} - {{#isDiscriminator}} + {{#vendorExtensions.x-is-base-or-new-discriminator}} {{^model.composedSchemas.anyOf}} {{^model.composedSchemas.oneOf}} /// @@ -170,12 +184,12 @@ /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public {{#isNew}}new {{/isNew}}{{datatypeWithEnum}} {{name}} { get; } = {{^isNew}}"{{classname}}"{{/isNew}}{{#isNew}}{{^isEnum}}"{{classname}}"{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), "{{classname}}"){{/isEnum}}{{/isNew}}; + public {{#isNew}}new {{/isNew}}{{datatypeWithEnum}} {{name}} { get; } {{/model.composedSchemas.oneOf}} {{/model.composedSchemas.anyOf}} - {{/isDiscriminator}} - {{^isDiscriminator}} + {{/vendorExtensions.x-is-base-or-new-discriminator}} + {{^vendorExtensions.x-is-base-or-new-discriminator}} {{^isEnum}} {{#isInherited}} {{#isNew}} @@ -228,7 +242,7 @@ {{/isInherited}} {{/isEnum}} - {{/isDiscriminator}} + {{/vendorExtensions.x-is-base-or-new-discriminator}} {{/allVars}} {{#isAdditionalPropertiesTrue}} {{^parentModel}} diff --git a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 5b726d69b9f6..9f4c06265921 100644 --- a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -2836,6 +2836,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: "#/components/schemas/TestDescendants" + - required: + - "descendantName" + type: "object" + properties: + descendantName: + type: "string" + Descendant2: + allOf: + - $ref: "#/components/schemas/TestDescendants" + - required: + - "confidentiality" + type: "object" + properties: + confidentiality: + type: "string" + TestDescendants: + required: + - "alternativeName" + - "objectType" + type: "object" + properties: + alternativeName: + type: "string" + objectType: + type: "string" + enum: + - "Descendant1" + - "Descendant2" + description: "" + discriminator: + propertyName: "objectType" CopyActivity: type: object required: diff --git a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Adult.cs b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Adult.cs index 3cdde4b29d96..30d6ca1fc47a 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Adult.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Adult.cs @@ -57,13 +57,6 @@ public Adult(Option> children = default, Option firstName = [JsonPropertyName("children")] public List Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new Option>(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Adult"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Child.cs b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Child.cs index 7f96dcd8b664..8eaaa8256eec 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Child.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Child.cs @@ -59,13 +59,6 @@ public Child(Option age = default, Option firstName = default, Opt [JsonPropertyName("age")] public int? Age { get { return this.AgeOption; } set { this.AgeOption = new Option(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Child"; - /// /// Used to track the state of BoosterSeat /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Person.cs b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Person.cs index 6c9261c98790..b1c00a2eda29 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Person.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Person.cs @@ -39,6 +39,7 @@ public Person(Option firstName = default, Option lastName = defa { FirstNameOption = firstName; LastNameOption = lastName; + Type = this.GetType().Name; OnCreated(); } @@ -75,7 +76,7 @@ public Person(Option firstName = default, Option lastName = defa /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Type { get; } = "Person"; + public string Type { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES index 930f03400a84..198d17c0839d 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES @@ -34,6 +34,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -115,6 +117,8 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md +docs/models/TestDescendantsObjectType.md docs/models/TestEnumParametersEnumHeaderStringParameter.md docs/models/TestEnumParametersEnumQueryDoubleParameter.md docs/models/TestEnumParametersEnumQueryIntegerParameter.md @@ -192,6 +196,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -273,6 +279,8 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs +src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumHeaderStringParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml index 3c7d8aa3954b..7aabfeda5cf7 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml @@ -2592,6 +2592,37 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + $ref: '#/components/schemas/TestDescendants_objectType' + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' @@ -2957,6 +2988,11 @@ components: type: number - $ref: '#/components/schemas/MixedSubId' description: Mixed anyOf types for testing + TestDescendants_objectType: + enum: + - Descendant1 + - Descendant2 + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/Descendant1.md new file mode 100644 index 000000000000..4ae95cf42a0b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**DescendantName** | **string** | | + +[[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/generichost/net4.7/FormModels/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/Descendant2.md new file mode 100644 index 000000000000..02904f68e01f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**Confidentiality** | **string** | | + +[[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/generichost/net4.7/FormModels/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/TestDescendants.md new file mode 100644 index 000000000000..b78b685c49a8 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | + +[[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/generichost/net4.7/FormModels/docs/models/TestDescendantsObjectType.md b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/TestDescendantsObjectType.md new file mode 100644 index 000000000000..4be31d1e4bbd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/TestDescendantsObjectType.md @@ -0,0 +1,9 @@ +# Org.OpenAPITools.Model.TestDescendantsObjectType + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[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/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs new file mode 100644 index 000000000000..4e27423cd18e --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs @@ -0,0 +1,56 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendantsObjectType + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsObjectTypeTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendantsObjectType + //private TestDescendantsObjectType instance; + + public TestDescendantsObjectTypeTests() + { + // TODO uncomment below to create an instance of TestDescendantsObjectType + //instance = new TestDescendantsObjectType(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendantsObjectType + /// + [Fact] + public void TestDescendantsObjectTypeInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendantsObjectType + //Assert.IsType(instance); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs index 66af4c79a0e3..71ebdb6c953c 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -213,6 +213,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClassRequiredNullableEnumIntegerOnlyValueConverter.ToJsonValue(requiredClassRequiredNullableEnumIntegerOnly).ToString(); if (obj is RequiredClassRequiredNullableEnumString requiredClassRequiredNullableEnumString) return RequiredClassRequiredNullableEnumStringValueConverter.ToJsonValue(requiredClassRequiredNullableEnumString); + if (obj is TestDescendantsObjectType testDescendantsObjectType) + return TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendantsObjectType); if (obj is TestEnumParametersEnumHeaderStringParameter testEnumParametersEnumHeaderStringParameter) return TestEnumParametersEnumHeaderStringParameterValueConverter.ToJsonValue(testEnumParametersEnumHeaderStringParameter); if (obj is TestEnumParametersEnumQueryDoubleParameter testEnumParametersEnumQueryDoubleParameter) diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs index 08b8e0541417..88170afdf8ca 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -64,6 +64,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -166,6 +168,9 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumQueryDoubleParameterJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Animal.cs index 74cb14f52d91..f172cd70bc53 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Cat.cs index 0ffe1228015d..780c28a972a6 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs index 8d76e5b9a7ce..632caa963cf7 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs @@ -36,6 +36,7 @@ public partial class ChildCat : ParentPet, IValidatableObject [JsonConstructor] public ChildCat(Option name = default) : base() { + PetType = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), this.GetType().Name); NameOption = name; OnCreated(); } @@ -47,7 +48,7 @@ public ChildCat(Option name = default) : base() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new ChildCatAllOfPetType PetType { get; } = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), "ChildCat"); + public new ChildCatAllOfPetType PetType { get; } /// /// Used to track the state of Name diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..1ed4938d5fa7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..fd2ec581e4df --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Dog.cs index 605dc512434b..509278540c44 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..df5553038566 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,219 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (TestDescendantsObjectType)Enum.Parse(typeof(TestDescendantsObjectType), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public TestDescendantsObjectType ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs new file mode 100644 index 000000000000..32fdf9b1c3b7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs @@ -0,0 +1,174 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Defines TestDescendants_objectType + /// + public enum TestDescendantsObjectType + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Converts to and from the JSON value + /// + public static class TestDescendantsObjectTypeValueConverter + { + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType FromString(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + throw new NotImplementedException($"Could not convert value to type TestDescendantsObjectType: '{value}'"); + } + + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType? FromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ToJsonValue(TestDescendantsObjectType value) + { + if (value == TestDescendantsObjectType.Descendant1) + return "Descendant1"; + + if (value == TestDescendantsObjectType.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + } + + /// + /// A Json converter for type + /// + /// + public class TestDescendantsObjectTypeJsonConverter : JsonConverter + { + /// + /// Returns a from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the TestDescendantsObjectType to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType.ToString()); + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsObjectTypeNullableJsonConverter : JsonConverter + { + /// + /// Returns a TestDescendantsObjectType from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the DateTime to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType? testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType?.ToString() ?? "null"); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES index 1facc69aec6b..ec9d28bdd136 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -168,6 +171,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -234,6 +239,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net4.7/Petstore/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net4.7/Petstore/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs index 560c039d70a9..c3801c3dd6a9 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -227,6 +227,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs index dbbc08df7968..b5de98d60f10 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -62,6 +62,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -134,6 +136,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Animal.cs index 74cb14f52d91..f172cd70bc53 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Cat.cs index 0ffe1228015d..780c28a972a6 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs index 2eb5dd8dc35a..cce039237aea 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs @@ -37,6 +37,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -112,7 +113,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..78e8ee587c11 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..a9859338c4ba --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Dog.cs index 605dc512434b..509278540c44 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..36c7ef1ca217 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,285 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Adult.cs b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Adult.cs index 3cdde4b29d96..30d6ca1fc47a 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Adult.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Adult.cs @@ -57,13 +57,6 @@ public Adult(Option> children = default, Option firstName = [JsonPropertyName("children")] public List Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new Option>(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Adult"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Child.cs b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Child.cs index 7f96dcd8b664..8eaaa8256eec 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Child.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Child.cs @@ -59,13 +59,6 @@ public Child(Option age = default, Option firstName = default, Opt [JsonPropertyName("age")] public int? Age { get { return this.AgeOption; } set { this.AgeOption = new Option(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Child"; - /// /// Used to track the state of BoosterSeat /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Person.cs b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Person.cs index 6c9261c98790..b1c00a2eda29 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Person.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Model/Person.cs @@ -39,6 +39,7 @@ public Person(Option firstName = default, Option lastName = defa { FirstNameOption = firstName; LastNameOption = lastName; + Type = this.GetType().Name; OnCreated(); } @@ -75,7 +76,7 @@ public Person(Option firstName = default, Option lastName = defa /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Type { get; } = "Person"; + public string Type { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES index 930f03400a84..198d17c0839d 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES @@ -34,6 +34,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -115,6 +117,8 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md +docs/models/TestDescendantsObjectType.md docs/models/TestEnumParametersEnumHeaderStringParameter.md docs/models/TestEnumParametersEnumQueryDoubleParameter.md docs/models/TestEnumParametersEnumQueryIntegerParameter.md @@ -192,6 +196,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -273,6 +279,8 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs +src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumHeaderStringParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml index 3c7d8aa3954b..7aabfeda5cf7 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml @@ -2592,6 +2592,37 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + $ref: '#/components/schemas/TestDescendants_objectType' + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' @@ -2957,6 +2988,11 @@ components: type: number - $ref: '#/components/schemas/MixedSubId' description: Mixed anyOf types for testing + TestDescendants_objectType: + enum: + - Descendant1 + - Descendant2 + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/Descendant1.md new file mode 100644 index 000000000000..4ae95cf42a0b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**DescendantName** | **string** | | + +[[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/generichost/net4.8/FormModels/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/Descendant2.md new file mode 100644 index 000000000000..02904f68e01f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**Confidentiality** | **string** | | + +[[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/generichost/net4.8/FormModels/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/TestDescendants.md new file mode 100644 index 000000000000..b78b685c49a8 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | + +[[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/generichost/net4.8/FormModels/docs/models/TestDescendantsObjectType.md b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/TestDescendantsObjectType.md new file mode 100644 index 000000000000..4be31d1e4bbd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/models/TestDescendantsObjectType.md @@ -0,0 +1,9 @@ +# Org.OpenAPITools.Model.TestDescendantsObjectType + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[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/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs new file mode 100644 index 000000000000..4e27423cd18e --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs @@ -0,0 +1,56 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendantsObjectType + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsObjectTypeTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendantsObjectType + //private TestDescendantsObjectType instance; + + public TestDescendantsObjectTypeTests() + { + // TODO uncomment below to create an instance of TestDescendantsObjectType + //instance = new TestDescendantsObjectType(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendantsObjectType + /// + [Fact] + public void TestDescendantsObjectTypeInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendantsObjectType + //Assert.IsType(instance); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs index 66af4c79a0e3..71ebdb6c953c 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -213,6 +213,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClassRequiredNullableEnumIntegerOnlyValueConverter.ToJsonValue(requiredClassRequiredNullableEnumIntegerOnly).ToString(); if (obj is RequiredClassRequiredNullableEnumString requiredClassRequiredNullableEnumString) return RequiredClassRequiredNullableEnumStringValueConverter.ToJsonValue(requiredClassRequiredNullableEnumString); + if (obj is TestDescendantsObjectType testDescendantsObjectType) + return TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendantsObjectType); if (obj is TestEnumParametersEnumHeaderStringParameter testEnumParametersEnumHeaderStringParameter) return TestEnumParametersEnumHeaderStringParameterValueConverter.ToJsonValue(testEnumParametersEnumHeaderStringParameter); if (obj is TestEnumParametersEnumQueryDoubleParameter testEnumParametersEnumQueryDoubleParameter) diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs index 08b8e0541417..88170afdf8ca 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -64,6 +64,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -166,6 +168,9 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumQueryDoubleParameterJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Animal.cs index 74cb14f52d91..f172cd70bc53 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Cat.cs index 0ffe1228015d..780c28a972a6 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs index 8d76e5b9a7ce..632caa963cf7 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs @@ -36,6 +36,7 @@ public partial class ChildCat : ParentPet, IValidatableObject [JsonConstructor] public ChildCat(Option name = default) : base() { + PetType = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), this.GetType().Name); NameOption = name; OnCreated(); } @@ -47,7 +48,7 @@ public ChildCat(Option name = default) : base() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new ChildCatAllOfPetType PetType { get; } = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), "ChildCat"); + public new ChildCatAllOfPetType PetType { get; } /// /// Used to track the state of Name diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..1ed4938d5fa7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..fd2ec581e4df --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Dog.cs index 605dc512434b..509278540c44 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..df5553038566 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,219 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (TestDescendantsObjectType)Enum.Parse(typeof(TestDescendantsObjectType), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public TestDescendantsObjectType ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs new file mode 100644 index 000000000000..32fdf9b1c3b7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs @@ -0,0 +1,174 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Defines TestDescendants_objectType + /// + public enum TestDescendantsObjectType + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Converts to and from the JSON value + /// + public static class TestDescendantsObjectTypeValueConverter + { + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType FromString(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + throw new NotImplementedException($"Could not convert value to type TestDescendantsObjectType: '{value}'"); + } + + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType? FromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ToJsonValue(TestDescendantsObjectType value) + { + if (value == TestDescendantsObjectType.Descendant1) + return "Descendant1"; + + if (value == TestDescendantsObjectType.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + } + + /// + /// A Json converter for type + /// + /// + public class TestDescendantsObjectTypeJsonConverter : JsonConverter + { + /// + /// Returns a from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the TestDescendantsObjectType to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType.ToString()); + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsObjectTypeNullableJsonConverter : JsonConverter + { + /// + /// Returns a TestDescendantsObjectType from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the DateTime to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType? testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType?.ToString() ?? "null"); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES index 1facc69aec6b..ec9d28bdd136 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -168,6 +171,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -234,6 +239,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net4.8/Petstore/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net4.8/Petstore/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs index 560c039d70a9..c3801c3dd6a9 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -227,6 +227,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs index dbbc08df7968..b5de98d60f10 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -62,6 +62,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -134,6 +136,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Animal.cs index 74cb14f52d91..f172cd70bc53 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Cat.cs index 0ffe1228015d..780c28a972a6 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs index 2eb5dd8dc35a..cce039237aea 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs @@ -37,6 +37,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -112,7 +113,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..78e8ee587c11 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..a9859338c4ba --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Dog.cs index 605dc512434b..509278540c44 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..36c7ef1ca217 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,285 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Adult.cs b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Adult.cs index 061761d954f3..88a0bc9e8ae8 100644 --- a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Adult.cs +++ b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Adult.cs @@ -59,13 +59,6 @@ public Adult(Option?> children = default, Option firstName [JsonPropertyName("children")] public List? Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Adult"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Child.cs b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Child.cs index 94bb37a7732d..b174729f4700 100644 --- a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Child.cs +++ b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Child.cs @@ -61,13 +61,6 @@ public Child(Option age = default, Option firstName = default, Op [JsonPropertyName("age")] public int? Age { get { return this.AgeOption; } set { this.AgeOption = new(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Child"; - /// /// Used to track the state of BoosterSeat /// diff --git a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Person.cs b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Person.cs index d3f9d198830e..6da989d4e3a7 100644 --- a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Person.cs +++ b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Model/Person.cs @@ -41,6 +41,7 @@ public Person(Option firstName = default, Option lastName = de { FirstNameOption = firstName; LastNameOption = lastName; + Type = this.GetType().Name; OnCreated(); } @@ -77,7 +78,7 @@ public Person(Option firstName = default, Option lastName = de /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Type { get; } = "Person"; + public string Type { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES index 77738c830b41..98b0f52f2157 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES @@ -34,6 +34,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -115,6 +117,8 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md +docs/models/TestDescendantsObjectType.md docs/models/TestEnumParametersEnumHeaderStringParameter.md docs/models/TestEnumParametersEnumQueryDoubleParameter.md docs/models/TestEnumParametersEnumQueryIntegerParameter.md @@ -194,6 +198,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -275,6 +281,8 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs +src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumHeaderStringParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml index 3c7d8aa3954b..7aabfeda5cf7 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml @@ -2592,6 +2592,37 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + $ref: '#/components/schemas/TestDescendants_objectType' + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' @@ -2957,6 +2988,11 @@ components: type: number - $ref: '#/components/schemas/MixedSubId' description: Mixed anyOf types for testing + TestDescendants_objectType: + enum: + - Descendant1 + - Descendant2 + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/Descendant1.md new file mode 100644 index 000000000000..4ae95cf42a0b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**DescendantName** | **string** | | + +[[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/generichost/net8/FormModels/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/Descendant2.md new file mode 100644 index 000000000000..02904f68e01f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**Confidentiality** | **string** | | + +[[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/generichost/net8/FormModels/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/TestDescendants.md new file mode 100644 index 000000000000..b78b685c49a8 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | + +[[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/generichost/net8/FormModels/docs/models/TestDescendantsObjectType.md b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/TestDescendantsObjectType.md new file mode 100644 index 000000000000..4be31d1e4bbd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/TestDescendantsObjectType.md @@ -0,0 +1,9 @@ +# Org.OpenAPITools.Model.TestDescendantsObjectType + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[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/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs new file mode 100644 index 000000000000..4e27423cd18e --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs @@ -0,0 +1,56 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendantsObjectType + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsObjectTypeTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendantsObjectType + //private TestDescendantsObjectType instance; + + public TestDescendantsObjectTypeTests() + { + // TODO uncomment below to create an instance of TestDescendantsObjectType + //instance = new TestDescendantsObjectType(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendantsObjectType + /// + [Fact] + public void TestDescendantsObjectTypeInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendantsObjectType + //Assert.IsType(instance); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs index 025b10ff3f0a..d29acc6c3328 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -212,6 +212,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClassRequiredNullableEnumIntegerOnlyValueConverter.ToJsonValue(requiredClassRequiredNullableEnumIntegerOnly).ToString(); if (obj is RequiredClassRequiredNullableEnumString requiredClassRequiredNullableEnumString) return RequiredClassRequiredNullableEnumStringValueConverter.ToJsonValue(requiredClassRequiredNullableEnumString); + if (obj is TestDescendantsObjectType testDescendantsObjectType) + return TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendantsObjectType); if (obj is TestEnumParametersEnumHeaderStringParameter testEnumParametersEnumHeaderStringParameter) return TestEnumParametersEnumHeaderStringParameterValueConverter.ToJsonValue(testEnumParametersEnumHeaderStringParameter); if (obj is TestEnumParametersEnumQueryDoubleParameter testEnumParametersEnumQueryDoubleParameter) diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs index 80118c6a1ec4..e00a281b33bd 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -66,6 +66,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -168,6 +170,9 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumQueryDoubleParameterJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Animal.cs index d0b07da62cc8..5a0b22326df1 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Cat.cs index 6a1dfe1d90b6..f424f8ef9d85 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs index d920c4ded985..99c5b315aa00 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs @@ -36,6 +36,7 @@ public partial class ChildCat : ParentPet, IValidatableObject [JsonConstructor] public ChildCat(Option name = default) : base() { + PetType = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), this.GetType().Name); NameOption = name; OnCreated(); } @@ -47,7 +48,7 @@ public ChildCat(Option name = default) : base() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new ChildCatAllOfPetType PetType { get; } = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), "ChildCat"); + public new ChildCatAllOfPetType PetType { get; } /// /// Used to track the state of Name diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..1ed4938d5fa7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..fd2ec581e4df --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Dog.cs index 2ab1ca19d2d0..a4879a78dc05 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..df5553038566 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,219 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (TestDescendantsObjectType)Enum.Parse(typeof(TestDescendantsObjectType), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public TestDescendantsObjectType ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs new file mode 100644 index 000000000000..32fdf9b1c3b7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs @@ -0,0 +1,174 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Defines TestDescendants_objectType + /// + public enum TestDescendantsObjectType + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Converts to and from the JSON value + /// + public static class TestDescendantsObjectTypeValueConverter + { + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType FromString(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + throw new NotImplementedException($"Could not convert value to type TestDescendantsObjectType: '{value}'"); + } + + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType? FromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ToJsonValue(TestDescendantsObjectType value) + { + if (value == TestDescendantsObjectType.Descendant1) + return "Descendant1"; + + if (value == TestDescendantsObjectType.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + } + + /// + /// A Json converter for type + /// + /// + public class TestDescendantsObjectTypeJsonConverter : JsonConverter + { + /// + /// Returns a from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the TestDescendantsObjectType to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType.ToString()); + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsObjectTypeNullableJsonConverter : JsonConverter + { + /// + /// Returns a TestDescendantsObjectType from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the DateTime to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType? testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType?.ToString() ?? "null"); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES index a24733a7c11a..b6cb61731e5e 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -170,6 +173,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -236,6 +241,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net8/NullReferenceTypes/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net8/NullReferenceTypes/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs index caef12016777..aec08983d426 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -228,6 +228,8 @@ public static string SanitizeFilename(string filename) return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs index 1557552a7687..71fc722f02ff 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -66,6 +66,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -138,6 +140,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs index 648b8fde8871..1e87e6de2950 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs @@ -38,6 +38,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -49,7 +50,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs index f6a4492730f4..0a879915fc74 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs @@ -45,13 +45,6 @@ public Cat(Option color = default, Option declawed = default) : partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs index 35e299d05c18..c37ba2ec211e 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs @@ -39,6 +39,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -114,7 +115,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs index 6acd040dc2e8..d2cbf27feffc 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -38,6 +38,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -101,7 +102,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..d86b93b3ff02 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,185 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value!, descendantName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..152103158d0a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,185 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value!, confidentiality.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs index f09923475b0d..05eb0781cfe7 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs @@ -45,13 +45,6 @@ public Dog(Option breed = default, Option color = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs index fa8a54d9dd01..17b8f812e777 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs @@ -37,6 +37,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -47,7 +48,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index 4cefd4ca6216..e8f6e0889167 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -37,6 +37,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -47,7 +48,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs index a4b1ab4347d6..9f659ee86ae8 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs @@ -42,13 +42,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..f1a80055f735 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,287 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string? discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES index a24733a7c11a..b6cb61731e5e 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -170,6 +173,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -236,6 +241,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net8/Petstore/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net8/Petstore/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs index 0dfe6afc4b13..d6f05a813b15 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -226,6 +226,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs index 47783040097a..58a420f8836c 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -64,6 +64,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -136,6 +138,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Animal.cs index d0b07da62cc8..5a0b22326df1 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Cat.cs index 6a1dfe1d90b6..f424f8ef9d85 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs index 87a49cbe08f0..ff5df164f2c9 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs @@ -37,6 +37,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -112,7 +113,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..78e8ee587c11 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..a9859338c4ba --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Dog.cs index 2ab1ca19d2d0..a4879a78dc05 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..36c7ef1ca217 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,285 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES index a24733a7c11a..b6cb61731e5e 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -170,6 +173,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -236,6 +241,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net8/SourceGeneration/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net8/SourceGeneration/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs index caef12016777..aec08983d426 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -228,6 +228,8 @@ public static string SanitizeFilename(string filename) return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs index 9914ab629e3f..08eb7fbb07e8 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -66,6 +66,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -138,6 +140,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); @@ -174,6 +177,8 @@ public HostConfiguration(IServiceCollection services) new DanishPigSerializationContext(), new DateOnlyClassSerializationContext(), new DeprecatedObjectSerializationContext(), + new Descendant1SerializationContext(), + new Descendant2SerializationContext(), new DogSerializationContext(), new DrawingSerializationContext(), new EntityBaseSerializationContext(), @@ -240,6 +245,7 @@ public HostConfiguration(IServiceCollection services) new TagSerializationContext(), new TestCollectionEndingWithWordListSerializationContext(), new TestCollectionEndingWithWordListObjectSerializationContext(), + new TestDescendantsSerializationContext(), new TestInlineFreeformAdditionalPropertiesRequestSerializationContext(), new TriangleSerializationContext(), new TriangleInterfaceSerializationContext(), diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs index 7c54e55cb7b5..37a0519bbd6b 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs @@ -39,6 +39,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -50,7 +51,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs index 352bba5d51e4..33e8935a249e 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs @@ -46,13 +46,6 @@ public Cat(Option color = default, Option declawed = default) : partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs index 2b39e8e86f0c..4131c59373af 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs @@ -40,6 +40,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -115,7 +116,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs index 3fd719564b91..a4a704b58170 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -39,6 +39,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -102,7 +103,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..9af51efffe3c --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,193 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using System.Text.Json.Serialization.Metadata; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value!, descendantName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } + + /// + /// The Descendant1SerializationContext + /// + [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)] + [JsonSerializable(typeof(Descendant1))] + public partial class Descendant1SerializationContext : JsonSerializerContext { } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..5e39d2322847 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,193 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using System.Text.Json.Serialization.Metadata; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value!, confidentiality.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } + + /// + /// The Descendant2SerializationContext + /// + [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)] + [JsonSerializable(typeof(Descendant2))] + public partial class Descendant2SerializationContext : JsonSerializerContext { } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs index 4de2c40c0183..6129b69ce916 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs @@ -46,13 +46,6 @@ public Dog(Option breed = default, Option color = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs index c8e883631368..093b2012f441 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs @@ -38,6 +38,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -48,7 +49,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index 69049f30a58f..2a787a59db6d 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -38,6 +38,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -48,7 +49,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs index 6218c3add483..b7c98ce645cb 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs @@ -43,13 +43,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..538b8c90d98f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,295 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using System.Text.Json.Serialization.Metadata; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string? discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } + + /// + /// The TestDescendantsSerializationContext + /// + [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)] + [JsonSerializable(typeof(TestDescendants))] + public partial class TestDescendantsSerializationContext : JsonSerializerContext { } +} diff --git a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Adult.cs b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Adult.cs index 061761d954f3..88a0bc9e8ae8 100644 --- a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Adult.cs +++ b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Adult.cs @@ -59,13 +59,6 @@ public Adult(Option?> children = default, Option firstName [JsonPropertyName("children")] public List? Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Adult"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Child.cs b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Child.cs index 94bb37a7732d..b174729f4700 100644 --- a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Child.cs +++ b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Child.cs @@ -61,13 +61,6 @@ public Child(Option age = default, Option firstName = default, Op [JsonPropertyName("age")] public int? Age { get { return this.AgeOption; } set { this.AgeOption = new(value); } } - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string Type { get; } = "Child"; - /// /// Used to track the state of BoosterSeat /// diff --git a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Person.cs b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Person.cs index d3f9d198830e..6da989d4e3a7 100644 --- a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Person.cs +++ b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Model/Person.cs @@ -41,6 +41,7 @@ public Person(Option firstName = default, Option lastName = de { FirstNameOption = firstName; LastNameOption = lastName; + Type = this.GetType().Name; OnCreated(); } @@ -77,7 +78,7 @@ public Person(Option firstName = default, Option lastName = de /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Type { get; } = "Person"; + public string Type { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES index 77738c830b41..98b0f52f2157 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES @@ -34,6 +34,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -115,6 +117,8 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md +docs/models/TestDescendantsObjectType.md docs/models/TestEnumParametersEnumHeaderStringParameter.md docs/models/TestEnumParametersEnumQueryDoubleParameter.md docs/models/TestEnumParametersEnumQueryIntegerParameter.md @@ -194,6 +198,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -275,6 +281,8 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs +src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumHeaderStringParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml index 3c7d8aa3954b..7aabfeda5cf7 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml @@ -2592,6 +2592,37 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + $ref: '#/components/schemas/TestDescendants_objectType' + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' @@ -2957,6 +2988,11 @@ components: type: number - $ref: '#/components/schemas/MixedSubId' description: Mixed anyOf types for testing + TestDescendants_objectType: + enum: + - Descendant1 + - Descendant2 + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/Descendant1.md new file mode 100644 index 000000000000..4ae95cf42a0b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**DescendantName** | **string** | | + +[[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/generichost/net9/FormModels/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/Descendant2.md new file mode 100644 index 000000000000..02904f68e01f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | +**Confidentiality** | **string** | | + +[[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/generichost/net9/FormModels/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/TestDescendants.md new file mode 100644 index 000000000000..b78b685c49a8 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **TestDescendantsObjectType** | | + +[[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/generichost/net9/FormModels/docs/models/TestDescendantsObjectType.md b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/TestDescendantsObjectType.md new file mode 100644 index 000000000000..4be31d1e4bbd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/models/TestDescendantsObjectType.md @@ -0,0 +1,9 @@ +# Org.OpenAPITools.Model.TestDescendantsObjectType + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[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/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs new file mode 100644 index 000000000000..4e27423cd18e --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsObjectTypeTests.cs @@ -0,0 +1,56 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendantsObjectType + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsObjectTypeTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendantsObjectType + //private TestDescendantsObjectType instance; + + public TestDescendantsObjectTypeTests() + { + // TODO uncomment below to create an instance of TestDescendantsObjectType + //instance = new TestDescendantsObjectType(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendantsObjectType + /// + [Fact] + public void TestDescendantsObjectTypeInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendantsObjectType + //Assert.IsType(instance); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs index 025b10ff3f0a..d29acc6c3328 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -212,6 +212,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClassRequiredNullableEnumIntegerOnlyValueConverter.ToJsonValue(requiredClassRequiredNullableEnumIntegerOnly).ToString(); if (obj is RequiredClassRequiredNullableEnumString requiredClassRequiredNullableEnumString) return RequiredClassRequiredNullableEnumStringValueConverter.ToJsonValue(requiredClassRequiredNullableEnumString); + if (obj is TestDescendantsObjectType testDescendantsObjectType) + return TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendantsObjectType); if (obj is TestEnumParametersEnumHeaderStringParameter testEnumParametersEnumHeaderStringParameter) return TestEnumParametersEnumHeaderStringParameterValueConverter.ToJsonValue(testEnumParametersEnumHeaderStringParameter); if (obj is TestEnumParametersEnumQueryDoubleParameter testEnumParametersEnumQueryDoubleParameter) diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs index 80118c6a1ec4..e00a281b33bd 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -66,6 +66,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -168,6 +170,9 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsObjectTypeNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumHeaderStringParameterNullableJsonConverter()); _jsonOptions.Converters.Add(new TestEnumParametersEnumQueryDoubleParameterJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Animal.cs index d0b07da62cc8..5a0b22326df1 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Cat.cs index 6a1dfe1d90b6..f424f8ef9d85 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs index d920c4ded985..99c5b315aa00 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ChildCat.cs @@ -36,6 +36,7 @@ public partial class ChildCat : ParentPet, IValidatableObject [JsonConstructor] public ChildCat(Option name = default) : base() { + PetType = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), this.GetType().Name); NameOption = name; OnCreated(); } @@ -47,7 +48,7 @@ public ChildCat(Option name = default) : base() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new ChildCatAllOfPetType PetType { get; } = (ChildCatAllOfPetType)Enum.Parse(typeof(ChildCatAllOfPetType), "ChildCat"); + public new ChildCatAllOfPetType PetType { get; } /// /// Used to track the state of Name diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..1ed4938d5fa7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..fd2ec581e4df --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Dog.cs index 2ab1ca19d2d0..a4879a78dc05 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..df5553038566 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,219 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (TestDescendantsObjectType)Enum.Parse(typeof(TestDescendantsObjectType), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public TestDescendantsObjectType ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendantsObjectTypeValueConverter.FromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendantsObjectTypeValueConverter.ToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs new file mode 100644 index 000000000000..32fdf9b1c3b7 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs @@ -0,0 +1,174 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Defines TestDescendants_objectType + /// + public enum TestDescendantsObjectType + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Converts to and from the JSON value + /// + public static class TestDescendantsObjectTypeValueConverter + { + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType FromString(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + throw new NotImplementedException($"Could not convert value to type TestDescendantsObjectType: '{value}'"); + } + + /// + /// Parses a given value to + /// + /// + /// + public static TestDescendantsObjectType? FromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return TestDescendantsObjectType.Descendant1; + + if (value.Equals("Descendant2")) + return TestDescendantsObjectType.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ToJsonValue(TestDescendantsObjectType value) + { + if (value == TestDescendantsObjectType.Descendant1) + return "Descendant1"; + + if (value == TestDescendantsObjectType.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + } + + /// + /// A Json converter for type + /// + /// + public class TestDescendantsObjectTypeJsonConverter : JsonConverter + { + /// + /// Returns a from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the TestDescendantsObjectType to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType.ToString()); + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsObjectTypeNullableJsonConverter : JsonConverter + { + /// + /// Returns a TestDescendantsObjectType from the Json object + /// + /// + /// + /// + /// + public override TestDescendantsObjectType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + string rawValue = reader.GetString(); + + TestDescendantsObjectType? result = rawValue == null + ? null + : TestDescendantsObjectTypeValueConverter.FromStringOrDefault(rawValue); + + if (result != null) + return result.Value; + + throw new JsonException(); + } + + /// + /// Writes the DateTime to the json writer + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendantsObjectType? testDescendantsObjectType, JsonSerializerOptions options) + { + writer.WriteStringValue(testDescendantsObjectType?.ToString() ?? "null"); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES index a24733a7c11a..b6cb61731e5e 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -170,6 +173,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -236,6 +241,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net9/NullReferenceTypes/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net9/NullReferenceTypes/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs index caef12016777..aec08983d426 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -228,6 +228,8 @@ public static string SanitizeFilename(string filename) return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs index 1557552a7687..71fc722f02ff 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -66,6 +66,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -138,6 +140,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs index 648b8fde8871..1e87e6de2950 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Animal.cs @@ -38,6 +38,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -49,7 +50,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs index f6a4492730f4..0a879915fc74 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Cat.cs @@ -45,13 +45,6 @@ public Cat(Option color = default, Option declawed = default) : partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs index 35e299d05c18..c37ba2ec211e 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ChildCat.cs @@ -39,6 +39,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -114,7 +115,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs index 6acd040dc2e8..d2cbf27feffc 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -38,6 +38,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -101,7 +102,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..d86b93b3ff02 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,185 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value!, descendantName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..152103158d0a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,185 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value!, confidentiality.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs index f09923475b0d..05eb0781cfe7 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/Dog.cs @@ -45,13 +45,6 @@ public Dog(Option breed = default, Option color = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs index fa8a54d9dd01..17b8f812e777 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/EntityBase.cs @@ -37,6 +37,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -47,7 +48,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index 4cefd4ca6216..e8f6e0889167 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -37,6 +37,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -47,7 +48,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs index a4b1ab4347d6..9f659ee86ae8 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/ParentPet.cs @@ -42,13 +42,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..f1a80055f735 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,287 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string? discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES index a24733a7c11a..b6cb61731e5e 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -170,6 +173,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -236,6 +241,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net9/Petstore/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net9/Petstore/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs index 0dfe6afc4b13..d6f05a813b15 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -226,6 +226,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs index 47783040097a..58a420f8836c 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -64,6 +64,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -136,6 +138,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Animal.cs index d0b07da62cc8..5a0b22326df1 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Cat.cs index 6a1dfe1d90b6..f424f8ef9d85 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs index 87a49cbe08f0..ff5df164f2c9 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs @@ -37,6 +37,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -112,7 +113,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..78e8ee587c11 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..a9859338c4ba --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Dog.cs index 2ab1ca19d2d0..a4879a78dc05 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..36c7ef1ca217 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,285 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES index a24733a7c11a..b6cb61731e5e 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -170,6 +173,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -236,6 +241,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/net9/SourceGeneration/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/net9/SourceGeneration/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs index caef12016777..aec08983d426 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -228,6 +228,8 @@ public static string SanitizeFilename(string filename) return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs index 9914ab629e3f..08eb7fbb07e8 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -66,6 +66,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -138,6 +140,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); @@ -174,6 +177,8 @@ public HostConfiguration(IServiceCollection services) new DanishPigSerializationContext(), new DateOnlyClassSerializationContext(), new DeprecatedObjectSerializationContext(), + new Descendant1SerializationContext(), + new Descendant2SerializationContext(), new DogSerializationContext(), new DrawingSerializationContext(), new EntityBaseSerializationContext(), @@ -240,6 +245,7 @@ public HostConfiguration(IServiceCollection services) new TagSerializationContext(), new TestCollectionEndingWithWordListSerializationContext(), new TestCollectionEndingWithWordListObjectSerializationContext(), + new TestDescendantsSerializationContext(), new TestInlineFreeformAdditionalPropertiesRequestSerializationContext(), new TriangleSerializationContext(), new TriangleInterfaceSerializationContext(), diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs index 7c54e55cb7b5..37a0519bbd6b 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Animal.cs @@ -39,6 +39,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -50,7 +51,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs index 352bba5d51e4..33e8935a249e 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Cat.cs @@ -46,13 +46,6 @@ public Cat(Option color = default, Option declawed = default) : partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs index 2b39e8e86f0c..4131c59373af 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ChildCat.cs @@ -40,6 +40,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -115,7 +116,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs index 3fd719564b91..a4a704b58170 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -39,6 +39,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -102,7 +103,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..9af51efffe3c --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,193 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using System.Text.Json.Serialization.Metadata; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value!, descendantName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } + + /// + /// The Descendant1SerializationContext + /// + [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)] + [JsonSerializable(typeof(Descendant1))] + public partial class Descendant1SerializationContext : JsonSerializerContext { } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..5e39d2322847 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,193 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using System.Text.Json.Serialization.Metadata; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value!, confidentiality.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } + + /// + /// The Descendant2SerializationContext + /// + [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)] + [JsonSerializable(typeof(Descendant2))] + public partial class Descendant2SerializationContext : JsonSerializerContext { } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs index 4de2c40c0183..6129b69ce916 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/Dog.cs @@ -46,13 +46,6 @@ public Dog(Option breed = default, Option color = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs index c8e883631368..093b2012f441 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/EntityBase.cs @@ -38,6 +38,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -48,7 +49,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index 69049f30a58f..2a787a59db6d 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -38,6 +38,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -48,7 +49,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs index 6218c3add483..b7c98ce645cb 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/ParentPet.cs @@ -43,13 +43,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..538b8c90d98f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,295 @@ +// +/* + * 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 + */ + +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using System.Text.Json.Serialization.Metadata; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string? discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string? localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()!); + break; + case "objectType": + string? objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value!); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } + + /// + /// The TestDescendantsSerializationContext + /// + [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization)] + [JsonSerializable(typeof(TestDescendants))] + public partial class TestDescendantsSerializationContext : JsonSerializerContext { } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES index 1facc69aec6b..ec9d28bdd136 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES @@ -33,6 +33,8 @@ docs/models/CopyActivity.md docs/models/DanishPig.md docs/models/DateOnlyClass.md docs/models/DeprecatedObject.md +docs/models/Descendant1.md +docs/models/Descendant2.md docs/models/Dog.md docs/models/Drawing.md docs/models/EntityBase.md @@ -99,6 +101,7 @@ docs/models/SpecialModelName.md docs/models/Tag.md docs/models/TestCollectionEndingWithWordList.md docs/models/TestCollectionEndingWithWordListObject.md +docs/models/TestDescendants.md docs/models/TestInlineFreeformAdditionalPropertiesRequest.md docs/models/Triangle.md docs/models/TriangleInterface.md @@ -168,6 +171,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -234,6 +239,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/Descendant1.md b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/Descendant1.md new file mode 100644 index 000000000000..c289ebd02abd --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/generichost/standard2.0/Petstore/docs/models/Descendant2.md b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/Descendant2.md new file mode 100644 index 000000000000..aea91e41c8ca --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/generichost/standard2.0/Petstore/docs/models/TestDescendants.md b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/TestDescendants.md new file mode 100644 index 000000000000..873b9339e9f0 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/models/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..f92c110e3c2b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..c2210523f34b --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,65 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..0732130160fb --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,94 @@ +/* + * 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; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs index 560c039d70a9..c3801c3dd6a9 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/ClientUtils.cs @@ -227,6 +227,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString(); if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum) return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum); + if (obj is TestDescendants.ObjectTypeEnum testDescendantsObjectTypeEnum) + return TestDescendants.ObjectTypeEnumToJsonValue(testDescendantsObjectTypeEnum); if (obj is Zebra.TypeEnum zebraTypeEnum) return Zebra.TypeEnumToJsonValue(zebraTypeEnum); if (obj is ZeroBasedEnum zeroBasedEnum) diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs index dbbc08df7968..b5de98d60f10 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/HostConfiguration.cs @@ -62,6 +62,8 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new DanishPigJsonConverter()); _jsonOptions.Converters.Add(new DateOnlyClassJsonConverter()); _jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter()); + _jsonOptions.Converters.Add(new Descendant1JsonConverter()); + _jsonOptions.Converters.Add(new Descendant2JsonConverter()); _jsonOptions.Converters.Add(new DogJsonConverter()); _jsonOptions.Converters.Add(new DrawingJsonConverter()); _jsonOptions.Converters.Add(new EntityBaseJsonConverter()); @@ -134,6 +136,7 @@ public HostConfiguration(IServiceCollection services) _jsonOptions.Converters.Add(new TagJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListJsonConverter()); _jsonOptions.Converters.Add(new TestCollectionEndingWithWordListObjectJsonConverter()); + _jsonOptions.Converters.Add(new TestDescendantsJsonConverter()); _jsonOptions.Converters.Add(new TestInlineFreeformAdditionalPropertiesRequestJsonConverter()); _jsonOptions.Converters.Add(new TriangleJsonConverter()); _jsonOptions.Converters.Add(new TriangleInterfaceJsonConverter()); diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Animal.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Animal.cs index 74cb14f52d91..f172cd70bc53 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Animal.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Animal.cs @@ -36,6 +36,7 @@ public partial class Animal : IValidatableObject [JsonConstructor] public Animal(Option color = default) { + ClassName = this.GetType().Name; ColorOption = color; OnCreated(); } @@ -47,7 +48,7 @@ public Animal(Option color = default) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string ClassName { get; } = "Animal"; + public string ClassName { get; } /// /// Used to track the state of Color diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Cat.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Cat.cs index 0ffe1228015d..780c28a972a6 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Cat.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Cat.cs @@ -43,13 +43,6 @@ public Cat(Option color = default, Option declawed = default) : b partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Cat"; - /// /// Used to track the state of Declawed /// diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs index 2eb5dd8dc35a..cce039237aea 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ChildCat.cs @@ -37,6 +37,7 @@ public partial class ChildCat : ParentPet, IValidatableObject public ChildCat(Option name = default) : base() { NameOption = name; + PetType = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), this.GetType().Name); OnCreated(); } @@ -112,7 +113,7 @@ public static string PetTypeEnumToJsonValue(PetTypeEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new PetTypeEnum PetType { get; } = (PetTypeEnum)Enum.Parse(typeof(PetTypeEnum), "ChildCat"); + public new PetTypeEnum PetType { get; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs index 7fbda7a016ba..7a8ae9371f73 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/CopyActivity.cs @@ -36,6 +36,7 @@ public partial class CopyActivity : EntityBase, IValidatableObject [JsonConstructor] public CopyActivity(string copyActivitytt) : base() { + Schema = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), this.GetType().Name); CopyActivitytt = copyActivitytt; OnCreated(); } @@ -99,7 +100,7 @@ public static string SchemaEnumToJsonValue(SchemaEnum value) /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new SchemaEnum Schema { get; } = (SchemaEnum)Enum.Parse(typeof(SchemaEnum), "CopyActivity"); + public new SchemaEnum Schema { get; } /// /// Gets or Sets CopyActivitytt diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..78e8ee587c11 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + public partial class Descendant1 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// descendantName + [JsonConstructor] + public Descendant1(string alternativeName, string descendantName) : base(alternativeName) + { + DescendantName = descendantName; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets DescendantName + /// + [JsonPropertyName("descendantName")] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant1JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant1 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option descendantName = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "descendantName": + descendantName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant1.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(alternativeName)); + + if (!descendantName.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(descendantName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant1.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant1."); + + if (descendantName.IsSet && descendantName.Value == null) + throw new ArgumentNullException(nameof(descendantName), "Property is not nullable for class Descendant1."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant1."); + + return new Descendant1(alternativeName.Value, descendantName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant1, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant1 descendant1, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant1.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant1.AlternativeName), "Property is required for class Descendant1."); + + if (descendant1.DescendantName == null) + throw new ArgumentNullException(nameof(descendant1.DescendantName), "Property is required for class Descendant1."); + + writer.WriteString("alternativeName", descendant1.AlternativeName); + + writer.WriteString("descendantName", descendant1.DescendantName); + + writer.WriteString("objectType", Descendant1.ObjectTypeEnumToJsonValue(descendant1.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..a9859338c4ba --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,183 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + public partial class Descendant2 : TestDescendants, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + /// confidentiality + [JsonConstructor] + public Descendant2(string alternativeName, string confidentiality) : base(alternativeName) + { + Confidentiality = confidentiality; + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Gets or Sets Confidentiality + /// + [JsonPropertyName("confidentiality")] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + } + + /// + /// A Json converter for type + /// + public class Descendant2JsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override Descendant2 Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option confidentiality = default; + Option objectType = default; + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "confidentiality": + confidentiality = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(Descendant2.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(alternativeName)); + + if (!confidentiality.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(confidentiality)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class Descendant2.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class Descendant2."); + + if (confidentiality.IsSet && confidentiality.Value == null) + throw new ArgumentNullException(nameof(confidentiality), "Property is not nullable for class Descendant2."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class Descendant2."); + + return new Descendant2(alternativeName.Value, confidentiality.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + writer.WriteStartObject(); + + WriteProperties(writer, descendant2, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, Descendant2 descendant2, JsonSerializerOptions jsonSerializerOptions) + { + if (descendant2.AlternativeName == null) + throw new ArgumentNullException(nameof(descendant2.AlternativeName), "Property is required for class Descendant2."); + + if (descendant2.Confidentiality == null) + throw new ArgumentNullException(nameof(descendant2.Confidentiality), "Property is required for class Descendant2."); + + writer.WriteString("alternativeName", descendant2.AlternativeName); + + writer.WriteString("confidentiality", descendant2.Confidentiality); + + writer.WriteString("objectType", Descendant2.ObjectTypeEnumToJsonValue(descendant2.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Dog.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Dog.cs index 605dc512434b..509278540c44 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Dog.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/Dog.cs @@ -43,13 +43,6 @@ public Dog(Option breed = default, Option color = default) : bas partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string ClassName { get; } = "Dog"; - /// /// Used to track the state of Breed /// diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs index 21bb6398df95..6ad9d8ea3a34 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/EntityBase.cs @@ -35,6 +35,7 @@ public partial class EntityBase : IValidatableObject [JsonConstructor] public EntityBase() { + Schema = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public EntityBase() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string Schema { get; } = "EntityBase"; + public string Schema { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs index b23e4826fd6b..78b741ac8c69 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/GrandparentAnimal.cs @@ -35,6 +35,7 @@ public partial class GrandparentAnimal : IValidatableObject [JsonConstructor] public GrandparentAnimal() { + PetType = this.GetType().Name; OnCreated(); } @@ -45,7 +46,7 @@ public GrandparentAnimal() /// [JsonIgnore] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public string PetType { get; } = "GrandparentAnimal"; + public string PetType { get; } /// /// Gets or Sets additional properties diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs index 83104e900d01..e69a7e25caa5 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/ParentPet.cs @@ -40,13 +40,6 @@ public ParentPet() : base() partial void OnCreated(); - /// - /// The discriminator - /// - [JsonIgnore] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public new string PetType { get; } = "ParentPet"; - /// /// Returns the string presentation of the object /// diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..36c7ef1ca217 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,285 @@ +// +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; +using Org.OpenAPITools.Client; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + public partial class TestDescendants : IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + /// alternativeName + [JsonConstructor] + public TestDescendants(string alternativeName) + { + AlternativeName = alternativeName; + ObjectType = (ObjectTypeEnum)Enum.Parse(typeof(ObjectTypeEnum), this.GetType().Name); + OnCreated(); + } + + partial void OnCreated(); + + /// + /// Defines ObjectType + /// + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + Descendant2 = 2 + } + + /// + /// Returns a + /// + /// + /// + /// + public static ObjectTypeEnum ObjectTypeEnumFromString(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + throw new NotImplementedException($"Could not convert value to type ObjectTypeEnum: '{value}'"); + } + + /// + /// Returns a + /// + /// + /// + public static ObjectTypeEnum? ObjectTypeEnumFromStringOrDefault(string value) + { + if (value.Equals("Descendant1")) + return ObjectTypeEnum.Descendant1; + + if (value.Equals("Descendant2")) + return ObjectTypeEnum.Descendant2; + + return null; + } + + /// + /// Converts the to the json value + /// + /// + /// + /// + public static string ObjectTypeEnumToJsonValue(ObjectTypeEnum value) + { + if (value == ObjectTypeEnum.Descendant1) + return "Descendant1"; + + if (value == ObjectTypeEnum.Descendant2) + return "Descendant2"; + + throw new NotImplementedException($"Value could not be handled: '{value}'"); + } + + /// + /// Gets or Sets AlternativeName + /// + [JsonPropertyName("alternativeName")] + public string AlternativeName { get; set; } + + /// + /// The discriminator + /// + [JsonIgnore] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + public ObjectTypeEnum ObjectType { get; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; } = new Dictionary(); + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + + /// + /// A Json converter for type + /// + public class TestDescendantsJsonConverter : JsonConverter + { + /// + /// Deserializes json to + /// + /// + /// + /// + /// + /// + public override TestDescendants Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions) + { + int currentDepth = utf8JsonReader.CurrentDepth; + + if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray) + throw new JsonException(); + + JsonTokenType startingTokenType = utf8JsonReader.TokenType; + + Option alternativeName = default; + Option objectType = default; + + string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "objectType"); + + if (discriminator != null && discriminator.Equals("Descendant1")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + if (discriminator != null && discriminator.Equals("Descendant2")) + return JsonSerializer.Deserialize(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value."); + + while (utf8JsonReader.Read()) + { + if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth) + break; + + if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1) + { + string localVarJsonPropertyName = utf8JsonReader.GetString(); + utf8JsonReader.Read(); + + switch (localVarJsonPropertyName) + { + case "alternativeName": + alternativeName = new Option(utf8JsonReader.GetString()); + break; + case "objectType": + string objectTypeRawValue = utf8JsonReader.GetString(); + if (objectTypeRawValue != null) + objectType = new Option(TestDescendants.ObjectTypeEnumFromStringOrDefault(objectTypeRawValue)); + break; + default: + break; + } + } + } + + if (!alternativeName.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(alternativeName)); + + if (!objectType.IsSet) + throw new ArgumentException("Property is required for class TestDescendants.", nameof(objectType)); + + if (alternativeName.IsSet && alternativeName.Value == null) + throw new ArgumentNullException(nameof(alternativeName), "Property is not nullable for class TestDescendants."); + + if (objectType.IsSet && objectType.Value == null) + throw new ArgumentNullException(nameof(objectType), "Property is not nullable for class TestDescendants."); + + return new TestDescendants(alternativeName.Value); + } + + /// + /// Serializes a + /// + /// + /// + /// + /// + public override void Write(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants is Descendant1 descendant1){ + JsonSerializer.Serialize(writer, descendant1, jsonSerializerOptions); + return; + } + + if (testDescendants is Descendant2 descendant2){ + JsonSerializer.Serialize(writer, descendant2, jsonSerializerOptions); + return; + } + + writer.WriteStartObject(); + + WriteProperties(writer, testDescendants, jsonSerializerOptions); + writer.WriteEndObject(); + } + + /// + /// Serializes the properties of + /// + /// + /// + /// + /// + public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions) + { + if (testDescendants.AlternativeName == null) + throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants."); + + writer.WriteString("alternativeName", testDescendants.AlternativeName); + + writer.WriteString("objectType", TestDescendants.ObjectTypeEnumToJsonValue(testDescendants.ObjectType)); + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/httpclient/net9/Petstore/.openapi-generator/FILES index 8bda3ce3fe77..6b41858405fb 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/.openapi-generator/FILES @@ -28,6 +28,8 @@ docs/DanishPig.md docs/DateOnlyClass.md docs/DefaultApi.md docs/DeprecatedObject.md +docs/Descendant1.md +docs/Descendant2.md docs/Dog.md docs/Drawing.md docs/EntityBase.md @@ -98,6 +100,7 @@ docs/StoreApi.md docs/Tag.md docs/TestCollectionEndingWithWordList.md docs/TestCollectionEndingWithWordListObject.md +docs/TestDescendants.md docs/TestInlineFreeformAdditionalPropertiesRequest.md docs/Triangle.md docs/TriangleInterface.md @@ -158,6 +161,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -224,6 +229,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md b/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md index e1623481f18f..238856cc7110 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md @@ -217,6 +217,8 @@ Class | Method | HTTP request | Description - [Model.DanishPig](docs/DanishPig.md) - [Model.DateOnlyClass](docs/DateOnlyClass.md) - [Model.DeprecatedObject](docs/DeprecatedObject.md) + - [Model.Descendant1](docs/Descendant1.md) + - [Model.Descendant2](docs/Descendant2.md) - [Model.Dog](docs/Dog.md) - [Model.Drawing](docs/Drawing.md) - [Model.EntityBase](docs/EntityBase.md) @@ -283,6 +285,7 @@ Class | Method | HTTP request | Description - [Model.Tag](docs/Tag.md) - [Model.TestCollectionEndingWithWordList](docs/TestCollectionEndingWithWordList.md) - [Model.TestCollectionEndingWithWordListObject](docs/TestCollectionEndingWithWordListObject.md) + - [Model.TestDescendants](docs/TestDescendants.md) - [Model.TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) - [Model.Triangle](docs/Triangle.md) - [Model.TriangleInterface](docs/TriangleInterface.md) diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/Descendant1.md b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/Descendant1.md new file mode 100644 index 000000000000..d36bd17fd77f --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/httpclient/net9/Petstore/docs/Descendant2.md b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/Descendant2.md new file mode 100644 index 000000000000..4c8d61ca46a8 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/httpclient/net9/Petstore/docs/TestDescendants.md b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/TestDescendants.md new file mode 100644 index 000000000000..895a1048e940 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..c8dc27df3d11 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..0ba1af79ba55 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..c17ca6e98494 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,95 @@ +/* + * 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 +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..a90f8b1593d2 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,164 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using FileParameter = Org.OpenAPITools.Client.FileParameter; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + [DataContract(Name = "Descendant1")] + public partial class Descendant1 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant1() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// descendantName (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant1). + public Descendant1(string descendantName = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant1) : base(alternativeName, objectType) + { + // to ensure "descendantName" is required (not null) + if (descendantName == null) + { + throw new ArgumentNullException("descendantName is a required property for Descendant1 and cannot be null"); + } + this.DescendantName = descendantName; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets DescendantName + /// + [DataMember(Name = "descendantName", IsRequired = true, EmitDefaultValue = true)] + public string DescendantName { get; set; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant1).AreEqual; + } + + /// + /// Returns true if Descendant1 instances are equal + /// + /// Instance of Descendant1 to be compared + /// Boolean + public bool Equals(Descendant1 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.DescendantName != null) + { + hashCode = (hashCode * 59) + this.DescendantName.GetHashCode(); + } + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..3148e8281456 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,164 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using FileParameter = Org.OpenAPITools.Client.FileParameter; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + [DataContract(Name = "Descendant2")] + public partial class Descendant2 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant2() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// confidentiality (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant2). + public Descendant2(string confidentiality = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant2) : base(alternativeName, objectType) + { + // to ensure "confidentiality" is required (not null) + if (confidentiality == null) + { + throw new ArgumentNullException("confidentiality is a required property for Descendant2 and cannot be null"); + } + this.Confidentiality = confidentiality; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets Confidentiality + /// + [DataMember(Name = "confidentiality", IsRequired = true, EmitDefaultValue = true)] + public string Confidentiality { get; set; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant2).AreEqual; + } + + /// + /// Returns true if Descendant2 instances are equal + /// + /// Instance of Descendant2 to be compared + /// Boolean + public bool Equals(Descendant2 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Confidentiality != null) + { + hashCode = (hashCode * 59) + this.Confidentiality.GetHashCode(); + } + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..0b9d18a6204b --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,189 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using FileParameter = Org.OpenAPITools.Client.FileParameter; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + [DataContract(Name = "TestDescendants")] + [JsonConverter(typeof(JsonSubtypes), "ObjectType")] + [JsonSubtypes.KnownSubType(typeof(Descendant1), "Descendant1")] + [JsonSubtypes.KnownSubType(typeof(Descendant2), "Descendant2")] + public partial class TestDescendants : IEquatable, IValidatableObject + { + /// + /// Defines ObjectType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + [EnumMember(Value = "Descendant1")] + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + [EnumMember(Value = "Descendant2")] + Descendant2 = 2 + } + + + /// + /// Gets or Sets ObjectType + /// + [DataMember(Name = "objectType", IsRequired = true, EmitDefaultValue = true)] + public ObjectTypeEnum ObjectType { get; set; } + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected TestDescendants() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// alternativeName (required). + /// objectType (required). + public TestDescendants(string alternativeName = default(string), ObjectTypeEnum objectType = default(ObjectTypeEnum)) + { + // to ensure "alternativeName" is required (not null) + if (alternativeName == null) + { + throw new ArgumentNullException("alternativeName is a required property for TestDescendants and cannot be null"); + } + this.AlternativeName = alternativeName; + this.ObjectType = objectType; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets AlternativeName + /// + [DataMember(Name = "alternativeName", IsRequired = true, EmitDefaultValue = true)] + public string AlternativeName { get; set; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" ObjectType: ").Append(ObjectType).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as TestDescendants).AreEqual; + } + + /// + /// Returns true if TestDescendants instances are equal + /// + /// Instance of TestDescendants to be compared + /// Boolean + public bool Equals(TestDescendants input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.AlternativeName != null) + { + hashCode = (hashCode * 59) + this.AlternativeName.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ObjectType.GetHashCode(); + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/.openapi-generator/FILES index b0909e10d1a5..6b9e55fa5cfc 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/.openapi-generator/FILES @@ -28,6 +28,8 @@ docs/DanishPig.md docs/DateOnlyClass.md docs/DefaultApi.md docs/DeprecatedObject.md +docs/Descendant1.md +docs/Descendant2.md docs/Dog.md docs/Drawing.md docs/EntityBase.md @@ -98,6 +100,7 @@ docs/StoreApi.md docs/Tag.md docs/TestCollectionEndingWithWordList.md docs/TestCollectionEndingWithWordListObject.md +docs/TestDescendants.md docs/TestInlineFreeformAdditionalPropertiesRequest.md docs/Triangle.md docs/TriangleInterface.md @@ -157,6 +160,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -223,6 +228,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md index 055197c06760..a8bbf1933974 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md @@ -205,6 +205,8 @@ Class | Method | HTTP request | Description - [Model.DanishPig](docs/DanishPig.md) - [Model.DateOnlyClass](docs/DateOnlyClass.md) - [Model.DeprecatedObject](docs/DeprecatedObject.md) + - [Model.Descendant1](docs/Descendant1.md) + - [Model.Descendant2](docs/Descendant2.md) - [Model.Dog](docs/Dog.md) - [Model.Drawing](docs/Drawing.md) - [Model.EntityBase](docs/EntityBase.md) @@ -271,6 +273,7 @@ Class | Method | HTTP request | Description - [Model.Tag](docs/Tag.md) - [Model.TestCollectionEndingWithWordList](docs/TestCollectionEndingWithWordList.md) - [Model.TestCollectionEndingWithWordListObject](docs/TestCollectionEndingWithWordListObject.md) + - [Model.TestDescendants](docs/TestDescendants.md) - [Model.TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) - [Model.Triangle](docs/Triangle.md) - [Model.TriangleInterface](docs/TriangleInterface.md) diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/Descendant1.md b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/Descendant1.md new file mode 100644 index 000000000000..d36bd17fd77f --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/httpclient/standard2.0/Petstore/docs/Descendant2.md b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/Descendant2.md new file mode 100644 index 000000000000..4c8d61ca46a8 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/httpclient/standard2.0/Petstore/docs/TestDescendants.md b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/TestDescendants.md new file mode 100644 index 000000000000..895a1048e940 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..c8dc27df3d11 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..0ba1af79ba55 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..c17ca6e98494 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,95 @@ +/* + * 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 +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..a90f8b1593d2 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,164 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using FileParameter = Org.OpenAPITools.Client.FileParameter; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + [DataContract(Name = "Descendant1")] + public partial class Descendant1 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant1() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// descendantName (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant1). + public Descendant1(string descendantName = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant1) : base(alternativeName, objectType) + { + // to ensure "descendantName" is required (not null) + if (descendantName == null) + { + throw new ArgumentNullException("descendantName is a required property for Descendant1 and cannot be null"); + } + this.DescendantName = descendantName; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets DescendantName + /// + [DataMember(Name = "descendantName", IsRequired = true, EmitDefaultValue = true)] + public string DescendantName { get; set; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant1).AreEqual; + } + + /// + /// Returns true if Descendant1 instances are equal + /// + /// Instance of Descendant1 to be compared + /// Boolean + public bool Equals(Descendant1 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.DescendantName != null) + { + hashCode = (hashCode * 59) + this.DescendantName.GetHashCode(); + } + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..3148e8281456 --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,164 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using FileParameter = Org.OpenAPITools.Client.FileParameter; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + [DataContract(Name = "Descendant2")] + public partial class Descendant2 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant2() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// confidentiality (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant2). + public Descendant2(string confidentiality = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant2) : base(alternativeName, objectType) + { + // to ensure "confidentiality" is required (not null) + if (confidentiality == null) + { + throw new ArgumentNullException("confidentiality is a required property for Descendant2 and cannot be null"); + } + this.Confidentiality = confidentiality; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets Confidentiality + /// + [DataMember(Name = "confidentiality", IsRequired = true, EmitDefaultValue = true)] + public string Confidentiality { get; set; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant2).AreEqual; + } + + /// + /// Returns true if Descendant2 instances are equal + /// + /// Instance of Descendant2 to be compared + /// Boolean + public bool Equals(Descendant2 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Confidentiality != null) + { + hashCode = (hashCode * 59) + this.Confidentiality.GetHashCode(); + } + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..0b9d18a6204b --- /dev/null +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,189 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using FileParameter = Org.OpenAPITools.Client.FileParameter; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + [DataContract(Name = "TestDescendants")] + [JsonConverter(typeof(JsonSubtypes), "ObjectType")] + [JsonSubtypes.KnownSubType(typeof(Descendant1), "Descendant1")] + [JsonSubtypes.KnownSubType(typeof(Descendant2), "Descendant2")] + public partial class TestDescendants : IEquatable, IValidatableObject + { + /// + /// Defines ObjectType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + [EnumMember(Value = "Descendant1")] + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + [EnumMember(Value = "Descendant2")] + Descendant2 = 2 + } + + + /// + /// Gets or Sets ObjectType + /// + [DataMember(Name = "objectType", IsRequired = true, EmitDefaultValue = true)] + public ObjectTypeEnum ObjectType { get; set; } + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected TestDescendants() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// alternativeName (required). + /// objectType (required). + public TestDescendants(string alternativeName = default(string), ObjectTypeEnum objectType = default(ObjectTypeEnum)) + { + // to ensure "alternativeName" is required (not null) + if (alternativeName == null) + { + throw new ArgumentNullException("alternativeName is a required property for TestDescendants and cannot be null"); + } + this.AlternativeName = alternativeName; + this.ObjectType = objectType; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets AlternativeName + /// + [DataMember(Name = "alternativeName", IsRequired = true, EmitDefaultValue = true)] + public string AlternativeName { get; set; } + + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" ObjectType: ").Append(ObjectType).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as TestDescendants).AreEqual; + } + + /// + /// Returns true if TestDescendants instances are equal + /// + /// Instance of TestDescendants to be compared + /// Boolean + public bool Equals(TestDescendants input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.AlternativeName != null) + { + hashCode = (hashCode * 59) + this.AlternativeName.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ObjectType.GetHashCode(); + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/restsharp/net8/Petstore/.openapi-generator/FILES index f63a424386ff..f902781c14cf 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/.openapi-generator/FILES @@ -28,6 +28,8 @@ docs/DanishPig.md docs/DateOnlyClass.md docs/DefaultApi.md docs/DeprecatedObject.md +docs/Descendant1.md +docs/Descendant2.md docs/Dog.md docs/Drawing.md docs/EntityBase.md @@ -98,6 +100,7 @@ docs/StoreApi.md docs/Tag.md docs/TestCollectionEndingWithWordList.md docs/TestCollectionEndingWithWordListObject.md +docs/TestDescendants.md docs/TestInlineFreeformAdditionalPropertiesRequest.md docs/Triangle.md docs/TriangleInterface.md @@ -160,6 +163,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -226,6 +231,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md b/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md index de946ecd37ab..7c66dfa4c795 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md @@ -192,6 +192,8 @@ Class | Method | HTTP request | Description - [Model.DanishPig](docs/DanishPig.md) - [Model.DateOnlyClass](docs/DateOnlyClass.md) - [Model.DeprecatedObject](docs/DeprecatedObject.md) + - [Model.Descendant1](docs/Descendant1.md) + - [Model.Descendant2](docs/Descendant2.md) - [Model.Dog](docs/Dog.md) - [Model.Drawing](docs/Drawing.md) - [Model.EntityBase](docs/EntityBase.md) @@ -258,6 +260,7 @@ Class | Method | HTTP request | Description - [Model.Tag](docs/Tag.md) - [Model.TestCollectionEndingWithWordList](docs/TestCollectionEndingWithWordList.md) - [Model.TestCollectionEndingWithWordListObject](docs/TestCollectionEndingWithWordListObject.md) + - [Model.TestDescendants](docs/TestDescendants.md) - [Model.TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) - [Model.Triangle](docs/Triangle.md) - [Model.TriangleInterface](docs/TriangleInterface.md) diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/Descendant1.md b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/Descendant1.md new file mode 100644 index 000000000000..d36bd17fd77f --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/restsharp/net8/Petstore/docs/Descendant2.md b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/Descendant2.md new file mode 100644 index 000000000000..4c8d61ca46a8 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/restsharp/net8/Petstore/docs/TestDescendants.md b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/TestDescendants.md new file mode 100644 index 000000000000..895a1048e940 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..c8dc27df3d11 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..0ba1af79ba55 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..c17ca6e98494 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,95 @@ +/* + * 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 +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..2191d34aabb5 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,148 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + [DataContract(Name = "Descendant1")] + public partial class Descendant1 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant1() { } + /// + /// Initializes a new instance of the class. + /// + /// descendantName (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant1). + public Descendant1(string descendantName = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant1) : base(alternativeName, objectType) + { + // to ensure "descendantName" is required (not null) + if (descendantName == null) + { + throw new ArgumentNullException("descendantName is a required property for Descendant1 and cannot be null"); + } + this.DescendantName = descendantName; + } + + /// + /// Gets or Sets DescendantName + /// + [DataMember(Name = "descendantName", IsRequired = true, EmitDefaultValue = true)] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant1).AreEqual; + } + + /// + /// Returns true if Descendant1 instances are equal + /// + /// Instance of Descendant1 to be compared + /// Boolean + public bool Equals(Descendant1 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.DescendantName != null) + { + hashCode = (hashCode * 59) + this.DescendantName.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..96aad2145bf0 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,148 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + [DataContract(Name = "Descendant2")] + public partial class Descendant2 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant2() { } + /// + /// Initializes a new instance of the class. + /// + /// confidentiality (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant2). + public Descendant2(string confidentiality = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant2) : base(alternativeName, objectType) + { + // to ensure "confidentiality" is required (not null) + if (confidentiality == null) + { + throw new ArgumentNullException("confidentiality is a required property for Descendant2 and cannot be null"); + } + this.Confidentiality = confidentiality; + } + + /// + /// Gets or Sets Confidentiality + /// + [DataMember(Name = "confidentiality", IsRequired = true, EmitDefaultValue = true)] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant2).AreEqual; + } + + /// + /// Returns true if Descendant2 instances are equal + /// + /// Instance of Descendant2 to be compared + /// Boolean + public bool Equals(Descendant2 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Confidentiality != null) + { + hashCode = (hashCode * 59) + this.Confidentiality.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..cb5f3c545123 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,173 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + [DataContract(Name = "TestDescendants")] + [JsonConverter(typeof(JsonSubtypes), "ObjectType")] + [JsonSubtypes.KnownSubType(typeof(Descendant1), "Descendant1")] + [JsonSubtypes.KnownSubType(typeof(Descendant2), "Descendant2")] + public partial class TestDescendants : IEquatable, IValidatableObject + { + /// + /// Defines ObjectType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + [EnumMember(Value = "Descendant1")] + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + [EnumMember(Value = "Descendant2")] + Descendant2 = 2 + } + + + /// + /// Gets or Sets ObjectType + /// + [DataMember(Name = "objectType", IsRequired = true, EmitDefaultValue = true)] + public ObjectTypeEnum ObjectType { get; set; } + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected TestDescendants() { } + /// + /// Initializes a new instance of the class. + /// + /// alternativeName (required). + /// objectType (required). + public TestDescendants(string alternativeName = default(string), ObjectTypeEnum objectType = default(ObjectTypeEnum)) + { + // to ensure "alternativeName" is required (not null) + if (alternativeName == null) + { + throw new ArgumentNullException("alternativeName is a required property for TestDescendants and cannot be null"); + } + this.AlternativeName = alternativeName; + this.ObjectType = objectType; + } + + /// + /// Gets or Sets AlternativeName + /// + [DataMember(Name = "alternativeName", IsRequired = true, EmitDefaultValue = true)] + public string AlternativeName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" ObjectType: ").Append(ObjectType).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as TestDescendants).AreEqual; + } + + /// + /// Returns true if TestDescendants instances are equal + /// + /// Instance of TestDescendants to be compared + /// Boolean + public bool Equals(TestDescendants input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.AlternativeName != null) + { + hashCode = (hashCode * 59) + this.AlternativeName.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ObjectType.GetHashCode(); + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/.openapi-generator/FILES b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/.openapi-generator/FILES index f63a424386ff..f902781c14cf 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/.openapi-generator/FILES @@ -28,6 +28,8 @@ docs/DanishPig.md docs/DateOnlyClass.md docs/DefaultApi.md docs/DeprecatedObject.md +docs/Descendant1.md +docs/Descendant2.md docs/Dog.md docs/Drawing.md docs/EntityBase.md @@ -98,6 +100,7 @@ docs/StoreApi.md docs/Tag.md docs/TestCollectionEndingWithWordList.md docs/TestCollectionEndingWithWordListObject.md +docs/TestDescendants.md docs/TestInlineFreeformAdditionalPropertiesRequest.md docs/Triangle.md docs/TriangleInterface.md @@ -160,6 +163,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -226,6 +231,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md index 523a2d862522..ce52ee22ebe2 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md @@ -180,6 +180,8 @@ Class | Method | HTTP request | Description - [Model.DanishPig](docs/DanishPig.md) - [Model.DateOnlyClass](docs/DateOnlyClass.md) - [Model.DeprecatedObject](docs/DeprecatedObject.md) + - [Model.Descendant1](docs/Descendant1.md) + - [Model.Descendant2](docs/Descendant2.md) - [Model.Dog](docs/Dog.md) - [Model.Drawing](docs/Drawing.md) - [Model.EntityBase](docs/EntityBase.md) @@ -246,6 +248,7 @@ Class | Method | HTTP request | Description - [Model.Tag](docs/Tag.md) - [Model.TestCollectionEndingWithWordList](docs/TestCollectionEndingWithWordList.md) - [Model.TestCollectionEndingWithWordListObject](docs/TestCollectionEndingWithWordListObject.md) + - [Model.TestDescendants](docs/TestDescendants.md) - [Model.TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) - [Model.Triangle](docs/Triangle.md) - [Model.TriangleInterface](docs/TriangleInterface.md) diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/Descendant1.md b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/Descendant1.md new file mode 100644 index 000000000000..d36bd17fd77f --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/restsharp/standard2.0/ConditionalSerialization/docs/Descendant2.md b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/Descendant2.md new file mode 100644 index 000000000000..4c8d61ca46a8 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/restsharp/standard2.0/ConditionalSerialization/docs/TestDescendants.md b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/TestDescendants.md new file mode 100644 index 000000000000..895a1048e940 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..c8dc27df3d11 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Fact] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Fact] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..0ba1af79ba55 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Fact] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Fact] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..c17ca6e98494 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,95 @@ +/* + * 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 +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Fact] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test deserialize a Descendant1 from type TestDescendants + /// + [Fact] + public void Descendant1DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant1 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant1().ToJson())); + } + + /// + /// Test deserialize a Descendant2 from type TestDescendants + /// + [Fact] + public void Descendant2DeserializeFromTestDescendantsTest() + { + // TODO uncomment below to test deserialize a Descendant2 from type TestDescendants + //Assert.IsType(JsonConvert.DeserializeObject(new Descendant2().ToJson())); + } + + /// + /// Test the property 'AlternativeName' + /// + [Fact] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + + /// + /// Test the property 'ObjectType' + /// + [Fact] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..77e199d9f318 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,181 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + [DataContract(Name = "Descendant1")] + public partial class Descendant1 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant1() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// descendantName (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant1). + public Descendant1(string descendantName = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant1) : base(alternativeName, objectType) + { + // to ensure "descendantName" is required (not null) + if (descendantName == null) + { + throw new ArgumentNullException("descendantName is a required property for Descendant1 and cannot be null"); + } + this._DescendantName = descendantName; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets DescendantName + /// + [DataMember(Name = "descendantName", IsRequired = true, EmitDefaultValue = true)] + public string DescendantName + { + get{ return _DescendantName;} + set + { + _DescendantName = value; + _flagDescendantName = true; + } + } + private string _DescendantName; + private bool _flagDescendantName; + + /// + /// Returns false as DescendantName should not be serialized given that it's read-only. + /// + /// false (boolean) + public bool ShouldSerializeDescendantName() + { + return _flagDescendantName; + } + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant1).AreEqual; + } + + /// + /// Returns true if Descendant1 instances are equal + /// + /// Instance of Descendant1 to be compared + /// Boolean + public bool Equals(Descendant1 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.DescendantName != null) + { + hashCode = (hashCode * 59) + this.DescendantName.GetHashCode(); + } + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..a4c58818c247 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,181 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + [DataContract(Name = "Descendant2")] + public partial class Descendant2 : TestDescendants, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant2() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// confidentiality (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant2). + public Descendant2(string confidentiality = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant2) : base(alternativeName, objectType) + { + // to ensure "confidentiality" is required (not null) + if (confidentiality == null) + { + throw new ArgumentNullException("confidentiality is a required property for Descendant2 and cannot be null"); + } + this._Confidentiality = confidentiality; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets Confidentiality + /// + [DataMember(Name = "confidentiality", IsRequired = true, EmitDefaultValue = true)] + public string Confidentiality + { + get{ return _Confidentiality;} + set + { + _Confidentiality = value; + _flagConfidentiality = true; + } + } + private string _Confidentiality; + private bool _flagConfidentiality; + + /// + /// Returns false as Confidentiality should not be serialized given that it's read-only. + /// + /// false (boolean) + public bool ShouldSerializeConfidentiality() + { + return _flagConfidentiality; + } + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as Descendant2).AreEqual; + } + + /// + /// Returns true if Descendant2 instances are equal + /// + /// Instance of Descendant2 to be compared + /// Boolean + public bool Equals(Descendant2 input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Confidentiality != null) + { + hashCode = (hashCode * 59) + this.Confidentiality.GetHashCode(); + } + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) + { + yield return x; + } + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..2e4eadf4cc50 --- /dev/null +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,226 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using JsonSubTypes; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; +using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + [DataContract(Name = "TestDescendants")] + [JsonConverter(typeof(JsonSubtypes), "ObjectType")] + [JsonSubtypes.KnownSubType(typeof(Descendant1), "Descendant1")] + [JsonSubtypes.KnownSubType(typeof(Descendant2), "Descendant2")] + public partial class TestDescendants : IEquatable, IValidatableObject + { + /// + /// Defines ObjectType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + [EnumMember(Value = "Descendant1")] + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + [EnumMember(Value = "Descendant2")] + Descendant2 = 2 + } + + + /// + /// Gets or Sets ObjectType + /// + + [DataMember(Name = "objectType", IsRequired = true, EmitDefaultValue = true)] + public ObjectTypeEnum ObjectType + { + get{ return _ObjectType;} + set + { + _ObjectType = value; + _flagObjectType = true; + } + } + private ObjectTypeEnum _ObjectType; + private bool _flagObjectType; + + /// + /// Returns false as ObjectType should not be serialized given that it's read-only. + /// + /// false (boolean) + public bool ShouldSerializeObjectType() + { + return _flagObjectType; + } + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected TestDescendants() + { + this.AdditionalProperties = new Dictionary(); + } + /// + /// Initializes a new instance of the class. + /// + /// alternativeName (required). + /// objectType (required). + public TestDescendants(string alternativeName = default(string), ObjectTypeEnum objectType = default(ObjectTypeEnum)) + { + // to ensure "alternativeName" is required (not null) + if (alternativeName == null) + { + throw new ArgumentNullException("alternativeName is a required property for TestDescendants and cannot be null"); + } + this._AlternativeName = alternativeName; + this._ObjectType = objectType; + this.AdditionalProperties = new Dictionary(); + } + + /// + /// Gets or Sets AlternativeName + /// + [DataMember(Name = "alternativeName", IsRequired = true, EmitDefaultValue = true)] + public string AlternativeName + { + get{ return _AlternativeName;} + set + { + _AlternativeName = value; + _flagAlternativeName = true; + } + } + private string _AlternativeName; + private bool _flagAlternativeName; + + /// + /// Returns false as AlternativeName should not be serialized given that it's read-only. + /// + /// false (boolean) + public bool ShouldSerializeAlternativeName() + { + return _flagAlternativeName; + } + /// + /// Gets or Sets additional properties + /// + [JsonExtensionData] + public IDictionary AdditionalProperties { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" ObjectType: ").Append(ObjectType).Append("\n"); + sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input as TestDescendants).AreEqual; + } + + /// + /// Returns true if TestDescendants instances are equal + /// + /// Instance of TestDescendants to be compared + /// Boolean + public bool Equals(TestDescendants input) + { + return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.AlternativeName != null) + { + hashCode = (hashCode * 59) + this.AlternativeName.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ObjectType.GetHashCode(); + if (this.AdditionalProperties != null) + { + hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode(); + } + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + return this.BaseValidate(validationContext); + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + protected IEnumerable BaseValidate(ValidationContext validationContext) + { + yield break; + } + } + +} diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/.openapi-generator/FILES index 7a3fb0afaba7..9bee4cd7fc41 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/.openapi-generator/FILES @@ -26,6 +26,8 @@ docs/DanishPig.md docs/DateOnlyClass.md docs/DefaultApi.md docs/DeprecatedObject.md +docs/Descendant1.md +docs/Descendant2.md docs/Dog.md docs/Drawing.md docs/EntityBase.md @@ -96,6 +98,7 @@ docs/StoreApi.md docs/Tag.md docs/TestCollectionEndingWithWordList.md docs/TestCollectionEndingWithWordListObject.md +docs/TestDescendants.md docs/TestInlineFreeformAdditionalPropertiesRequest.md docs/Triangle.md docs/TriangleInterface.md @@ -156,6 +159,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -222,6 +227,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md index b7d030f82ff1..7e38d83d3da4 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md @@ -166,6 +166,8 @@ Class | Method | HTTP request | Description - [Model.DanishPig](DanishPig.md) - [Model.DateOnlyClass](DateOnlyClass.md) - [Model.DeprecatedObject](DeprecatedObject.md) + - [Model.Descendant1](Descendant1.md) + - [Model.Descendant2](Descendant2.md) - [Model.Dog](Dog.md) - [Model.Drawing](Drawing.md) - [Model.EntityBase](EntityBase.md) @@ -232,6 +234,7 @@ Class | Method | HTTP request | Description - [Model.Tag](Tag.md) - [Model.TestCollectionEndingWithWordList](TestCollectionEndingWithWordList.md) - [Model.TestCollectionEndingWithWordListObject](TestCollectionEndingWithWordListObject.md) + - [Model.TestDescendants](TestDescendants.md) - [Model.TestInlineFreeformAdditionalPropertiesRequest](TestInlineFreeformAdditionalPropertiesRequest.md) - [Model.Triangle](Triangle.md) - [Model.TriangleInterface](TriangleInterface.md) diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/Descendant1.md b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/Descendant1.md new file mode 100644 index 000000000000..d36bd17fd77f --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/unityWebRequest/net9/Petstore/docs/Descendant2.md b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/Descendant2.md new file mode 100644 index 000000000000..4c8d61ca46a8 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/unityWebRequest/net9/Petstore/docs/TestDescendants.md b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/TestDescendants.md new file mode 100644 index 000000000000..895a1048e940 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..c0203f826fc7 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Model; +using Org.OpenAPITools.Client; +using System.Reflection; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Test] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Test] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..54c08e3da097 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Model; +using Org.OpenAPITools.Client; +using System.Reflection; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Test] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Test] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..3a8f6b45c383 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,74 @@ +/* + * 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 System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Model; +using Org.OpenAPITools.Client; +using System.Reflection; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Test] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test the property 'AlternativeName' + /// + [Test] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + /// + /// Test the property 'ObjectType' + /// + [Test] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..73d2d0fddd24 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,131 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + [DataContract(Name = "Descendant1")] + public partial class Descendant1 : TestDescendants, IEquatable + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant1() { } + /// + /// Initializes a new instance of the class. + /// + /// descendantName (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant1). + public Descendant1(string descendantName = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant1) : base(alternativeName, objectType) + { + // to ensure "descendantName" is required (not null) + if (descendantName == null) + { + throw new ArgumentNullException("descendantName is a required property for Descendant1 and cannot be null"); + } + this.DescendantName = descendantName; + } + + /// + /// Gets or Sets DescendantName + /// + [DataMember(Name = "descendantName", IsRequired = true, EmitDefaultValue = true)] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as Descendant1); + } + + /// + /// Returns true if Descendant1 instances are equal + /// + /// Instance of Descendant1 to be compared + /// Boolean + public bool Equals(Descendant1 input) + { + if (input == null) + { + return false; + } + return base.Equals(input) && + ( + this.DescendantName == input.DescendantName || + (this.DescendantName != null && + this.DescendantName.Equals(input.DescendantName)) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.DescendantName != null) + { + hashCode = (hashCode * 59) + this.DescendantName.GetHashCode(); + } + return hashCode; + } + } + + } + +} diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..513e80611cc6 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,131 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + [DataContract(Name = "Descendant2")] + public partial class Descendant2 : TestDescendants, IEquatable + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant2() { } + /// + /// Initializes a new instance of the class. + /// + /// confidentiality (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant2). + public Descendant2(string confidentiality = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant2) : base(alternativeName, objectType) + { + // to ensure "confidentiality" is required (not null) + if (confidentiality == null) + { + throw new ArgumentNullException("confidentiality is a required property for Descendant2 and cannot be null"); + } + this.Confidentiality = confidentiality; + } + + /// + /// Gets or Sets Confidentiality + /// + [DataMember(Name = "confidentiality", IsRequired = true, EmitDefaultValue = true)] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as Descendant2); + } + + /// + /// Returns true if Descendant2 instances are equal + /// + /// Instance of Descendant2 to be compared + /// Boolean + public bool Equals(Descendant2 input) + { + if (input == null) + { + return false; + } + return base.Equals(input) && + ( + this.Confidentiality == input.Confidentiality || + (this.Confidentiality != null && + this.Confidentiality.Equals(input.Confidentiality)) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Confidentiality != null) + { + hashCode = (hashCode * 59) + this.Confidentiality.GetHashCode(); + } + return hashCode; + } + } + + } + +} diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..535bbbaba69f --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,161 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + [DataContract(Name = "TestDescendants")] + public partial class TestDescendants : IEquatable + { + /// + /// Defines ObjectType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + [EnumMember(Value = "Descendant1")] + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + [EnumMember(Value = "Descendant2")] + Descendant2 = 2 + } + + + /// + /// Gets or Sets ObjectType + /// + [DataMember(Name = "objectType", IsRequired = true, EmitDefaultValue = true)] + public ObjectTypeEnum ObjectType { get; set; } + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected TestDescendants() { } + /// + /// Initializes a new instance of the class. + /// + /// alternativeName (required). + /// objectType (required). + public TestDescendants(string alternativeName = default(string), ObjectTypeEnum objectType = default(ObjectTypeEnum)) + { + // to ensure "alternativeName" is required (not null) + if (alternativeName == null) + { + throw new ArgumentNullException("alternativeName is a required property for TestDescendants and cannot be null"); + } + this.AlternativeName = alternativeName; + this.ObjectType = objectType; + } + + /// + /// Gets or Sets AlternativeName + /// + [DataMember(Name = "alternativeName", IsRequired = true, EmitDefaultValue = true)] + public string AlternativeName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" ObjectType: ").Append(ObjectType).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as TestDescendants); + } + + /// + /// Returns true if TestDescendants instances are equal + /// + /// Instance of TestDescendants to be compared + /// Boolean + public bool Equals(TestDescendants input) + { + if (input == null) + { + return false; + } + return + ( + this.AlternativeName == input.AlternativeName || + (this.AlternativeName != null && + this.AlternativeName.Equals(input.AlternativeName)) + ) && + ( + this.ObjectType == input.ObjectType || + this.ObjectType.Equals(input.ObjectType) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.AlternativeName != null) + { + hashCode = (hashCode * 59) + this.AlternativeName.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ObjectType.GetHashCode(); + return hashCode; + } + } + + } + +} diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/.openapi-generator/FILES index 7a3fb0afaba7..9bee4cd7fc41 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/.openapi-generator/FILES @@ -26,6 +26,8 @@ docs/DanishPig.md docs/DateOnlyClass.md docs/DefaultApi.md docs/DeprecatedObject.md +docs/Descendant1.md +docs/Descendant2.md docs/Dog.md docs/Drawing.md docs/EntityBase.md @@ -96,6 +98,7 @@ docs/StoreApi.md docs/Tag.md docs/TestCollectionEndingWithWordList.md docs/TestCollectionEndingWithWordListObject.md +docs/TestDescendants.md docs/TestInlineFreeformAdditionalPropertiesRequest.md docs/Triangle.md docs/TriangleInterface.md @@ -156,6 +159,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs src/Org.OpenAPITools/Model/DanishPig.cs src/Org.OpenAPITools/Model/DateOnlyClass.cs src/Org.OpenAPITools/Model/DeprecatedObject.cs +src/Org.OpenAPITools/Model/Descendant1.cs +src/Org.OpenAPITools/Model/Descendant2.cs src/Org.OpenAPITools/Model/Dog.cs src/Org.OpenAPITools/Model/Drawing.cs src/Org.OpenAPITools/Model/EntityBase.cs @@ -222,6 +227,7 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs src/Org.OpenAPITools/Model/Tag.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs +src/Org.OpenAPITools/Model/TestDescendants.cs src/Org.OpenAPITools/Model/TestInlineFreeformAdditionalPropertiesRequest.cs src/Org.OpenAPITools/Model/Triangle.cs src/Org.OpenAPITools/Model/TriangleInterface.cs diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md index b7d030f82ff1..7e38d83d3da4 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md @@ -166,6 +166,8 @@ Class | Method | HTTP request | Description - [Model.DanishPig](DanishPig.md) - [Model.DateOnlyClass](DateOnlyClass.md) - [Model.DeprecatedObject](DeprecatedObject.md) + - [Model.Descendant1](Descendant1.md) + - [Model.Descendant2](Descendant2.md) - [Model.Dog](Dog.md) - [Model.Drawing](Drawing.md) - [Model.EntityBase](EntityBase.md) @@ -232,6 +234,7 @@ Class | Method | HTTP request | Description - [Model.Tag](Tag.md) - [Model.TestCollectionEndingWithWordList](TestCollectionEndingWithWordList.md) - [Model.TestCollectionEndingWithWordListObject](TestCollectionEndingWithWordListObject.md) + - [Model.TestDescendants](TestDescendants.md) - [Model.TestInlineFreeformAdditionalPropertiesRequest](TestInlineFreeformAdditionalPropertiesRequest.md) - [Model.Triangle](Triangle.md) - [Model.TriangleInterface](TriangleInterface.md) diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml index 6a83f7a1e484..2e264be37c70 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml @@ -2770,6 +2770,40 @@ components: properties: id: type: string + Descendant1: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + descendantName: + type: string + required: + - descendantName + type: object + Descendant2: + allOf: + - $ref: '#/components/schemas/TestDescendants' + - properties: + confidentiality: + type: string + required: + - confidentiality + type: object + TestDescendants: + description: "" + discriminator: + propertyName: objectType + properties: + alternativeName: + type: string + objectType: + enum: + - Descendant1 + - Descendant2 + type: string + required: + - alternativeName + - objectType + type: object CopyActivity: allOf: - $ref: '#/components/schemas/EntityBase' diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/Descendant1.md b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/Descendant1.md new file mode 100644 index 000000000000..d36bd17fd77f --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/Descendant1.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**DescendantName** | **string** | | + +[[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/unityWebRequest/standard2.0/Petstore/docs/Descendant2.md b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/Descendant2.md new file mode 100644 index 000000000000..4c8d61ca46a8 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/Descendant2.md @@ -0,0 +1,12 @@ +# Org.OpenAPITools.Model.Descendant2 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | +**Confidentiality** | **string** | | + +[[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/unityWebRequest/standard2.0/Petstore/docs/TestDescendants.md b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/TestDescendants.md new file mode 100644 index 000000000000..895a1048e940 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/TestDescendants.md @@ -0,0 +1,11 @@ +# Org.OpenAPITools.Model.TestDescendants + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AlternativeName** | **string** | | +**ObjectType** | **string** | | + +[[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/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs new file mode 100644 index 000000000000..c0203f826fc7 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant1Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Model; +using Org.OpenAPITools.Client; +using System.Reflection; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant1 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant1Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant1 + //private Descendant1 instance; + + public Descendant1Tests() + { + // TODO uncomment below to create an instance of Descendant1 + //instance = new Descendant1(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant1 + /// + [Test] + public void Descendant1InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant1 + //Assert.IsType(instance); + } + + /// + /// Test the property 'DescendantName' + /// + [Test] + public void DescendantNameTest() + { + // TODO unit test for the property 'DescendantName' + } + } +} diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs new file mode 100644 index 000000000000..54c08e3da097 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/Descendant2Tests.cs @@ -0,0 +1,66 @@ +/* + * 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 System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Model; +using Org.OpenAPITools.Client; +using System.Reflection; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing Descendant2 + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class Descendant2Tests : IDisposable + { + // TODO uncomment below to declare an instance variable for Descendant2 + //private Descendant2 instance; + + public Descendant2Tests() + { + // TODO uncomment below to create an instance of Descendant2 + //instance = new Descendant2(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of Descendant2 + /// + [Test] + public void Descendant2InstanceTest() + { + // TODO uncomment below to test "IsType" Descendant2 + //Assert.IsType(instance); + } + + /// + /// Test the property 'Confidentiality' + /// + [Test] + public void ConfidentialityTest() + { + // TODO unit test for the property 'Confidentiality' + } + } +} diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs new file mode 100644 index 000000000000..3a8f6b45c383 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools.Test/Model/TestDescendantsTests.cs @@ -0,0 +1,74 @@ +/* + * 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 System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Model; +using Org.OpenAPITools.Client; +using System.Reflection; +using Newtonsoft.Json; +using NUnit.Framework; + +namespace Org.OpenAPITools.Test.Model +{ + /// + /// Class for testing TestDescendants + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class TestDescendantsTests : IDisposable + { + // TODO uncomment below to declare an instance variable for TestDescendants + //private TestDescendants instance; + + public TestDescendantsTests() + { + // TODO uncomment below to create an instance of TestDescendants + //instance = new TestDescendants(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of TestDescendants + /// + [Test] + public void TestDescendantsInstanceTest() + { + // TODO uncomment below to test "IsType" TestDescendants + //Assert.IsType(instance); + } + + /// + /// Test the property 'AlternativeName' + /// + [Test] + public void AlternativeNameTest() + { + // TODO unit test for the property 'AlternativeName' + } + /// + /// Test the property 'ObjectType' + /// + [Test] + public void ObjectTypeTest() + { + // TODO unit test for the property 'ObjectType' + } + } +} diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs new file mode 100644 index 000000000000..73d2d0fddd24 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant1.cs @@ -0,0 +1,131 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant1 + /// + [DataContract(Name = "Descendant1")] + public partial class Descendant1 : TestDescendants, IEquatable + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant1() { } + /// + /// Initializes a new instance of the class. + /// + /// descendantName (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant1). + public Descendant1(string descendantName = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant1) : base(alternativeName, objectType) + { + // to ensure "descendantName" is required (not null) + if (descendantName == null) + { + throw new ArgumentNullException("descendantName is a required property for Descendant1 and cannot be null"); + } + this.DescendantName = descendantName; + } + + /// + /// Gets or Sets DescendantName + /// + [DataMember(Name = "descendantName", IsRequired = true, EmitDefaultValue = true)] + public string DescendantName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant1 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" DescendantName: ").Append(DescendantName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as Descendant1); + } + + /// + /// Returns true if Descendant1 instances are equal + /// + /// Instance of Descendant1 to be compared + /// Boolean + public bool Equals(Descendant1 input) + { + if (input == null) + { + return false; + } + return base.Equals(input) && + ( + this.DescendantName == input.DescendantName || + (this.DescendantName != null && + this.DescendantName.Equals(input.DescendantName)) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.DescendantName != null) + { + hashCode = (hashCode * 59) + this.DescendantName.GetHashCode(); + } + return hashCode; + } + } + + } + +} diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs new file mode 100644 index 000000000000..513e80611cc6 --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/Descendant2.cs @@ -0,0 +1,131 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; + +namespace Org.OpenAPITools.Model +{ + /// + /// Descendant2 + /// + [DataContract(Name = "Descendant2")] + public partial class Descendant2 : TestDescendants, IEquatable + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected Descendant2() { } + /// + /// Initializes a new instance of the class. + /// + /// confidentiality (required). + /// alternativeName (required). + /// objectType (required) (default to ObjectTypeEnum.Descendant2). + public Descendant2(string confidentiality = default(string), string alternativeName = default(string), ObjectTypeEnum objectType = ObjectTypeEnum.Descendant2) : base(alternativeName, objectType) + { + // to ensure "confidentiality" is required (not null) + if (confidentiality == null) + { + throw new ArgumentNullException("confidentiality is a required property for Descendant2 and cannot be null"); + } + this.Confidentiality = confidentiality; + } + + /// + /// Gets or Sets Confidentiality + /// + [DataMember(Name = "confidentiality", IsRequired = true, EmitDefaultValue = true)] + public string Confidentiality { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class Descendant2 {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); + sb.Append(" Confidentiality: ").Append(Confidentiality).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as Descendant2); + } + + /// + /// Returns true if Descendant2 instances are equal + /// + /// Instance of Descendant2 to be compared + /// Boolean + public bool Equals(Descendant2 input) + { + if (input == null) + { + return false; + } + return base.Equals(input) && + ( + this.Confidentiality == input.Confidentiality || + (this.Confidentiality != null && + this.Confidentiality.Equals(input.Confidentiality)) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Confidentiality != null) + { + hashCode = (hashCode * 59) + this.Confidentiality.GetHashCode(); + } + return hashCode; + } + } + + } + +} diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs new file mode 100644 index 000000000000..535bbbaba69f --- /dev/null +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Model/TestDescendants.cs @@ -0,0 +1,161 @@ +/* + * 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 System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter; + +namespace Org.OpenAPITools.Model +{ + /// + /// TestDescendants + /// + [DataContract(Name = "TestDescendants")] + public partial class TestDescendants : IEquatable + { + /// + /// Defines ObjectType + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ObjectTypeEnum + { + /// + /// Enum Descendant1 for value: Descendant1 + /// + [EnumMember(Value = "Descendant1")] + Descendant1 = 1, + + /// + /// Enum Descendant2 for value: Descendant2 + /// + [EnumMember(Value = "Descendant2")] + Descendant2 = 2 + } + + + /// + /// Gets or Sets ObjectType + /// + [DataMember(Name = "objectType", IsRequired = true, EmitDefaultValue = true)] + public ObjectTypeEnum ObjectType { get; set; } + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected TestDescendants() { } + /// + /// Initializes a new instance of the class. + /// + /// alternativeName (required). + /// objectType (required). + public TestDescendants(string alternativeName = default(string), ObjectTypeEnum objectType = default(ObjectTypeEnum)) + { + // to ensure "alternativeName" is required (not null) + if (alternativeName == null) + { + throw new ArgumentNullException("alternativeName is a required property for TestDescendants and cannot be null"); + } + this.AlternativeName = alternativeName; + this.ObjectType = objectType; + } + + /// + /// Gets or Sets AlternativeName + /// + [DataMember(Name = "alternativeName", IsRequired = true, EmitDefaultValue = true)] + public string AlternativeName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class TestDescendants {\n"); + sb.Append(" AlternativeName: ").Append(AlternativeName).Append("\n"); + sb.Append(" ObjectType: ").Append(ObjectType).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as TestDescendants); + } + + /// + /// Returns true if TestDescendants instances are equal + /// + /// Instance of TestDescendants to be compared + /// Boolean + public bool Equals(TestDescendants input) + { + if (input == null) + { + return false; + } + return + ( + this.AlternativeName == input.AlternativeName || + (this.AlternativeName != null && + this.AlternativeName.Equals(input.AlternativeName)) + ) && + ( + this.ObjectType == input.ObjectType || + this.ObjectType.Equals(input.ObjectType) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.AlternativeName != null) + { + hashCode = (hashCode * 59) + this.AlternativeName.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ObjectType.GetHashCode(); + return hashCode; + } + } + + } + +}