diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/3.0/model.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/3.0/model.mustache index a9e04767cdce..1bb50410d06f 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/3.0/model.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/3.0/model.mustache @@ -77,7 +77,7 @@ namespace {{modelPackage}} public {{{datatypeWithEnum}}}{{#isNullable}}?{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}} {{/isEnum}} {{^isEnum}} - public {{{dataType}}}{{#nullableReferenceTypes}}{{^isContainer}}{{^required}}?{{/required}}{{/isContainer}}{{/nullableReferenceTypes}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}} + public {{{dataType}}}{{#nullableReferenceTypes}}{{^isContainer}}{{^required}}{{^isNullable}}?{{/isNullable}}{{/required}}{{/isContainer}}{{/nullableReferenceTypes}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}} {{/isEnum}} {{^-last}} diff --git a/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml index 20e8b70c4218..065598b9f743 100644 --- a/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml @@ -594,6 +594,20 @@ paths: responses: default: description: successful operation + /fake/nullable_example_test: + get: + tags: + - fake + summary: Fake endpoint to test nullable example (object) + description: '' + operationId: fake_nullable_example_test + responses: + '200': + description: Successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/TestNullable' externalDocs: description: Find out more about Swagger url: 'http://swagger.io' @@ -637,6 +651,14 @@ components: enum: - A - B + TestNullable: + type: object + properties: + name: + type: string + nullableName: + type: string + nullable: true Order: title: Pet Order description: An order for a pets from the pet store diff --git a/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES index ac21668e628b..e04fd4c8e91c 100644 --- a/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-3.0/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Program.cs diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..8db75f2dafd6 --- /dev/null +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-3.0/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES index ac21668e628b..e04fd4c8e91c 100644 --- a/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-3.1/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Program.cs diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..8db75f2dafd6 --- /dev/null +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-3.1/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES index ac21668e628b..e04fd4c8e91c 100644 --- a/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-5.0/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Program.cs diff --git a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..8db75f2dafd6 --- /dev/null +++ b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-5.0/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/.openapi-generator/FILES index fe6225de0b22..5813de3b53b5 100644 --- a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Org.OpenAPITools.csproj diff --git a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Controllers/FakeApi.cs index 155edd3e86fb..6dd12a5fd682 100644 --- a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonSerializer.Deserialize(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..18d3b5347c20 --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,138 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using System.Text.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + var options = new JsonSerializerOptions + { + WriteIndented = true + }; + + return JsonSerializer.Serialize(this, options); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-6.0-NewtonsoftFalse/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/.openapi-generator/FILES index fe6225de0b22..5813de3b53b5 100644 --- a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Org.OpenAPITools.csproj diff --git a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..c07abecc09aa --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string? Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string? NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-6.0-nullableReferenceTypes/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-6.0-pocoModels/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0-pocoModels/.openapi-generator/FILES index fe6225de0b22..5813de3b53b5 100644 --- a/samples/server/petstore/aspnetcore-6.0-pocoModels/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0-pocoModels/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Org.OpenAPITools.csproj diff --git a/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..f2b9c2ebe477 --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,42 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + } +} diff --git a/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-6.0-pocoModels/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-6.0-project4Models/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0-project4Models/.openapi-generator/FILES index 2836933eb2c5..2f0226d29bc8 100644 --- a/samples/server/petstore/aspnetcore-6.0-project4Models/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0-project4Models/.openapi-generator/FILES @@ -14,6 +14,7 @@ src/Org.OpenAPITools.Models/Org.OpenAPITools.Models.csproj src/Org.OpenAPITools.Models/Pet.cs src/Org.OpenAPITools.Models/Tag.cs src/Org.OpenAPITools.Models/TestEnum.cs +src/Org.OpenAPITools.Models/TestNullable.cs src/Org.OpenAPITools.Models/User.cs src/Org.OpenAPITools/.gitignore src/Org.OpenAPITools/Attributes/ValidateModelStateAttribute.cs diff --git a/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools.Models/TestNullable.cs b/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools.Models/TestNullable.cs new file mode 100644 index 000000000000..8db75f2dafd6 --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools.Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-6.0-project4Models/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : { diff --git a/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/.openapi-generator/FILES index 7d45629430c5..8da23f0cd090 100644 --- a/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/.openapi-generator/FILES @@ -21,6 +21,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Org.OpenAPITools.csproj diff --git a/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Controllers/FakeApi.cs index 07c44c861432..d1cc02582f7b 100644 --- a/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -25,6 +25,16 @@ namespace Org.OpenAPITools.Controllers [ApiController] public abstract class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [ProducesResponseType(statusCode: 200, type: typeof(TestNullable))] + public abstract IActionResult FakeNullableExampleTest(); + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..d61290a27c67 --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0-useSwashBuckle/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES b/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES index fe6225de0b22..5813de3b53b5 100644 --- a/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES +++ b/samples/server/petstore/aspnetcore-6.0/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Models/Order.cs src/Org.OpenAPITools/Models/Pet.cs src/Org.OpenAPITools/Models/Tag.cs src/Org.OpenAPITools/Models/TestEnum.cs +src/Org.OpenAPITools/Models/TestNullable.cs src/Org.OpenAPITools/Models/User.cs src/Org.OpenAPITools/OpenApi/TypeExtensions.cs src/Org.OpenAPITools/Org.OpenAPITools.csproj diff --git a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs index 8e36c8d2be18..a0f2bd3b2315 100644 --- a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs +++ b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Controllers/FakeApi.cs @@ -28,6 +28,30 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class FakeApiController : ControllerBase { + /// + /// Fake endpoint to test nullable example (object) + /// + /// Successful operation + [HttpGet] + [Route("/v2/fake/nullable_example_test")] + [ValidateModelState] + [SwaggerOperation("FakeNullableExampleTest")] + [SwaggerResponse(statusCode: 200, type: typeof(TestNullable), description: "Successful operation")] + public virtual IActionResult FakeNullableExampleTest() + { + + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(TestNullable)); + string exampleJson = null; + exampleJson = "{\n \"nullableName\" : \"nullableName\",\n \"name\" : \"name\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(TestNullable); + //TODO: Change the data returned + return new ObjectResult(example); + } + /// /// fake endpoint to test parameter example (object) /// diff --git a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Models/TestNullable.cs b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Models/TestNullable.cs new file mode 100644 index 000000000000..8db75f2dafd6 --- /dev/null +++ b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/Models/TestNullable.cs @@ -0,0 +1,133 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Linq; +using System.Text; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Org.OpenAPITools.Converters; + +namespace Org.OpenAPITools.Models +{ + /// + /// + /// + [DataContract] + public partial class TestNullable : IEquatable + { + /// + /// Gets or Sets Name + /// + [DataMember(Name="name", EmitDefaultValue=false)] + public string Name { get; set; } + + /// + /// Gets or Sets NullableName + /// + [DataMember(Name="nullableName", EmitDefaultValue=true)] + public string NullableName { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class TestNullable {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" NullableName: ").Append(NullableName).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((TestNullable)obj); + } + + /// + /// Returns true if TestNullable instances are equal + /// + /// Instance of TestNullable to be compared + /// Boolean + public bool Equals(TestNullable other) + { + if (other is null) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + NullableName == other.NullableName || + NullableName != null && + NullableName.Equals(other.NullableName) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (NullableName != null) + hashCode = hashCode * 59 + NullableName.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(TestNullable left, TestNullable right) + { + return Equals(left, right); + } + + public static bool operator !=(TestNullable left, TestNullable right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json index a117e88378f6..b47dce3d2c68 100644 --- a/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore-6.0/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -812,6 +812,26 @@ "summary" : "fake endpoint to test parameter example (object)", "tags" : [ "fake" ] } + }, + "/fake/nullable_example_test" : { + "get" : { + "description" : "", + "operationId" : "fake_nullable_example_test", + "responses" : { + "200" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TestNullable" + } + } + }, + "description" : "Successful operation" + } + }, + "summary" : "Fake endpoint to test nullable example (object)", + "tags" : [ "fake" ] + } } }, "components" : { @@ -852,6 +872,22 @@ "enum" : [ "A", "B" ], "type" : "string" }, + "TestNullable" : { + "example" : { + "nullableName" : "nullableName", + "name" : "name" + }, + "properties" : { + "name" : { + "type" : "string" + }, + "nullableName" : { + "nullable" : true, + "type" : "string" + } + }, + "type" : "object" + }, "Order" : { "description" : "An order for a pets from the pet store", "example" : {