diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java index c72a844e056..4535115ef1c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java @@ -35,7 +35,7 @@ public class CodegenOperation { public ExternalDocs externalDocs; public Map vendorExtensions; public String nickname; // legacy support - public String operationIdLowerCase; // for mardown documentation + public String operationIdLowerCase; // for markdown documentation public String operationIdCamelCase; // for class names /** diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java index 692c0004cac..80c1cbbbf41 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java @@ -114,6 +114,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen { supportingFiles.add(new SupportingFile("project.json.mustache", packageFolder, "project.json")); supportingFiles.add(new SupportingFile("Startup.mustache", packageFolder, "Startup.cs")); supportingFiles.add(new SupportingFile("Program.mustache", packageFolder, "Program.cs")); + 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.xproj.mustache", packageFolder, this.packageName + ".xproj")); diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/Dockerfile.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/Dockerfile.mustache index 6e42c14542a..553d5ce5ce9 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/Dockerfile.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/Dockerfile.mustache @@ -2,9 +2,8 @@ FROM microsoft/dotnet:1.0.3-sdk-projectjson ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 -RUN mkdir -p /app/{{packageName}} -COPY . /app/{{packageName}} WORKDIR /app/{{packageName}} +COPY . /app/{{packageName}} EXPOSE 5000/tcp diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/Program.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/Program.mustache index ab465c42516..7e6a12ed022 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/Program.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/Program.mustache @@ -1,15 +1,17 @@ -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Builder; namespace {{packageName}} { + /// + /// Program + /// public class Program { + /// + /// Main + /// + /// public static void Main(string[] args) { var host = new WebHostBuilder() diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/Properties/launchSettings.json b/modules/swagger-codegen/src/main/resources/aspnetcore/Properties/launchSettings.json index 45a5f3319a5..21acfed207b 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/Properties/launchSettings.json +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/Properties/launchSettings.json @@ -11,7 +11,7 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "swagger/ui/index.html", + "launchUrl": "swagger/", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -19,7 +19,7 @@ "web": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "http://localhost:5000/swagger/ui/index.html", + "launchUrl": "http://localhost:5000/swagger/", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache index 80709bd068f..cb3a3bb9288 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache @@ -1,27 +1,31 @@ {{>partial_header}} using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; -using System.Xml.XPath; 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 Swashbuckle.Swagger.Model; -using Swashbuckle.SwaggerGen.Annotations; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; namespace {{packageName}} { + /// + /// Startup + /// public class Startup { private readonly IHostingEnvironment _hostingEnv; - public IConfigurationRoot Configuration { get; } + private IConfigurationRoot Configuration { get; } + /// + /// Constructor + /// + /// public Startup(IHostingEnvironment env) { _hostingEnv = env; @@ -33,49 +37,60 @@ namespace {{packageName}} .AddEnvironmentVariables(); Configuration = builder.Build(); } - - - // This method gets called by the runtime. Use this method to add services to the container. + + /// + /// This method gets called by the runtime. Use this method to add services to the container. + /// + /// public void ConfigureServices(IServiceCollection services) { // Add framework services. - services.AddMvc() - .AddJsonOptions( - opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); - - services.AddSwaggerGen(); - - services.ConfigureSwaggerGen(options => - { - options.SingleApiVersion(new Info + services + .AddMvc() + .AddJsonOptions(opts => { - Version = "v1", - Title = "{{packageName}}", - Description = "{{packageName}} (ASP.NET Core 1.0)" + opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter { + CamelCaseText = true + }); }); - options.DescribeAllEnumsAsStrings(); - - var comments = new XPathDocument($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); - options.OperationFilter(comments); - options.ModelFilter(comments); - }); - + services + .AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new Info + { + Version = "v1", + Title = "{{packageName}}", + Description = "{{packageName}} (ASP.NET Core 1.0)" + }); + c.CustomSchemaIds(type => type.FriendlyId(true)); + c.DescribeAllEnumsAsStrings(); + c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); + }); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + /// + /// 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) { - loggerFactory.AddConsole(Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); + loggerFactory + .AddConsole(Configuration.GetSection("Logging")) + .AddDebug(); - app.UseMvc(); - - app.UseDefaultFiles(); - app.UseStaticFiles(); - - app.UseSwagger(); - app.UseSwaggerUi(); + app + .UseMvc() + .UseDefaultFiles() + .UseStaticFiles() + .UseSwagger() + .UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "{{packageName}}"); + }); } } } diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache index e7cbb54cfda..a6cdff4cdef 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/controller.mustache @@ -1,15 +1,17 @@ {{>partial_header}} using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.IO; 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 Swashbuckle.SwaggerGen.Annotations; +using {{packageName}}.Attributes; using {{packageName}}.Models; namespace {{packageName}}.Controllers @@ -20,7 +22,6 @@ namespace {{packageName}}.Controllers [Description("{{description}}")]{{/description}} public class {{classname}}Controller : Controller { {{#operation}} - /// /// {{#summary}}{{summary}}{{/summary}} /// @@ -29,8 +30,9 @@ namespace {{packageName}}.Controllers /// {{message}}{{/responses}} [{{httpMethod}}] [Route("{{{basePathWithoutHost}}}{{{path}}}")] - [SwaggerOperation("{{operationId}}")]{{#returnType}} - [SwaggerResponse(200, type: typeof({{&returnType}}))]{{/returnType}} + [ValidateModelState] + [SwaggerOperation("{{operationId}}")]{{#responses}}{{#returnType}} + [SwaggerResponse({{code}}, typeof({{&returnType}}), "{{message}}")]{{/returnType}}{{/responses}} public virtual {{#returnType}}IActionResult{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#returnType}} string exampleJson = null; @@ -39,7 +41,7 @@ namespace {{packageName}}.Controllers return new ObjectResult(example);{{/returnType}}{{^returnType}} throw new NotImplementedException();{{/returnType}} } -{{/operation}} + {{/operation}} } {{/operations}} } diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/enumClass.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/enumClass.mustache index 1a5850e28a9..3c1d6e15d6a 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/enumClass.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/enumClass.mustache @@ -3,12 +3,11 @@ /// {{#description}} /// {{{description}}}{{/description}} public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} - { - {{#allowableValues}}{{#enumVars}} + { {{#allowableValues}}{{#enumVars}} /// /// Enum {{name}} for {{{value}}} /// [EnumMember(Value = {{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isFloat}}"{{/isFloat}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isFloat}}"{{/isFloat}})] {{name}}{{#isLong}} = {{{value}}}{{/isLong}}{{#isInteger}} = {{{value}}}{{/isInteger}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} - } \ No newline at end of file + } diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/model.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/model.mustache index 101f85ce13f..71d4ec434e9 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/model.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/model.mustache @@ -6,79 +6,36 @@ 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; {{#models}} {{#model}} namespace {{packageName}}.Models -{ -{{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}} +{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}} /// /// {{description}} /// [DataContract] - public partial class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}} IEquatable<{{classname}}> - { - {{#vars}} - {{#isEnum}} - {{>enumClass}} - {{/isEnum}} - {{#items.isEnum}} - {{#items}} - {{>enumClass}} - {{/items}} - {{/items.isEnum}} - {{/vars}} - {{#vars}} - {{#isEnum}} + public partial 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}} /// {{#description}} /// {{{description}}}{{/description}} + {{#required}} + [Required] + {{/required}} [DataMember(Name="{{baseName}}")] + {{#isEnum}} public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; } {{/isEnum}} - {{/vars}} - - /// - /// Initializes a new instance of the class. - /// -{{#vars}} /// {{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}. -{{/vars}} - public {{classname}}({{#readWriteVars}}{{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}default({{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^-last}}, {{/-last}}{{/readWriteVars}}) - { - {{#vars}}{{#required}}// to ensure "{{name}}" is required (not null) - if ({{name}} == null) - { - throw new InvalidDataException("{{name}} is a required property for {{classname}} and cannot be null"); - } - else - { - this.{{name}} = {{name}}; - } - {{/required}}{{/vars}}{{#vars}}{{^required}}{{#defaultValue}}// use default value if no "{{name}}" provided - if ({{name}} == null) - { - this.{{name}} = {{{defaultValue}}}; - } - else - { - this.{{name}} = {{name}}; - } - {{/defaultValue}}{{^defaultValue}}this.{{name}} = {{name}}; - {{/defaultValue}}{{/required}}{{/vars}} - } - - {{#vars}} {{^isEnum}} - /// - /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} - /// {{#description}} - /// {{description}}{{/description}} - [DataMember(Name="{{baseName}}")] public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; } {{/isEnum}} + {{#hasMore}} + {{/hasMore}} {{/vars}} /// @@ -114,8 +71,7 @@ namespace {{packageName}}.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals(({{classname}})obj); + return obj.GetType() == GetType() && Equals(({{classname}})obj); } /// @@ -125,20 +81,19 @@ namespace {{packageName}}.Models /// Boolean public bool Equals({{classname}} other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return {{#vars}}{{#isNotContainer}} ( - this.{{name}} == other.{{name}} || - this.{{name}} != null && - this.{{name}}.Equals(other.{{name}}) + {{name}} == other.{{name}} || + {{name}} != null && + {{name}}.Equals(other.{{name}}) ){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{^isNotContainer}} ( - this.{{name}} == other.{{name}} || - this.{{name}} != null && - this.{{name}}.SequenceEqual(other.{{name}}) + {{name}} == other.{{name}} || + {{name}} != null && + {{name}}.SequenceEqual(other.{{name}}) ){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}}{{^vars}}false{{/vars}}; } @@ -151,17 +106,18 @@ namespace {{packageName}}.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) {{#vars}} - if (this.{{name}} != null) - hash = hash * 59 + this.{{name}}.GetHashCode(); + if ({{name}} != null) + hash = hash * 59 + {{name}}.GetHashCode(); {{/vars}} return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==({{classname}} left, {{classname}} right) { @@ -173,8 +129,8 @@ namespace {{packageName}}.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } {{/isEnum}} {{/model}} diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/project.json.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/project.json.mustache index 46a9071fde4..e415d80d728 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/project.json.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/project.json.mustache @@ -21,8 +21,7 @@ "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.EntityFrameworkCore": "1.0.0", - "Swashbuckle.SwaggerGen": "6.0.0-beta901", - "Swashbuckle.SwaggerUi": "6.0.0-beta901", + "Swashbuckle.AspNetCore": "1.0.0-rc3", "Newtonsoft.Json": "9.0.1" }, diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/validateModel.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/validateModel.mustache new file mode 100644 index 00000000000..9f850f71d93 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/validateModel.mustache @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace {{packageName}}.Attributes +{ + /// + /// Model state validation attribute + /// + public class ValidateModelStateAttribute : ActionFilterAttribute + { + /// + /// Called before the action method is invoked + /// + /// + public override void OnActionExecuting(ActionExecutingContext context) + { + if (!context.ModelState.IsValid) + { + context.Result = new BadRequestObjectResult(context.ModelState); + } + } + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/wwwroot/index.html b/modules/swagger-codegen/src/main/resources/aspnetcore/wwwroot/index.html index c8c055b34f7..cde1f2f90b9 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/wwwroot/index.html +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/wwwroot/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs new file mode 100644 index 00000000000..d654d2d4ce1 --- /dev/null +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace IO.Swagger.Attributes +{ + /// + /// Model state validation attribute + /// + public class ValidateModelStateAttribute : ActionFilterAttribute + { + /// + /// Called before the action method is invoked. + /// + /// + public override void OnActionExecuting(ActionExecutingContext context) + { + if (!context.ModelState.IsValid) + { + context.Result = new BadRequestObjectResult(context.ModelState); + } + } + } +} \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs index 460192fc3fe..ad5f2d39cec 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/PetApi.cs @@ -10,15 +10,17 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.IO; 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 Swashbuckle.SwaggerGen.Annotations; +using IO.Swagger.Attributes; using IO.Swagger.Models; namespace IO.Swagger.Controllers @@ -28,7 +30,6 @@ namespace IO.Swagger.Controllers /// public class PetApiController : Controller { - /// /// Add a new pet to the store /// @@ -37,13 +38,13 @@ namespace IO.Swagger.Controllers /// Invalid input [HttpPost] [Route("/v2/pet")] + [ValidateModelState] [SwaggerOperation("AddPet")] public virtual void AddPet([FromBody]Pet body) { throw new NotImplementedException(); } - /// /// Deletes a pet /// @@ -53,13 +54,13 @@ namespace IO.Swagger.Controllers /// Invalid pet value [HttpDelete] [Route("/v2/pet/{petId}")] + [ValidateModelState] [SwaggerOperation("DeletePet")] public virtual void DeletePet([FromRoute]long? petId, [FromHeader]string apiKey) { throw new NotImplementedException(); } - /// /// Finds Pets by status /// @@ -69,8 +70,10 @@ namespace IO.Swagger.Controllers /// Invalid status value [HttpGet] [Route("/v2/pet/findByStatus")] + [ValidateModelState] [SwaggerOperation("FindPetsByStatus")] - [SwaggerResponse(200, type: typeof(List))] + [SwaggerResponse(200, typeof(List), "successful operation")] + [SwaggerResponse(400, typeof(List), "Invalid status value")] public virtual IActionResult FindPetsByStatus([FromQuery]List status) { string exampleJson = null; @@ -81,7 +84,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Finds Pets by tags /// @@ -91,8 +93,10 @@ namespace IO.Swagger.Controllers /// Invalid tag value [HttpGet] [Route("/v2/pet/findByTags")] + [ValidateModelState] [SwaggerOperation("FindPetsByTags")] - [SwaggerResponse(200, type: typeof(List))] + [SwaggerResponse(200, typeof(List), "successful operation")] + [SwaggerResponse(400, typeof(List), "Invalid tag value")] public virtual IActionResult FindPetsByTags([FromQuery]List tags) { string exampleJson = null; @@ -103,7 +107,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Find pet by ID /// @@ -114,8 +117,11 @@ namespace IO.Swagger.Controllers /// Pet not found [HttpGet] [Route("/v2/pet/{petId}")] + [ValidateModelState] [SwaggerOperation("GetPetById")] - [SwaggerResponse(200, type: typeof(Pet))] + [SwaggerResponse(200, typeof(Pet), "successful operation")] + [SwaggerResponse(400, typeof(Pet), "Invalid ID supplied")] + [SwaggerResponse(404, typeof(Pet), "Pet not found")] public virtual IActionResult GetPetById([FromRoute]long? petId) { string exampleJson = null; @@ -126,7 +132,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Update an existing pet /// @@ -137,13 +142,13 @@ namespace IO.Swagger.Controllers /// Validation exception [HttpPut] [Route("/v2/pet")] + [ValidateModelState] [SwaggerOperation("UpdatePet")] public virtual void UpdatePet([FromBody]Pet body) { throw new NotImplementedException(); } - /// /// Updates a pet in the store with form data /// @@ -154,13 +159,13 @@ namespace IO.Swagger.Controllers /// Invalid input [HttpPost] [Route("/v2/pet/{petId}")] + [ValidateModelState] [SwaggerOperation("UpdatePetWithForm")] public virtual void UpdatePetWithForm([FromRoute]long? petId, [FromForm]string name, [FromForm]string status) { throw new NotImplementedException(); } - /// /// uploads an image /// @@ -171,8 +176,9 @@ namespace IO.Swagger.Controllers /// successful operation [HttpPost] [Route("/v2/pet/{petId}/uploadImage")] + [ValidateModelState] [SwaggerOperation("UploadFile")] - [SwaggerResponse(200, type: typeof(ApiResponse))] + [SwaggerResponse(200, typeof(ApiResponse), "successful operation")] public virtual IActionResult UploadFile([FromRoute]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream file) { string exampleJson = null; diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs index 467a365679b..0bfb79eb2d2 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/StoreApi.cs @@ -10,15 +10,17 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.IO; 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 Swashbuckle.SwaggerGen.Annotations; +using IO.Swagger.Attributes; using IO.Swagger.Models; namespace IO.Swagger.Controllers @@ -28,7 +30,6 @@ namespace IO.Swagger.Controllers /// public class StoreApiController : Controller { - /// /// Delete purchase order by ID /// @@ -38,13 +39,13 @@ namespace IO.Swagger.Controllers /// Order not found [HttpDelete] [Route("/v2/store/order/{orderId}")] + [ValidateModelState] [SwaggerOperation("DeleteOrder")] public virtual void DeleteOrder([FromRoute]string orderId) { throw new NotImplementedException(); } - /// /// Returns pet inventories by status /// @@ -52,8 +53,9 @@ namespace IO.Swagger.Controllers /// successful operation [HttpGet] [Route("/v2/store/inventory")] + [ValidateModelState] [SwaggerOperation("GetInventory")] - [SwaggerResponse(200, type: typeof(Dictionary))] + [SwaggerResponse(200, typeof(Dictionary), "successful operation")] public virtual IActionResult GetInventory() { string exampleJson = null; @@ -64,7 +66,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Find purchase order by ID /// @@ -75,8 +76,11 @@ namespace IO.Swagger.Controllers /// Order not found [HttpGet] [Route("/v2/store/order/{orderId}")] + [ValidateModelState] [SwaggerOperation("GetOrderById")] - [SwaggerResponse(200, type: typeof(Order))] + [SwaggerResponse(200, typeof(Order), "successful operation")] + [SwaggerResponse(400, typeof(Order), "Invalid ID supplied")] + [SwaggerResponse(404, typeof(Order), "Order not found")] public virtual IActionResult GetOrderById([FromRoute]long? orderId) { string exampleJson = null; @@ -87,7 +91,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Place an order for a pet /// @@ -97,8 +100,10 @@ namespace IO.Swagger.Controllers /// Invalid Order [HttpPost] [Route("/v2/store/order")] + [ValidateModelState] [SwaggerOperation("PlaceOrder")] - [SwaggerResponse(200, type: typeof(Order))] + [SwaggerResponse(200, typeof(Order), "successful operation")] + [SwaggerResponse(400, typeof(Order), "Invalid Order")] public virtual IActionResult PlaceOrder([FromBody]Order body) { string exampleJson = null; diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs index c01db365593..aaa5d027c5d 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Controllers/UserApi.cs @@ -10,15 +10,17 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.IO; 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 Swashbuckle.SwaggerGen.Annotations; +using IO.Swagger.Attributes; using IO.Swagger.Models; namespace IO.Swagger.Controllers @@ -28,7 +30,6 @@ namespace IO.Swagger.Controllers /// public class UserApiController : Controller { - /// /// Create user /// @@ -37,13 +38,13 @@ namespace IO.Swagger.Controllers /// successful operation [HttpPost] [Route("/v2/user")] + [ValidateModelState] [SwaggerOperation("CreateUser")] public virtual void CreateUser([FromBody]User body) { throw new NotImplementedException(); } - /// /// Creates list of users with given input array /// @@ -52,13 +53,13 @@ namespace IO.Swagger.Controllers /// successful operation [HttpPost] [Route("/v2/user/createWithArray")] + [ValidateModelState] [SwaggerOperation("CreateUsersWithArrayInput")] public virtual void CreateUsersWithArrayInput([FromBody]List body) { throw new NotImplementedException(); } - /// /// Creates list of users with given input array /// @@ -67,13 +68,13 @@ namespace IO.Swagger.Controllers /// successful operation [HttpPost] [Route("/v2/user/createWithList")] + [ValidateModelState] [SwaggerOperation("CreateUsersWithListInput")] public virtual void CreateUsersWithListInput([FromBody]List body) { throw new NotImplementedException(); } - /// /// Delete user /// @@ -83,13 +84,13 @@ namespace IO.Swagger.Controllers /// User not found [HttpDelete] [Route("/v2/user/{username}")] + [ValidateModelState] [SwaggerOperation("DeleteUser")] public virtual void DeleteUser([FromRoute]string username) { throw new NotImplementedException(); } - /// /// Get user by user name /// @@ -100,8 +101,11 @@ namespace IO.Swagger.Controllers /// User not found [HttpGet] [Route("/v2/user/{username}")] + [ValidateModelState] [SwaggerOperation("GetUserByName")] - [SwaggerResponse(200, type: typeof(User))] + [SwaggerResponse(200, typeof(User), "successful operation")] + [SwaggerResponse(400, typeof(User), "Invalid username supplied")] + [SwaggerResponse(404, typeof(User), "User not found")] public virtual IActionResult GetUserByName([FromRoute]string username) { string exampleJson = null; @@ -112,7 +116,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Logs user into the system /// @@ -123,8 +126,10 @@ namespace IO.Swagger.Controllers /// Invalid username/password supplied [HttpGet] [Route("/v2/user/login")] + [ValidateModelState] [SwaggerOperation("LoginUser")] - [SwaggerResponse(200, type: typeof(string))] + [SwaggerResponse(200, typeof(string), "successful operation")] + [SwaggerResponse(400, typeof(string), "Invalid username/password supplied")] public virtual IActionResult LoginUser([FromQuery]string username, [FromQuery]string password) { string exampleJson = null; @@ -135,7 +140,6 @@ namespace IO.Swagger.Controllers return new ObjectResult(example); } - /// /// Logs out current logged in user session /// @@ -143,13 +147,13 @@ namespace IO.Swagger.Controllers /// successful operation [HttpGet] [Route("/v2/user/logout")] + [ValidateModelState] [SwaggerOperation("LogoutUser")] public virtual void LogoutUser() { throw new NotImplementedException(); } - /// /// Updated user /// @@ -160,6 +164,7 @@ namespace IO.Swagger.Controllers /// User not found [HttpPut] [Route("/v2/user/{username}")] + [ValidateModelState] [SwaggerOperation("UpdateUser")] public virtual void UpdateUser([FromRoute]string username, [FromBody]User body) { diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Dockerfile b/samples/server/petstore/aspnetcore/src/IO.Swagger/Dockerfile index 54915a5e2a0..66c2e7fdd23 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Dockerfile +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Dockerfile @@ -2,9 +2,8 @@ FROM microsoft/dotnet:1.0.3-sdk-projectjson ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 -RUN mkdir -p /app/IO.Swagger -COPY . /app/IO.Swagger WORKDIR /app/IO.Swagger +COPY . /app/IO.Swagger EXPOSE 5000/tcp diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/ApiResponse.cs index 2782644943b..8724ca9cb93 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/ApiResponse.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/ApiResponse.cs @@ -15,43 +15,30 @@ 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; namespace IO.Swagger.Models -{ - +{ /// /// Describes the result of uploading an image resource /// [DataContract] - public partial class ApiResponse : IEquatable - { - - /// - /// Initializes a new instance of the class. - /// - /// Code. - /// Type. - /// Message. - public ApiResponse(int? Code = default(int?), string Type = default(string), string Message = default(string)) - { - this.Code = Code; - this.Type = Type; - this.Message = Message; - - } - + public partial class ApiResponse : IEquatable + { /// /// Gets or Sets Code /// [DataMember(Name="code")] public int? Code { get; set; } + /// /// Gets or Sets Type /// [DataMember(Name="type")] public string Type { get; set; } + /// /// Gets or Sets Message /// @@ -91,8 +78,7 @@ namespace IO.Swagger.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((ApiResponse)obj); + return obj.GetType() == GetType() && Equals((ApiResponse)obj); } /// @@ -102,25 +88,24 @@ namespace IO.Swagger.Models /// Boolean public bool Equals(ApiResponse other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return ( - this.Code == other.Code || - this.Code != null && - this.Code.Equals(other.Code) + Code == other.Code || + Code != null && + Code.Equals(other.Code) ) && ( - this.Type == other.Type || - this.Type != null && - this.Type.Equals(other.Type) + Type == other.Type || + Type != null && + Type.Equals(other.Type) ) && ( - this.Message == other.Message || - this.Message != null && - this.Message.Equals(other.Message) + Message == other.Message || + Message != null && + Message.Equals(other.Message) ); } @@ -133,19 +118,20 @@ namespace IO.Swagger.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) - if (this.Code != null) - hash = hash * 59 + this.Code.GetHashCode(); - if (this.Type != null) - hash = hash * 59 + this.Type.GetHashCode(); - if (this.Message != null) - hash = hash * 59 + this.Message.GetHashCode(); + if (Code != null) + hash = hash * 59 + Code.GetHashCode(); + if (Type != null) + hash = hash * 59 + Type.GetHashCode(); + if (Message != null) + hash = hash * 59 + Message.GetHashCode(); return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==(ApiResponse left, ApiResponse right) { @@ -157,7 +143,7 @@ namespace IO.Swagger.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Category.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Category.cs index 55a7bcdc113..3be20928258 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Category.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Category.cs @@ -15,36 +15,24 @@ 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; namespace IO.Swagger.Models -{ - +{ /// /// A category for a pet /// [DataContract] - public partial class Category : IEquatable - { - - /// - /// Initializes a new instance of the class. - /// - /// Id. - /// Name. - public Category(long? Id = default(long?), string Name = default(string)) - { - this.Id = Id; - this.Name = Name; - - } - + public partial class Category : IEquatable + { /// /// Gets or Sets Id /// [DataMember(Name="id")] public long? Id { get; set; } + /// /// Gets or Sets Name /// @@ -83,8 +71,7 @@ namespace IO.Swagger.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((Category)obj); + return obj.GetType() == GetType() && Equals((Category)obj); } /// @@ -94,20 +81,19 @@ namespace IO.Swagger.Models /// Boolean public bool Equals(Category other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return ( - this.Id == other.Id || - this.Id != null && - this.Id.Equals(other.Id) + Id == other.Id || + Id != null && + Id.Equals(other.Id) ) && ( - this.Name == other.Name || - this.Name != null && - this.Name.Equals(other.Name) + Name == other.Name || + Name != null && + Name.Equals(other.Name) ); } @@ -120,17 +106,18 @@ namespace IO.Swagger.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) - if (this.Id != null) - hash = hash * 59 + this.Id.GetHashCode(); - if (this.Name != null) - hash = hash * 59 + this.Name.GetHashCode(); + if (Id != null) + hash = hash * 59 + Id.GetHashCode(); + if (Name != null) + hash = hash * 59 + Name.GetHashCode(); return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==(Category left, Category right) { @@ -142,7 +129,7 @@ namespace IO.Swagger.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Order.cs index 7b3d9cf31c7..749dc49dad6 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Order.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Order.cs @@ -15,25 +15,47 @@ 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; namespace IO.Swagger.Models -{ - +{ /// /// An order for a pets from the pet store /// [DataContract] - public partial class Order : IEquatable - { - /// + public partial class Order : IEquatable + { + /// + /// Gets or Sets Id + /// + [DataMember(Name="id")] + public long? Id { get; set; } + + /// + /// Gets or Sets PetId + /// + [DataMember(Name="petId")] + public long? PetId { get; set; } + + /// + /// Gets or Sets Quantity + /// + [DataMember(Name="quantity")] + public int? Quantity { get; set; } + + /// + /// Gets or Sets ShipDate + /// + [DataMember(Name="shipDate")] + public DateTime? ShipDate { get; set; } + /// /// Order Status /// /// Order Status public enum StatusEnum - { - + { /// /// Enum PlacedEnum for "placed" /// @@ -52,6 +74,7 @@ namespace IO.Swagger.Models [EnumMember(Value = "delivered")] DeliveredEnum } + /// /// Order Status /// @@ -59,54 +82,6 @@ namespace IO.Swagger.Models [DataMember(Name="status")] public StatusEnum? Status { get; set; } - /// - /// Initializes a new instance of the class. - /// - /// Id. - /// PetId. - /// Quantity. - /// ShipDate. - /// Order Status. - /// Complete (default to false). - public Order(long? Id = default(long?), long? PetId = default(long?), int? Quantity = default(int?), DateTime? ShipDate = default(DateTime?), StatusEnum? Status = default(StatusEnum?), bool? Complete = false) - { - this.Id = Id; - this.PetId = PetId; - this.Quantity = Quantity; - this.ShipDate = ShipDate; - this.Status = Status; - // use default value if no "Complete" provided - if (Complete == null) - { - this.Complete = false; - } - else - { - this.Complete = Complete; - } - - } - - /// - /// Gets or Sets Id - /// - [DataMember(Name="id")] - public long? Id { get; set; } - /// - /// Gets or Sets PetId - /// - [DataMember(Name="petId")] - public long? PetId { get; set; } - /// - /// Gets or Sets Quantity - /// - [DataMember(Name="quantity")] - public int? Quantity { get; set; } - /// - /// Gets or Sets ShipDate - /// - [DataMember(Name="shipDate")] - public DateTime? ShipDate { get; set; } /// /// Gets or Sets Complete /// @@ -149,8 +124,7 @@ namespace IO.Swagger.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((Order)obj); + return obj.GetType() == GetType() && Equals((Order)obj); } /// @@ -160,40 +134,39 @@ namespace IO.Swagger.Models /// Boolean public bool Equals(Order other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return ( - this.Id == other.Id || - this.Id != null && - this.Id.Equals(other.Id) + Id == other.Id || + Id != null && + Id.Equals(other.Id) ) && ( - this.PetId == other.PetId || - this.PetId != null && - this.PetId.Equals(other.PetId) + PetId == other.PetId || + PetId != null && + PetId.Equals(other.PetId) ) && ( - this.Quantity == other.Quantity || - this.Quantity != null && - this.Quantity.Equals(other.Quantity) + Quantity == other.Quantity || + Quantity != null && + Quantity.Equals(other.Quantity) ) && ( - this.ShipDate == other.ShipDate || - this.ShipDate != null && - this.ShipDate.Equals(other.ShipDate) + ShipDate == other.ShipDate || + ShipDate != null && + ShipDate.Equals(other.ShipDate) ) && ( - this.Status == other.Status || - this.Status != null && - this.Status.Equals(other.Status) + Status == other.Status || + Status != null && + Status.Equals(other.Status) ) && ( - this.Complete == other.Complete || - this.Complete != null && - this.Complete.Equals(other.Complete) + Complete == other.Complete || + Complete != null && + Complete.Equals(other.Complete) ); } @@ -206,25 +179,26 @@ namespace IO.Swagger.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) - if (this.Id != null) - hash = hash * 59 + this.Id.GetHashCode(); - if (this.PetId != null) - hash = hash * 59 + this.PetId.GetHashCode(); - if (this.Quantity != null) - hash = hash * 59 + this.Quantity.GetHashCode(); - if (this.ShipDate != null) - hash = hash * 59 + this.ShipDate.GetHashCode(); - if (this.Status != null) - hash = hash * 59 + this.Status.GetHashCode(); - if (this.Complete != null) - hash = hash * 59 + this.Complete.GetHashCode(); + if (Id != null) + hash = hash * 59 + Id.GetHashCode(); + if (PetId != null) + hash = hash * 59 + PetId.GetHashCode(); + if (Quantity != null) + hash = hash * 59 + Quantity.GetHashCode(); + if (ShipDate != null) + hash = hash * 59 + ShipDate.GetHashCode(); + if (Status != null) + hash = hash * 59 + Status.GetHashCode(); + if (Complete != null) + hash = hash * 59 + Complete.GetHashCode(); return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==(Order left, Order right) { @@ -236,7 +210,7 @@ namespace IO.Swagger.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Pet.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Pet.cs index a6454c61726..f38ce163e13 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Pet.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Pet.cs @@ -15,25 +15,55 @@ 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; namespace IO.Swagger.Models -{ - +{ /// /// A pet for sale in the pet store /// [DataContract] - public partial class Pet : IEquatable - { - /// + public partial class Pet : IEquatable + { + /// + /// Gets or Sets Id + /// + [DataMember(Name="id")] + public long? Id { get; set; } + + /// + /// Gets or Sets Category + /// + [DataMember(Name="category")] + public Category Category { get; set; } + + /// + /// Gets or Sets Name + /// + [Required] + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Gets or Sets PhotoUrls + /// + [Required] + [DataMember(Name="photoUrls")] + public List PhotoUrls { get; set; } + + /// + /// Gets or Sets Tags + /// + [DataMember(Name="tags")] + public List Tags { get; set; } + /// /// pet status in the store /// /// pet status in the store public enum StatusEnum - { - + { /// /// Enum AvailableEnum for "available" /// @@ -52,6 +82,7 @@ namespace IO.Swagger.Models [EnumMember(Value = "sold")] SoldEnum } + /// /// pet status in the store /// @@ -59,68 +90,6 @@ namespace IO.Swagger.Models [DataMember(Name="status")] public StatusEnum? Status { get; set; } - /// - /// Initializes a new instance of the class. - /// - /// Id. - /// Category. - /// Name (required). - /// PhotoUrls (required). - /// Tags. - /// pet status in the store. - public Pet(long? Id = default(long?), Category Category = default(Category), string Name = default(string), List PhotoUrls = default(List), List Tags = default(List), StatusEnum? Status = default(StatusEnum?)) - { - // to ensure "Name" is required (not null) - if (Name == null) - { - throw new InvalidDataException("Name is a required property for Pet and cannot be null"); - } - else - { - this.Name = Name; - } - // to ensure "PhotoUrls" is required (not null) - if (PhotoUrls == null) - { - throw new InvalidDataException("PhotoUrls is a required property for Pet and cannot be null"); - } - else - { - this.PhotoUrls = PhotoUrls; - } - this.Id = Id; - this.Category = Category; - this.Tags = Tags; - this.Status = Status; - - } - - /// - /// Gets or Sets Id - /// - [DataMember(Name="id")] - public long? Id { get; set; } - /// - /// Gets or Sets Category - /// - [DataMember(Name="category")] - public Category Category { get; set; } - /// - /// Gets or Sets Name - /// - [DataMember(Name="name")] - public string Name { get; set; } - /// - /// Gets or Sets PhotoUrls - /// - [DataMember(Name="photoUrls")] - public List PhotoUrls { get; set; } - /// - /// Gets or Sets Tags - /// - [DataMember(Name="tags")] - public List Tags { get; set; } - /// /// Returns the string presentation of the object /// @@ -157,8 +126,7 @@ namespace IO.Swagger.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((Pet)obj); + return obj.GetType() == GetType() && Equals((Pet)obj); } /// @@ -168,40 +136,39 @@ namespace IO.Swagger.Models /// Boolean public bool Equals(Pet other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return ( - this.Id == other.Id || - this.Id != null && - this.Id.Equals(other.Id) + Id == other.Id || + Id != null && + Id.Equals(other.Id) ) && ( - this.Category == other.Category || - this.Category != null && - this.Category.Equals(other.Category) + Category == other.Category || + Category != null && + Category.Equals(other.Category) ) && ( - this.Name == other.Name || - this.Name != null && - this.Name.Equals(other.Name) + Name == other.Name || + Name != null && + Name.Equals(other.Name) ) && ( - this.PhotoUrls == other.PhotoUrls || - this.PhotoUrls != null && - this.PhotoUrls.SequenceEqual(other.PhotoUrls) + PhotoUrls == other.PhotoUrls || + PhotoUrls != null && + PhotoUrls.SequenceEqual(other.PhotoUrls) ) && ( - this.Tags == other.Tags || - this.Tags != null && - this.Tags.SequenceEqual(other.Tags) + Tags == other.Tags || + Tags != null && + Tags.SequenceEqual(other.Tags) ) && ( - this.Status == other.Status || - this.Status != null && - this.Status.Equals(other.Status) + Status == other.Status || + Status != null && + Status.Equals(other.Status) ); } @@ -214,25 +181,26 @@ namespace IO.Swagger.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) - if (this.Id != null) - hash = hash * 59 + this.Id.GetHashCode(); - if (this.Category != null) - hash = hash * 59 + this.Category.GetHashCode(); - if (this.Name != null) - hash = hash * 59 + this.Name.GetHashCode(); - if (this.PhotoUrls != null) - hash = hash * 59 + this.PhotoUrls.GetHashCode(); - if (this.Tags != null) - hash = hash * 59 + this.Tags.GetHashCode(); - if (this.Status != null) - hash = hash * 59 + this.Status.GetHashCode(); + if (Id != null) + hash = hash * 59 + Id.GetHashCode(); + if (Category != null) + hash = hash * 59 + Category.GetHashCode(); + if (Name != null) + hash = hash * 59 + Name.GetHashCode(); + if (PhotoUrls != null) + hash = hash * 59 + PhotoUrls.GetHashCode(); + if (Tags != null) + hash = hash * 59 + Tags.GetHashCode(); + if (Status != null) + hash = hash * 59 + Status.GetHashCode(); return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==(Pet left, Pet right) { @@ -244,7 +212,7 @@ namespace IO.Swagger.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Tag.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Tag.cs index ea2ca1d6c1e..01dbf4cefee 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Tag.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/Tag.cs @@ -15,36 +15,24 @@ 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; namespace IO.Swagger.Models -{ - +{ /// /// A tag for a pet /// [DataContract] - public partial class Tag : IEquatable - { - - /// - /// Initializes a new instance of the class. - /// - /// Id. - /// Name. - public Tag(long? Id = default(long?), string Name = default(string)) - { - this.Id = Id; - this.Name = Name; - - } - + public partial class Tag : IEquatable + { /// /// Gets or Sets Id /// [DataMember(Name="id")] public long? Id { get; set; } + /// /// Gets or Sets Name /// @@ -83,8 +71,7 @@ namespace IO.Swagger.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((Tag)obj); + return obj.GetType() == GetType() && Equals((Tag)obj); } /// @@ -94,20 +81,19 @@ namespace IO.Swagger.Models /// Boolean public bool Equals(Tag other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return ( - this.Id == other.Id || - this.Id != null && - this.Id.Equals(other.Id) + Id == other.Id || + Id != null && + Id.Equals(other.Id) ) && ( - this.Name == other.Name || - this.Name != null && - this.Name.Equals(other.Name) + Name == other.Name || + Name != null && + Name.Equals(other.Name) ); } @@ -120,17 +106,18 @@ namespace IO.Swagger.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) - if (this.Id != null) - hash = hash * 59 + this.Id.GetHashCode(); - if (this.Name != null) - hash = hash * 59 + this.Name.GetHashCode(); + if (Id != null) + hash = hash * 59 + Id.GetHashCode(); + if (Name != null) + hash = hash * 59 + Name.GetHashCode(); return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==(Tag left, Tag right) { @@ -142,7 +129,7 @@ namespace IO.Swagger.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/User.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/User.cs index 54b0a00d989..f0edcb53d47 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/User.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Models/User.cs @@ -15,78 +15,60 @@ 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; namespace IO.Swagger.Models -{ - +{ /// /// A User who is purchasing from the pet store /// [DataContract] - public partial class User : IEquatable - { - - /// - /// Initializes a new instance of the class. - /// - /// Id. - /// Username. - /// FirstName. - /// LastName. - /// Email. - /// Password. - /// Phone. - /// User Status. - public User(long? Id = default(long?), string Username = default(string), string FirstName = default(string), string LastName = default(string), string Email = default(string), string Password = default(string), string Phone = default(string), int? UserStatus = default(int?)) - { - this.Id = Id; - this.Username = Username; - this.FirstName = FirstName; - this.LastName = LastName; - this.Email = Email; - this.Password = Password; - this.Phone = Phone; - this.UserStatus = UserStatus; - - } - + public partial class User : IEquatable + { /// /// Gets or Sets Id /// [DataMember(Name="id")] public long? Id { get; set; } + /// /// Gets or Sets Username /// [DataMember(Name="username")] public string Username { get; set; } + /// /// Gets or Sets FirstName /// [DataMember(Name="firstName")] public string FirstName { get; set; } + /// /// Gets or Sets LastName /// [DataMember(Name="lastName")] public string LastName { get; set; } + /// /// Gets or Sets Email /// [DataMember(Name="email")] public string Email { get; set; } + /// /// Gets or Sets Password /// [DataMember(Name="password")] public string Password { get; set; } + /// /// Gets or Sets Phone /// [DataMember(Name="phone")] public string Phone { get; set; } + /// /// User Status /// @@ -132,8 +114,7 @@ namespace IO.Swagger.Models { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((User)obj); + return obj.GetType() == GetType() && Equals((User)obj); } /// @@ -143,50 +124,49 @@ namespace IO.Swagger.Models /// Boolean public bool Equals(User other) { - if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return ( - this.Id == other.Id || - this.Id != null && - this.Id.Equals(other.Id) + Id == other.Id || + Id != null && + Id.Equals(other.Id) ) && ( - this.Username == other.Username || - this.Username != null && - this.Username.Equals(other.Username) + Username == other.Username || + Username != null && + Username.Equals(other.Username) ) && ( - this.FirstName == other.FirstName || - this.FirstName != null && - this.FirstName.Equals(other.FirstName) + FirstName == other.FirstName || + FirstName != null && + FirstName.Equals(other.FirstName) ) && ( - this.LastName == other.LastName || - this.LastName != null && - this.LastName.Equals(other.LastName) + LastName == other.LastName || + LastName != null && + LastName.Equals(other.LastName) ) && ( - this.Email == other.Email || - this.Email != null && - this.Email.Equals(other.Email) + Email == other.Email || + Email != null && + Email.Equals(other.Email) ) && ( - this.Password == other.Password || - this.Password != null && - this.Password.Equals(other.Password) + Password == other.Password || + Password != null && + Password.Equals(other.Password) ) && ( - this.Phone == other.Phone || - this.Phone != null && - this.Phone.Equals(other.Phone) + Phone == other.Phone || + Phone != null && + Phone.Equals(other.Phone) ) && ( - this.UserStatus == other.UserStatus || - this.UserStatus != null && - this.UserStatus.Equals(other.UserStatus) + UserStatus == other.UserStatus || + UserStatus != null && + UserStatus.Equals(other.UserStatus) ); } @@ -199,29 +179,30 @@ namespace IO.Swagger.Models // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { - int hash = 41; + var hash = 41; // Suitable nullity checks etc, of course :) - if (this.Id != null) - hash = hash * 59 + this.Id.GetHashCode(); - if (this.Username != null) - hash = hash * 59 + this.Username.GetHashCode(); - if (this.FirstName != null) - hash = hash * 59 + this.FirstName.GetHashCode(); - if (this.LastName != null) - hash = hash * 59 + this.LastName.GetHashCode(); - if (this.Email != null) - hash = hash * 59 + this.Email.GetHashCode(); - if (this.Password != null) - hash = hash * 59 + this.Password.GetHashCode(); - if (this.Phone != null) - hash = hash * 59 + this.Phone.GetHashCode(); - if (this.UserStatus != null) - hash = hash * 59 + this.UserStatus.GetHashCode(); + if (Id != null) + hash = hash * 59 + Id.GetHashCode(); + if (Username != null) + hash = hash * 59 + Username.GetHashCode(); + if (FirstName != null) + hash = hash * 59 + FirstName.GetHashCode(); + if (LastName != null) + hash = hash * 59 + LastName.GetHashCode(); + if (Email != null) + hash = hash * 59 + Email.GetHashCode(); + if (Password != null) + hash = hash * 59 + Password.GetHashCode(); + if (Phone != null) + hash = hash * 59 + Phone.GetHashCode(); + if (UserStatus != null) + hash = hash * 59 + UserStatus.GetHashCode(); return hash; } } #region Operators + #pragma warning disable 1591 public static bool operator ==(User left, User right) { @@ -233,7 +214,7 @@ namespace IO.Swagger.Models return !Equals(left, right); } + #pragma warning restore 1591 #endregion Operators - } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Program.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Program.cs index 8990e6b48ad..343960bdc37 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Program.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Program.cs @@ -1,15 +1,17 @@ -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Builder; namespace IO.Swagger { + /// + /// Program + /// public class Program { + /// + /// Main + /// + /// public static void Main(string[] args) { var host = new WebHostBuilder() diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Properties/launchSettings.json b/samples/server/petstore/aspnetcore/src/IO.Swagger/Properties/launchSettings.json index 45a5f3319a5..21acfed207b 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Properties/launchSettings.json +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Properties/launchSettings.json @@ -11,7 +11,7 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "swagger/ui/index.html", + "launchUrl": "swagger/", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -19,7 +19,7 @@ "web": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "http://localhost:5000/swagger/ui/index.html", + "launchUrl": "http://localhost:5000/swagger/", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/Startup.cs b/samples/server/petstore/aspnetcore/src/IO.Swagger/Startup.cs index 43438ff0582..d1cf8d17032 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/Startup.cs +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/Startup.cs @@ -9,28 +9,32 @@ */ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; -using System.Xml.XPath; 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 Swashbuckle.Swagger.Model; -using Swashbuckle.SwaggerGen.Annotations; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; namespace IO.Swagger { + /// + /// Startup + /// public class Startup { private readonly IHostingEnvironment _hostingEnv; - public IConfigurationRoot Configuration { get; } + private IConfigurationRoot Configuration { get; } + /// + /// Constructor + /// + /// public Startup(IHostingEnvironment env) { _hostingEnv = env; @@ -42,49 +46,60 @@ namespace IO.Swagger .AddEnvironmentVariables(); Configuration = builder.Build(); } - - - // This method gets called by the runtime. Use this method to add services to the container. + + /// + /// This method gets called by the runtime. Use this method to add services to the container. + /// + /// public void ConfigureServices(IServiceCollection services) { // Add framework services. - services.AddMvc() - .AddJsonOptions( - opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); - - services.AddSwaggerGen(); - - services.ConfigureSwaggerGen(options => - { - options.SingleApiVersion(new Info + services + .AddMvc() + .AddJsonOptions(opts => { - Version = "v1", - Title = "IO.Swagger", - Description = "IO.Swagger (ASP.NET Core 1.0)" + opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter { + CamelCaseText = true + }); }); - options.DescribeAllEnumsAsStrings(); - - var comments = new XPathDocument($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); - options.OperationFilter(comments); - options.ModelFilter(comments); - }); - + services + .AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new Info + { + Version = "v1", + Title = "IO.Swagger", + Description = "IO.Swagger (ASP.NET Core 1.0)" + }); + c.CustomSchemaIds(type => type.FriendlyId(true)); + c.DescribeAllEnumsAsStrings(); + c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); + }); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + /// + /// 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) { - loggerFactory.AddConsole(Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); + loggerFactory + .AddConsole(Configuration.GetSection("Logging")) + .AddDebug(); - app.UseMvc(); - - app.UseDefaultFiles(); - app.UseStaticFiles(); - - app.UseSwagger(); - app.UseSwaggerUi(); + app + .UseMvc() + .UseDefaultFiles() + .UseStaticFiles() + .UseSwagger() + .UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "IO.Swagger"); + }); } } } diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/project.json b/samples/server/petstore/aspnetcore/src/IO.Swagger/project.json index de2fe74640d..3dbfd87246e 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/project.json +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/project.json @@ -21,8 +21,7 @@ "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.EntityFrameworkCore": "1.0.0", - "Swashbuckle.SwaggerGen": "6.0.0-beta901", - "Swashbuckle.SwaggerUi": "6.0.0-beta901", + "Swashbuckle.AspNetCore": "1.0.0-rc3", "Newtonsoft.Json": "9.0.1" }, diff --git a/samples/server/petstore/aspnetcore/src/IO.Swagger/wwwroot/index.html b/samples/server/petstore/aspnetcore/src/IO.Swagger/wwwroot/index.html index c8c055b34f7..cde1f2f90b9 100644 --- a/samples/server/petstore/aspnetcore/src/IO.Swagger/wwwroot/index.html +++ b/samples/server/petstore/aspnetcore/src/IO.Swagger/wwwroot/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file