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 3efd312e703a..ab6941032e26 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 @@ -34,16 +34,19 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen { + public static final String USE_SWASHBUCKLE = "useSwashbuckle"; + private String packageGuid = "{" + randomUUID().toString().toUpperCase() + "}"; @SuppressWarnings("hiding") protected Logger LOGGER = LoggerFactory.getLogger(AspNetCoreServerCodegen.class); + private boolean useSwashbuckle = true; + public AspNetCoreServerCodegen() { super(); - setSourceFolder("src"); - outputFolder = "generated-code" + File.separator + this.getName(); + outputFolder = "generated-code" + File.separator + getName(); modelTemplateFiles.put("model.mustache", ".cs"); apiTemplateFiles.put("controller.mustache", ".cs"); @@ -59,11 +62,11 @@ public AspNetCoreServerCodegen() { // CLI options addOption(CodegenConstants.PACKAGE_NAME, "C# package name (convention: Title.Case).", - this.packageName); + packageName); addOption(CodegenConstants.PACKAGE_VERSION, "C# package version.", - this.packageVersion); + packageVersion); addOption(CodegenConstants.OPTIONAL_PROJECT_GUID, CodegenConstants.OPTIONAL_PROJECT_GUID_DESC, @@ -76,19 +79,23 @@ public AspNetCoreServerCodegen() { // CLI Switches addSwitch(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC, - this.sortParamsByRequiredFlag); + sortParamsByRequiredFlag); addSwitch(CodegenConstants.USE_DATETIME_OFFSET, CodegenConstants.USE_DATETIME_OFFSET_DESC, - this.useDateTimeOffsetFlag); + useDateTimeOffsetFlag); addSwitch(CodegenConstants.USE_COLLECTION, CodegenConstants.USE_COLLECTION_DESC, - this.useCollection); + useCollection); addSwitch(CodegenConstants.RETURN_ICOLLECTION, CodegenConstants.RETURN_ICOLLECTION_DESC, - this.returnICollection); + returnICollection); + + addSwitch(USE_SWASHBUCKLE, + "Uses the Swashbuckle.AspNetCore NuGet package for documentation.", + useSwashbuckle); } @Override @@ -115,7 +122,13 @@ public void processOpts() { } additionalProperties.put("packageGuid", packageGuid); - additionalProperties.put("dockerTag", this.packageName.toLowerCase()); + if (additionalProperties.containsKey(USE_SWASHBUCKLE)) { + useSwashbuckle = convertPropertyToBooleanAndWriteBack(USE_SWASHBUCKLE); + } else { + additionalProperties.put(USE_SWASHBUCKLE, useSwashbuckle); + } + + additionalProperties.put("dockerTag", packageName.toLowerCase()); apiPackage = packageName + ".Controllers"; modelPackage = packageName + ".Models"; @@ -125,7 +138,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("build.sh.mustache", "", "build.sh")); supportingFiles.add(new SupportingFile("build.bat.mustache", "", "build.bat")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - supportingFiles.add(new SupportingFile("Solution.mustache", "", this.packageName + ".sln")); + supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln")); supportingFiles.add(new SupportingFile("Dockerfile.mustache", packageFolder, "Dockerfile")); supportingFiles.add(new SupportingFile("gitignore", packageFolder, ".gitignore")); supportingFiles.add(new SupportingFile("appsettings.json", packageFolder, "appsettings.json")); @@ -135,12 +148,14 @@ public void processOpts() { supportingFiles.add(new SupportingFile("validateModel.mustache", packageFolder + File.separator + "Attributes", "ValidateModelStateAttribute.cs")); supportingFiles.add(new SupportingFile("web.config", packageFolder, "web.config")); - supportingFiles.add(new SupportingFile("Project.csproj.mustache", packageFolder, this.packageName + ".csproj")); + supportingFiles.add(new SupportingFile("Project.csproj.mustache", packageFolder, packageName + ".csproj")); supportingFiles.add(new SupportingFile("Properties" + File.separator + "launchSettings.json", packageFolder + File.separator + "Properties", "launchSettings.json")); - supportingFiles.add(new SupportingFile("Filters" + File.separator + "BasePathFilter.mustache", packageFolder + File.separator + "Filters", "BasePathFilter.cs")); - supportingFiles.add(new SupportingFile("Filters" + File.separator + "GeneratePathParamsValidationFilter.mustache", packageFolder + File.separator + "Filters", "GeneratePathParamsValidationFilter.cs")); + if (useSwashbuckle) { + supportingFiles.add(new SupportingFile("Filters" + File.separator + "BasePathFilter.mustache", packageFolder + File.separator + "Filters", "BasePathFilter.cs")); + supportingFiles.add(new SupportingFile("Filters" + File.separator + "GeneratePathParamsValidationFilter.mustache", packageFolder + File.separator + "Filters", "GeneratePathParamsValidationFilter.cs")); + } supportingFiles.add(new SupportingFile("wwwroot" + File.separator + "README.md", packageFolder + File.separator + "wwwroot", "README.md")); supportingFiles.add(new SupportingFile("wwwroot" + File.separator + "index.html", packageFolder + File.separator + "wwwroot", "index.html")); @@ -149,19 +164,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile("wwwroot" + File.separator + "openapi-original.mustache", packageFolder + File.separator + "wwwroot", "openapi-original.json")); } - @Override - public void setSourceFolder(final String sourceFolder) { - if (sourceFolder == null) { - LOGGER.warn("No sourceFolder specified, using default"); - this.sourceFolder = "src" + File.separator + this.packageName; - } else if (!sourceFolder.equals("src") && !sourceFolder.startsWith("src")) { - LOGGER.warn("ASP.NET Core requires source code exists under src. Adjusting."); - this.sourceFolder = "src" + File.separator + sourceFolder; - } else { - this.sourceFolder = sourceFolder; - } - } - public void setPackageGuid(String packageGuid) { this.packageGuid = packageGuid; } @@ -176,14 +178,12 @@ public String modelFileFolder() { return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + "Models"; } - @Override public Map postProcessSupportingFileData(Map objs) { generateJSONSpecFile(objs); return super.postProcessSupportingFileData(objs); } - @Override protected void processOperation(CodegenOperation operation) { super.processOperation(operation); diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/Filters/BasePathFilter.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/Filters/BasePathFilter.mustache index bc76e3accc6f..a3e1b9ce0804 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/Filters/BasePathFilter.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/Filters/BasePathFilter.mustache @@ -32,15 +32,15 @@ namespace {{packageName}}.Filters /// FilterContext public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context) { - swaggerDoc.BasePath = this.BasePath; + swaggerDoc.BasePath = BasePath; - var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(this.BasePath)).ToList(); + var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList(); foreach (var path in pathsToModify) { - if (path.Key.StartsWith(this.BasePath)) + if (path.Key.StartsWith(BasePath)) { - string newKey = Regex.Replace(path.Key, $"^{this.BasePath}", string.Empty); + string newKey = Regex.Replace(path.Key, $"^{BasePath}", string.Empty); swaggerDoc.Paths.Remove(path.Key); swaggerDoc.Paths.Add(newKey, path.Value); } diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/Program.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/Program.mustache index 52fdd13d0522..b71c858489d3 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/Program.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/Program.mustache @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore; namespace {{packageName}} diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/Project.csproj.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/Project.csproj.mustache index 76d664abe284..252d955829a0 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/Project.csproj.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/Project.csproj.mustache @@ -9,8 +9,8 @@ {{packageName}} - - + {{#useSwashbuckle}} + {{/useSwashbuckle}} diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/README.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/README.mustache index 03f23c1916ad..71c4cfebb8b3 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/README.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/README.mustache @@ -21,7 +21,7 @@ build.bat ## Run in Docker ``` -cd src/{{packageName}} +cd {{sourceFolder}}/{{packageName}} docker build -t {{dockerTag}} . docker run -p 5000:5000 {{dockerTag}} ``` diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/Solution.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/Solution.mustache index d4c53c66b817..8c6d69ea93da 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/Solution.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/Solution.mustache @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27428.2043 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{packageName}}", "src\{{packageName}}\{{packageName}}.csproj", "{{packageGuid}}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{packageName}}", "{{sourceFolder}}\{{packageName}}\{{packageName}}.csproj", "{{packageGuid}}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/Startup.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/Startup.mustache index f34e2a6b2557..2a4c1f53cf2a 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/Startup.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/Startup.mustache @@ -5,12 +5,11 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Serialization;{{#useSwashbuckle}} using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; -using {{packageName}}.Filters; +using {{packageName}}.Filters;{{/useSwashbuckle}} namespace {{packageName}} { @@ -20,8 +19,7 @@ namespace {{packageName}} public class Startup { private readonly IHostingEnvironment _hostingEnv; - - private IConfiguration Configuration { get; } + private readonly IConfiguration _configuration; /// /// Constructor @@ -31,7 +29,7 @@ namespace {{packageName}} public Startup(IHostingEnvironment env, IConfiguration configuration) { _hostingEnv = env; - Configuration = configuration; + _configuration = configuration; } /// @@ -46,10 +44,11 @@ namespace {{packageName}} .AddJsonOptions(opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - opts.SerializerSettings.Converters.Add(new StringEnumConverter { + opts.SerializerSettings.Converters.Add(new StringEnumConverter + { CamelCaseText = true }); - }); + });{{#useSwashbuckle}} services .AddSwaggerGen(c => @@ -78,21 +77,19 @@ 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}} } /// /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// /// - /// - /// - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + public void Configure(IApplicationBuilder app) { app .UseMvc() .UseDefaultFiles() - .UseStaticFiles() + .UseStaticFiles(){{#useSwashbuckle}} .UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/openapi.json"; @@ -104,9 +101,9 @@ namespace {{packageName}} //TODO: Or alternatively use the original Swagger contract that's included in the static files // c.SwaggerEndpoint("/openapi-original.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}} Original"); - }); + }){{/useSwashbuckle}}; - if (env.IsDevelopment()) + if (_hostingEnv.IsDevelopment()) { app.UseDeveloperExceptionPage(); } diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/build.bat.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/build.bat.mustache index c58e018bee39..e437bccf7d6f 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/build.bat.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/build.bat.mustache @@ -3,7 +3,7 @@ @echo off -dotnet restore src\{{packageName}} -dotnet build src\{{packageName}} -echo Now, run the following to start the project: dotnet run -p src\{{packageName}}\{{packageName}}.csproj --launch-profile web. +dotnet restore {{sourceFolder}}\{{packageName}} +dotnet build {{sourceFolder}}\{{packageName}} +echo Now, run the following to start the project: dotnet run -p {{sourceFolder}}\{{packageName}}\{{packageName}}.csproj --launch-profile web. echo. diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/build.sh.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/build.sh.mustache index 29ee0e0b7ce0..3804359d7e26 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/build.sh.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/build.sh.mustache @@ -3,6 +3,6 @@ # Generated by: https://openapi-generator.tech # -dotnet restore src/{{packageName}}/ && \ - dotnet build src/{{packageName}}/ && \ - echo "Now, run the following to start the project: dotnet run -p src/{{packageName}}/{{packageName}}.csproj --launch-profile web" +dotnet restore {{sourceFolder}}/{{packageName}}/ && \ + dotnet build {{sourceFolder}}/{{packageName}}/ && \ + echo "Now, run the following to start the project: dotnet run -p {{sourceFolder}}/{{packageName}}/{{packageName}}.csproj --launch-profile web" diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/controller.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/controller.mustache index 55e64d7cacf6..ba152878544e 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/controller.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/controller.mustache @@ -1,15 +1,8 @@ {{>partial_header}} using System; using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; -using Swashbuckle.AspNetCore.SwaggerGen; +using Microsoft.AspNetCore.Mvc;{{#useSwashbuckle}} +using Swashbuckle.AspNetCore.SwaggerGen;{{/useSwashbuckle}} using Newtonsoft.Json; using System.ComponentModel.DataAnnotations; using {{packageName}}.Attributes; @@ -25,15 +18,15 @@ namespace {{packageName}}.Controllers { {{#operation}} /// /// {{#summary}}{{summary}}{{/summary}} - /// - {{#notes}}/// {{notes}}{{/notes}}{{#allParams}} + /// {{#notes}} + /// {{notes}}{{/notes}}{{#allParams}} /// {{description}}{{/allParams}}{{#responses}} /// {{message}}{{/responses}} [{{httpMethod}}] [Route("{{{basePathWithoutHost}}}{{{path}}}")] - [ValidateModelState] + [ValidateModelState]{{#useSwashbuckle}} [SwaggerOperation("{{operationId}}")]{{#responses}}{{#dataType}} - [SwaggerResponse(statusCode: {{code}}, type: typeof({{&dataType}}), description: "{{message}}")]{{/dataType}}{{^dataType}}{{/dataType}}{{/responses}} + [SwaggerResponse(statusCode: {{code}}, type: typeof({{&dataType}}), description: "{{message}}")]{{/dataType}}{{^dataType}}{{/dataType}}{{/responses}}{{/useSwashbuckle}} public virtual IActionResult {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#responses}} {{#dataType}} diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/model.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/model.mustache index 3176801f5f89..bae41a3e3bca 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/model.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/model.mustache @@ -1,11 +1,8 @@ {{>partial_header}} using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; 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 512894311829..0be78aacc4fe 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/PetApi.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/PetApi.cs @@ -10,14 +10,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; using Swashbuckle.AspNetCore.SwaggerGen; using Newtonsoft.Json; using System.ComponentModel.DataAnnotations; @@ -34,7 +27,6 @@ public class PetApiController : Controller /// /// Add a new pet to the store /// - /// Pet object that needs to be added to the store /// Invalid input [HttpPost] @@ -53,7 +45,6 @@ public virtual IActionResult AddPet([FromBody]Pet pet) /// /// Deletes a pet /// - /// Pet id to delete /// /// Invalid pet value @@ -170,7 +161,6 @@ public virtual IActionResult GetPetById([FromRoute][Required]long? petId) /// /// Update an existing pet /// - /// Pet object that needs to be added to the store /// Invalid ID supplied /// Pet not found @@ -197,7 +187,6 @@ public virtual IActionResult UpdatePet([FromBody]Pet pet) /// /// Updates a pet in the store with form data /// - /// ID of pet that needs to be updated /// Updated name of the pet /// Updated status of the pet @@ -218,7 +207,6 @@ public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, /// /// uploads an image /// - /// ID of pet to update /// Additional data to pass to server /// file to upload 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 f3ec10fcb7d1..ed5f6e327ee3 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/StoreApi.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/StoreApi.cs @@ -10,14 +10,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; using Swashbuckle.AspNetCore.SwaggerGen; using Newtonsoft.Json; using System.ComponentModel.DataAnnotations; @@ -116,7 +109,6 @@ public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 5)]long /// /// Place an order for a pet /// - /// order placed for purchasing the pet /// successful operation /// Invalid Order 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 5d6952686a3c..463f0d8ecfd0 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/UserApi.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Controllers/UserApi.cs @@ -10,14 +10,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; using Swashbuckle.AspNetCore.SwaggerGen; using Newtonsoft.Json; using System.ComponentModel.DataAnnotations; @@ -53,7 +46,6 @@ public virtual IActionResult CreateUser([FromBody]User user) /// /// Creates list of users with given input array /// - /// List of user object /// successful operation [HttpPost] @@ -72,7 +64,6 @@ public virtual IActionResult CreateUsersWithArrayInput([FromBody]List user /// /// Creates list of users with given input array /// - /// List of user object /// successful operation [HttpPost] @@ -114,7 +105,6 @@ public virtual IActionResult DeleteUser([FromRoute][Required]string username) /// /// Get user by user name /// - /// The name that needs to be fetched. Use user1 for testing. /// successful operation /// Invalid username supplied @@ -149,7 +139,6 @@ public virtual IActionResult GetUserByName([FromRoute][Required]string username) /// /// Logs user into the system /// - /// The user name for login /// The password for login in clear text /// successful operation @@ -179,7 +168,6 @@ public virtual IActionResult LoginUser([FromQuery][Required()]string username, [ /// /// Logs out current logged in user session /// - /// successful operation [HttpGet] [Route("/v2/user/logout")] diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Filters/BasePathFilter.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Filters/BasePathFilter.cs index 7a3796aa24de..5caf40966680 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Filters/BasePathFilter.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Filters/BasePathFilter.cs @@ -32,15 +32,15 @@ public BasePathFilter(string basePath) /// FilterContext public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context) { - swaggerDoc.BasePath = this.BasePath; + swaggerDoc.BasePath = BasePath; - var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(this.BasePath)).ToList(); + var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList(); foreach (var path in pathsToModify) { - if (path.Key.StartsWith(this.BasePath)) + if (path.Key.StartsWith(BasePath)) { - string newKey = Regex.Replace(path.Key, $"^{this.BasePath}", string.Empty); + string newKey = Regex.Replace(path.Key, $"^{BasePath}", string.Empty); swaggerDoc.Paths.Remove(path.Key); swaggerDoc.Paths.Add(newKey, path.Value); } diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/ApiResponse.cs index 9c1fd2dd7830..c5937000ae8b 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/ApiResponse.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/ApiResponse.cs @@ -10,11 +10,8 @@ using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Category.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Category.cs index be0ddd5c0ecd..5c58d5fd4613 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Category.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Category.cs @@ -10,11 +10,8 @@ using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Order.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Order.cs index 137c80fb78bc..4f21cb7268d2 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Order.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Order.cs @@ -10,11 +10,8 @@ using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; 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 fc0ef0687b4c..d3e6dbc5dcd1 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Pet.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Pet.cs @@ -10,11 +10,8 @@ using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Tag.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Tag.cs index 67cbb5b3c768..cc9916d4392a 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Tag.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/Tag.cs @@ -10,11 +10,8 @@ using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/User.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/User.cs index ceeff06b2b62..2fb42e7ab8d5 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/User.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Models/User.cs @@ -10,11 +10,8 @@ using System; using System.Linq; -using System.IO; using System.Text; -using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Program.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Program.cs index 64e875c2b869..d4fb205bacd8 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Program.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Program.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore; namespace Org.OpenAPITools diff --git a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Startup.cs b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Startup.cs index 05d5ff5bee11..4f76c4ed6d1c 100644 --- a/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Startup.cs +++ b/samples/server/petstore/aspnetcore/src/Org.OpenAPITools/Startup.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; using Swashbuckle.AspNetCore.Swagger; @@ -29,8 +28,7 @@ namespace Org.OpenAPITools public class Startup { private readonly IHostingEnvironment _hostingEnv; - - private IConfiguration Configuration { get; } + private readonly IConfiguration _configuration; /// /// Constructor @@ -40,7 +38,7 @@ public class Startup public Startup(IHostingEnvironment env, IConfiguration configuration) { _hostingEnv = env; - Configuration = configuration; + _configuration = configuration; } /// @@ -55,7 +53,8 @@ public void ConfigureServices(IServiceCollection services) .AddJsonOptions(opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - opts.SerializerSettings.Converters.Add(new StringEnumConverter { + opts.SerializerSettings.Converters.Add(new StringEnumConverter + { CamelCaseText = true }); }); @@ -92,9 +91,7 @@ public void ConfigureServices(IServiceCollection services) /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// /// - /// - /// - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + public void Configure(IApplicationBuilder app) { app .UseMvc() @@ -113,7 +110,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF // c.SwaggerEndpoint("/openapi-original.json", "OpenAPI Petstore Original"); }); - if (env.IsDevelopment()) + if (_hostingEnv.IsDevelopment()) { app.UseDeveloperExceptionPage(); }