diff --git a/bin/aspnetcore-petstore-server.sh b/bin/aspnetcore-petstore-server.sh index 1b25911d14..ec6aa29eed 100755 --- a/bin/aspnetcore-petstore-server.sh +++ b/bin/aspnetcore-petstore-server.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/aspnetcore --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} $@" +ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/aspnetcore/2.1/ -o samples/server/petstore/aspnetcore --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} $@" java $JAVA_OPTS -jar $executable $ags diff --git a/docs/generators/aspnetcore.md b/docs/generators/aspnetcore.md index 64a0b8d9a3..a864c9e702 100644 --- a/docs/generators/aspnetcore.md +++ b/docs/generators/aspnetcore.md @@ -28,6 +28,6 @@ sidebar_label: aspnetcore |operationModifier|Operation Modifier can be virtual, abstract or partial| |virtual| |buildTarget|Target to build an application or library| |program| |generateBody|Generates method body.| |true| -|operationIsAsync|Set methods to async or sync.| |false| +|operationIsAsync|Set methods to async or sync (default).| |false| |operationResultTask|Set methods result to Task<>.| |false| |modelClassModifier|Model Class Modifier can be nothing or partial| |partial| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java index 962da0f3d9..85d6f7a60d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java @@ -142,9 +142,9 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen { addOption(COMPATIBILITY_VERSION, "ASP.Net Core CompatibilityVersion", compatibilityVersion); - aspnetCoreVersion.addEnum("2.0", "ASP.NET COre V2.0"); - aspnetCoreVersion.addEnum("2.1", "ASP.NET COre V2.1"); - aspnetCoreVersion.addEnum("2.2", "ASP.NET COre V2.2"); + aspnetCoreVersion.addEnum("2.0", "ASP.NET COre 2.0"); + aspnetCoreVersion.addEnum("2.1", "ASP.NET Core 2.1"); + aspnetCoreVersion.addEnum("2.2", "ASP.NET Core 2.2"); aspnetCoreVersion.setDefault("2.2"); aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault()); addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue()); @@ -180,13 +180,13 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen { classModifier.setOptValue(classModifier.getDefault()); addOption(classModifier.getOpt(), classModifier.getDescription(), classModifier.getOptValue()); - operationModifier.addEnum("virtual", "Keep method virtual "); + operationModifier.addEnum("virtual", "Keep method virtual"); operationModifier.addEnum("abstract", "Make method abstract"); operationModifier.setDefault("virtual"); operationModifier.setOptValue(operationModifier.getDefault()); addOption(operationModifier.getOpt(), operationModifier.getDescription(), operationModifier.getOptValue()); - buildTarget.addEnum("program", "Generate code for standalone server"); + buildTarget.addEnum("program", "Generate code for a standalone server"); buildTarget.addEnum("library", "Generate code for a server abstract class lbrary"); buildTarget.setDefault("program"); buildTarget.setOptValue(buildTarget.getDefault()); @@ -197,7 +197,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen { generateBody); addSwitch(OPERATION_IS_ASYNC, - "Set methods to async or sync.", + "Set methods to async or sync (default).", operationIsAsync); addSwitch(OPERATION_RESULT_TASK, diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.0/controller.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.0/controller.mustache index ba15287854..afb6b08edd 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.0/controller.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.0/controller.mustache @@ -1,8 +1,10 @@ {{>partial_header}} using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc;{{#useSwashbuckle}} -using Swashbuckle.AspNetCore.SwaggerGen;{{/useSwashbuckle}} +using Microsoft.AspNetCore.Mvc; +{{#useSwashbuckle}} +using Swashbuckle.AspNetCore.SwaggerGen; +{{/useSwashbuckle}} using Newtonsoft.Json; using System.ComponentModel.DataAnnotations; using {{packageName}}.Attributes; diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache index 670e24f413..8cbfaf0efd 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache @@ -92,6 +92,7 @@ namespace {{packageName}}.Models ( {{name}} == other.{{name}} || {{name}} != null && + other.{{name}} != null && {{name}}.SequenceEqual(other.{{name}}) ){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}}; } diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache index f7d0e08493..3352c113c4 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache @@ -44,7 +44,7 @@ namespace {{packageName}} services .AddMvc() {{#compatibilityVersion}} - .SetCompatibilityVersion (CompatibilityVersion.{{compatibilityVersion}}) + .SetCompatibilityVersion(CompatibilityVersion.{{compatibilityVersion}}) {{/compatibilityVersion}} .AddJsonOptions(opts => { @@ -53,7 +53,8 @@ namespace {{packageName}} { CamelCaseText = true }); - });{{#useSwashbuckle}} + }); + {{#useSwashbuckle}} services .AddSwaggerGen(c => @@ -82,7 +83,8 @@ namespace {{packageName}} // Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..) // Use [ValidateModelState] on Actions to actually validate it in C# as well! c.OperationFilter(); - });{{/useSwashbuckle}} + }); + {{/useSwashbuckle}} } /// @@ -109,7 +111,7 @@ namespace {{packageName}} // c.SwaggerEndpoint("/openapi-original.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}} Original"); }){{/useSwashbuckle}}; -if (env.IsDevelopment()) + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/controller.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/controller.mustache index eb6430150c..dec27299ff 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/controller.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/controller.mustache @@ -1,12 +1,17 @@ {{>partial_header}} using System; -using System.Collections.Generic;{{#operationResultTask}} +using System.Collections.Generic; +{{#operationResultTask}} using System.Threading.Tasks; {{/operationResultTask}} -using Microsoft.AspNetCore.Mvc;{{#useSwashbuckle}} +using Microsoft.AspNetCore.Mvc; +{{#useSwashbuckle}} using Swashbuckle.AspNetCore.Annotations; -using Swashbuckle.AspNetCore.SwaggerGen;{{/useSwashbuckle}}{{^isLibrary}} -using Newtonsoft.Json;{{/isLibrary}} +using Swashbuckle.AspNetCore.SwaggerGen; +{{/useSwashbuckle}} +{{^isLibrary}} +using Newtonsoft.Json; +{{/isLibrary}} using System.ComponentModel.DataAnnotations; using {{packageName}}.Attributes; using {{modelPackage}}; diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache index ee6e5e2db7..0083aee398 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache @@ -15,7 +15,7 @@ namespace {{modelPackage}} /// {{description}} /// [DataContract] - public {{#modelClassModifier}}{{modelClassModifier}} {{/modelClassModifier}} class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}> + public {{#modelClassModifier}}{{modelClassModifier}} {{/modelClassModifier}}class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}> { {{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{>enumClass}}{{/items}}{{/items.isEnum}} /// /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} @@ -92,6 +92,7 @@ namespace {{modelPackage}} ( {{name}} == other.{{name}} || {{name}} != null && + other.{{name}} != null && {{name}}.SequenceEqual(other.{{name}}) ){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}}; } diff --git a/samples/server/petstore/aspnetcore/README.md b/samples/server/petstore/aspnetcore/README.md index bd8a4c3ffb..83c46e8a52 100644 --- a/samples/server/petstore/aspnetcore/README.md +++ b/samples/server/petstore/aspnetcore/README.md @@ -15,7 +15,6 @@ Windows: ``` build.bat ``` - ## Run in Docker ``` diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/PetApi.cs index 8a0d855e30..d4f1c50554 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/PetApi.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/PetApi.cs @@ -23,7 +23,8 @@ namespace Org.OpenAPITools.Controllers /// /// /// - public class PetApiController : ControllerBase + [ApiController] + public class PetApiController : ControllerBase { /// /// Add a new pet to the store diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/StoreApi.cs index d6e4720d4c..6ed7b79c84 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/StoreApi.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/StoreApi.cs @@ -23,7 +23,8 @@ namespace Org.OpenAPITools.Controllers /// /// /// - public class StoreApiController : ControllerBase + [ApiController] + public class StoreApiController : ControllerBase { /// /// Delete purchase order by ID diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/UserApi.cs index 01f3ade7a5..99a13ef744 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/UserApi.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/UserApi.cs @@ -23,7 +23,8 @@ namespace Org.OpenAPITools.Controllers /// /// /// - public class UserApiController : ControllerBase + [ApiController] + public class UserApiController : ControllerBase { /// /// Create user diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Pet.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Pet.cs index ddb23c6d92..302b17551d 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Pet.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Pet.cs @@ -158,11 +158,13 @@ namespace Org.OpenAPITools.Models ( PhotoUrls == other.PhotoUrls || PhotoUrls != null && + other.PhotoUrls != null && PhotoUrls.SequenceEqual(other.PhotoUrls) ) && ( Tags == other.Tags || Tags != null && + other.Tags != null && Tags.SequenceEqual(other.Tags) ) && ( diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/wwwroot/openapi-original.json b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/wwwroot/openapi-original.json index b39e24282f..a0a4803cd0 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/wwwroot/openapi-original.json +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/wwwroot/openapi-original.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] } } } ],