diff --git a/bin/aspnetcore-petstore-server-interface-controller.sh b/bin/aspnetcore-petstore-server-interface-controller.sh new file mode 100755 index 00000000000..72807efe75e --- /dev/null +++ b/bin/aspnetcore-petstore-server-interface-controller.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml" +ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -o samples/server/petstore/aspnetcore-interface-controller --interface-controller" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/aspnetcore-petstore-server-interfaces.sh b/bin/aspnetcore-petstore-server-interfaces.sh new file mode 100755 index 00000000000..3d2c02b1dda --- /dev/null +++ b/bin/aspnetcore-petstore-server-interfaces.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml" +ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -o samples/server/petstore/aspnetcore-interface-only --interface-only" + +java $JAVA_OPTS -jar $executable $ags diff --git a/samples/server/petstore/aspnetcore-interface-controller/.swagger-codegen-ignore b/samples/server/petstore/aspnetcore-interface-controller/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/aspnetcore-interface-controller/.swagger-codegen/VERSION b/samples/server/petstore/aspnetcore-interface-controller/.swagger-codegen/VERSION new file mode 100644 index 00000000000..78822e7720d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/.swagger-codegen/VERSION @@ -0,0 +1 @@ +3.0.9-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-interface-controller/IO.Swagger.sln b/samples/server/petstore/aspnetcore-interface-controller/IO.Swagger.sln new file mode 100644 index 00000000000..048247ce520 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/IO.Swagger.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26114.2 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{8125E348-BDAC-48B2-8620-9360B68B0F6A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8125E348-BDAC-48B2-8620-9360B68B0F6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8125E348-BDAC-48B2-8620-9360B68B0F6A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8125E348-BDAC-48B2-8620-9360B68B0F6A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8125E348-BDAC-48B2-8620-9360B68B0F6A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/server/petstore/aspnetcore-interface-controller/NuGet.Config b/samples/server/petstore/aspnetcore-interface-controller/NuGet.Config new file mode 100644 index 00000000000..01f3d1f203f --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-controller/README.md b/samples/server/petstore/aspnetcore-interface-controller/README.md new file mode 100644 index 00000000000..a12bcb571e3 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/README.md @@ -0,0 +1,25 @@ +# IO.Swagger - ASP.NET Core 2.0 Server + +This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + +## Run + +Linux/OS X: + +``` +sh build.sh +``` + +Windows: + +``` +build.bat +``` + +## Run in Docker + +``` +cd src/IO.Swagger +docker build -t io.swagger . +docker run -p 5000:5000 io.swagger +``` diff --git a/samples/server/petstore/aspnetcore-interface-controller/build.bat b/samples/server/petstore/aspnetcore-interface-controller/build.bat new file mode 100644 index 00000000000..2e041233a06 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/build.bat @@ -0,0 +1,9 @@ +:: Generated by: https://github.com/swagger-api/swagger-codegen.git +:: + +@echo off + +dotnet restore src\IO.Swagger +dotnet build src\IO.Swagger +echo Now, run the following to start the project: dotnet run -p src\IO.Swagger\IO.Swagger.csproj --launch-profile web. +echo. diff --git a/samples/server/petstore/aspnetcore-interface-controller/build.sh b/samples/server/petstore/aspnetcore-interface-controller/build.sh new file mode 100644 index 00000000000..ce6063a2f49 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Generated by: https://github.com/swagger-api/swagger-codegen.git +# + +dotnet restore src/IO.Swagger/ && \ + dotnet build src/IO.Swagger/ && \ + echo "Now, run the following to start the project: dotnet run -p src/IO.Swagger/IO.Swagger.csproj --launch-profile web" diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/.gitignore b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/.gitignore new file mode 100644 index 00000000000..cd9b840e549 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/.gitignore @@ -0,0 +1,208 @@ +PID + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs new file mode 100644 index 00000000000..07cfabe83cf --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs @@ -0,0 +1,61 @@ +using System.ComponentModel.DataAnnotations; +using System.Reflection; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.ModelBinding; + +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) + { + // Per https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/ + var descriptor = context.ActionDescriptor as ControllerActionDescriptor; + if (descriptor != null) + { + foreach (var parameter in descriptor.MethodInfo.GetParameters()) + { + object args = null; + if (context.ActionArguments.ContainsKey(parameter.Name)) + { + args = context.ActionArguments[parameter.Name]; + } + + ValidateAttributes(parameter, args, context.ModelState); + } + } + + if (!context.ModelState.IsValid) + { + context.Result = new BadRequestObjectResult(context.ModelState); + } + } + + private void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState) + { + foreach (var attributeData in parameter.CustomAttributes) + { + var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType); + + var validationAttribute = attributeInstance as ValidationAttribute; + if (validationAttribute != null) + { + var isValid = validationAttribute.IsValid(args); + if (!isValid) + { + modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name)); + } + } + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/DefaultApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/DefaultApi.cs new file mode 100644 index 00000000000..4276b05a389 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/DefaultApi.cs @@ -0,0 +1,53 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Attributes; +using IO.Swagger.Security; +using Microsoft.AspNetCore.Authorization; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + [ApiController] + public class DefaultApiController : ControllerBase, IDefaultApiController + { + /// + /// + /// + /// peticion realizada con exito + [HttpGet] + [Route("/test")] + [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + [ValidateModelState] + [SwaggerOperation("TestMethod")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "peticion realizada con exito")] + public virtual IActionResult TestMethod() + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(List)); + string exampleJson = null; + exampleJson = "[ \"\", \"\" ]"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject>(exampleJson) + : default(List); //TODO: Change the data returned + return new ObjectResult(example); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IDefaultApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IDefaultApi.cs new file mode 100644 index 00000000000..4179fad3b2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IDefaultApi.cs @@ -0,0 +1,31 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IDefaultApiController + { + /// + /// + /// + + /// peticion realizada con exito + IActionResult TestMethod(); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs new file mode 100644 index 00000000000..406250ef74a --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs @@ -0,0 +1,90 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IPetApiController + { + /// + /// Add a new pet to the store + /// + + /// Pet object that needs to be added to the store + /// Invalid input + IActionResult AddPet([FromBody]Pet body); + + /// + /// Deletes a pet + /// + + /// Pet id to delete + /// + /// Invalid ID supplied + /// Pet not found + IActionResult DeletePet([FromRoute][Required]long? petId, [FromHeader]string apiKey); + + /// + /// Finds Pets by status + /// + /// Multiple status values can be provided with comma separated strings + /// Status values that need to be considered for filter + /// successful operation + /// Invalid status value + IActionResult FindPetsByStatus([FromQuery][Required()]List status); + + /// + /// Finds Pets by tags + /// + /// Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing. + /// Tags to filter by + /// successful operation + /// Invalid tag value + IActionResult FindPetsByTags([FromQuery][Required()]List tags); + + /// + /// Find pet by ID + /// + /// Returns a single pet + /// ID of pet to return + /// successful operation + /// Invalid ID supplied + /// Pet not found + 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 + /// Validation exception + IActionResult UpdatePet([FromBody]Pet body); + + + /// + /// uploads an image + /// + + /// ID of pet to update + /// + /// successful operation + IActionResult UploadFile([FromRoute][Required]long? petId, [FromBody]Object body); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs new file mode 100644 index 00000000000..1f664418776 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs @@ -0,0 +1,59 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IStoreApiController + { + /// + /// Delete purchase order by ID + /// + /// For valid response try integer IDs with positive integer value.\\ \\ Negative or non-integer values will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + IActionResult DeleteOrder([FromRoute][Required]long? orderId); + + /// + /// Returns pet inventories by status + /// + /// Returns a map of status codes to quantities + /// successful operation + IActionResult GetInventory(); + + /// + /// Find purchase order by ID + /// + /// For valid response try integer IDs with value >= 1 and <= 10.\\ \\ Other values will generated exceptions + /// ID of pet that needs to be fetched + /// successful operation + /// Invalid ID supplied + /// Order not found + IActionResult GetOrderById([FromRoute][Required][Range(1, 10)]long? orderId); + + /// + /// Place an order for a pet + /// + + /// order placed for purchasing the pet + /// successful operation + /// Invalid Order + IActionResult PlaceOrder([FromBody]Order body); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs new file mode 100644 index 00000000000..8de67b2ef74 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs @@ -0,0 +1,94 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IUserApiController + { + /// + /// Create user + /// + /// This can only be done by the logged in user. + /// Created user object + /// successful operation + IActionResult CreateUser([FromBody]User body); + + /// + /// Creates list of users with given input array + /// + + /// List of user object + /// successful operation + IActionResult CreateUsersWithArrayInput([FromBody]List body); + + /// + /// Creates list of users with given input array + /// + + /// List of user object + /// successful operation + IActionResult CreateUsersWithListInput([FromBody]List body); + + /// + /// Delete user + /// + /// This can only be done by the logged in user. + /// The name that needs to be deleted + /// Invalid username supplied + /// User not found + 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 + /// User not found + 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 + /// Invalid username/password supplied + IActionResult LoginUser([FromQuery][Required()]string username, [FromQuery][Required()]string password); + + /// + /// Logs out current logged in user session + /// + + /// successful operation + IActionResult LogoutUser(); + + /// + /// Updated user + /// + /// This can only be done by the logged in user. + /// Updated user object + /// name that need to be updated + /// Invalid user supplied + /// User not found + IActionResult UserUsernamePut([FromBody]User body, [FromRoute][Required]string username); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/PetApi.cs new file mode 100644 index 00000000000..be37d436a18 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/PetApi.cs @@ -0,0 +1,208 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Attributes; +using IO.Swagger.Security; +using Microsoft.AspNetCore.Authorization; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + [ApiController] + public class PetApiController : ControllerBase, IPetApiController + { + /// + /// Add a new pet to the store + /// + /// Pet object that needs to be added to the store + /// Invalid input + [HttpPost] + [Route("/pet")] + [ValidateModelState] + [SwaggerOperation("AddPet")] + public virtual IActionResult AddPet([FromBody]Pet body) + { + //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(405); + + throw new NotImplementedException(); + } + + /// + /// Deletes a pet + /// + /// Pet id to delete + /// + /// Invalid ID supplied + /// Pet not found + [HttpDelete] + [Route("/pet/{petId}")] + [ValidateModelState] + [SwaggerOperation("DeletePet")] + public virtual IActionResult DeletePet([FromRoute][Required]long? petId, [FromHeader]string apiKey) + { + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + + throw new NotImplementedException(); + } + + /// + /// Finds Pets by status + /// + /// Multiple status values can be provided with comma separated strings + /// Status values that need to be considered for filter + /// successful operation + /// Invalid status value + [HttpGet] + [Route("/pet/findByStatus")] + [ValidateModelState] + [SwaggerOperation("FindPetsByStatus")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "successful operation")] + public virtual IActionResult FindPetsByStatus([FromQuery][Required()]List status) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(List)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + string exampleJson = null; + exampleJson = "[ {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}, {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n} ]"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject>(exampleJson) + : default(List); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Finds Pets by tags + /// + /// Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing. + /// Tags to filter by + /// successful operation + /// Invalid tag value + [HttpGet] + [Route("/pet/findByTags")] + [ValidateModelState] + [SwaggerOperation("FindPetsByTags")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "successful operation")] + public virtual IActionResult FindPetsByTags([FromQuery][Required()]List tags) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(List)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + string exampleJson = null; + exampleJson = "[ {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}, {\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n} ]"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject>(exampleJson) + : default(List); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Find pet by ID + /// + /// Returns a single pet + /// ID of pet to return + /// successful operation + /// Invalid ID supplied + /// Pet not found + [HttpGet] + [Route("/pet/{petId}")] + [Authorize(AuthenticationSchemes = ApiKeyAuthenticationHandler.SchemeName)] + [ValidateModelState] + [SwaggerOperation("GetPetById")] + [SwaggerResponse(statusCode: 200, type: typeof(Pet), description: "successful operation")] + public virtual IActionResult GetPetById([FromRoute][Required]long? petId) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Pet)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + string exampleJson = null; + exampleJson = "{\n \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ],\n \"name\" : \"doggie\",\n \"id\" : 0,\n \"category\" : {\n \"name\" : \"name\",\n \"id\" : 6\n },\n \"tags\" : [ {\n \"name\" : \"name\",\n \"id\" : 1\n }, {\n \"name\" : \"name\",\n \"id\" : 1\n } ],\n \"status\" : \"available\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Pet); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Update an existing pet + /// + /// Pet object that needs to be added to the store + /// Invalid ID supplied + /// Pet not found + /// Validation exception + [HttpPut] + [Route("/pet")] + [ValidateModelState] + [SwaggerOperation("UpdatePet")] + public virtual IActionResult UpdatePet([FromBody]Pet body) + { + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + + //TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(405); + + throw new NotImplementedException(); + } + + + /// + /// uploads an image + /// + /// ID of pet to update + /// + /// successful operation + [HttpPost] + [Route("/pet/{petId}/uploadImage")] + [ValidateModelState] + [SwaggerOperation("UploadFile")] + [SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")] + public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromBody]Object body) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(ApiResponse)); + string exampleJson = null; + exampleJson = "{\n \"code\" : 0,\n \"type\" : \"type\",\n \"message\" : \"message\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(ApiResponse); //TODO: Change the data returned + return new ObjectResult(example); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs new file mode 100644 index 00000000000..64d2d5a275d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs @@ -0,0 +1,135 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Attributes; +using IO.Swagger.Security; +using Microsoft.AspNetCore.Authorization; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + [ApiController] + public class StoreApiController : ControllerBase, IStoreApiController + { + /// + /// Delete purchase order by ID + /// + /// For valid response try integer IDs with positive integer value.\\ \\ Negative or non-integer values will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + [HttpDelete] + [Route("/store/order/{orderId}")] + [ValidateModelState] + [SwaggerOperation("DeleteOrder")] + public virtual IActionResult DeleteOrder([FromRoute][Required]long? orderId) + { + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + + throw new NotImplementedException(); + } + + /// + /// Returns pet inventories by status + /// + /// Returns a map of status codes to quantities + /// successful operation + [HttpGet] + [Route("/store/inventory")] + [Authorize(AuthenticationSchemes = ApiKeyAuthenticationHandler.SchemeName)] + [ValidateModelState] + [SwaggerOperation("GetInventory")] + [SwaggerResponse(statusCode: 200, type: typeof(Dictionary), description: "successful operation")] + public virtual IActionResult GetInventory() + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Dictionary)); + string exampleJson = null; + exampleJson = "{\n \"key\" : 0\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject>(exampleJson) + : default(Dictionary); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Find purchase order by ID + /// + /// For valid response try integer IDs with value >= 1 and <= 10.\\ \\ Other values will generated exceptions + /// ID of pet that needs to be fetched + /// successful operation + /// Invalid ID supplied + /// Order not found + [HttpGet] + [Route("/store/order/{orderId}")] + [ValidateModelState] + [SwaggerOperation("GetOrderById")] + [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] + public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 10)]long? orderId) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Order)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + string exampleJson = null; + exampleJson = "{\n \"petId\" : 6,\n \"quantity\" : 1,\n \"id\" : 0,\n \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\",\n \"complete\" : false,\n \"status\" : \"placed\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Order); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Place an order for a pet + /// + /// order placed for purchasing the pet + /// successful operation + /// Invalid Order + [HttpPost] + [Route("/store/order")] + [ValidateModelState] + [SwaggerOperation("PlaceOrder")] + [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] + public virtual IActionResult PlaceOrder([FromBody]Order body) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(Order)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + string exampleJson = null; + exampleJson = "{\n \"petId\" : 6,\n \"quantity\" : 1,\n \"id\" : 0,\n \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\",\n \"complete\" : false,\n \"status\" : \"placed\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(Order); //TODO: Change the data returned + return new ObjectResult(example); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/UserApi.cs new file mode 100644 index 00000000000..753d18b0489 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Controllers/UserApi.cs @@ -0,0 +1,202 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Attributes; +using IO.Swagger.Security; +using Microsoft.AspNetCore.Authorization; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + [ApiController] + public class UserApiController : ControllerBase, IUserApiController + { + /// + /// Create user + /// + /// This can only be done by the logged in user. + /// Created user object + /// successful operation + [HttpPost] + [Route("/user")] + [ValidateModelState] + [SwaggerOperation("CreateUser")] + public virtual IActionResult CreateUser([FromBody]User body) + { + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + + /// + /// Creates list of users with given input array + /// + /// List of user object + /// successful operation + [HttpPost] + [Route("/user/createWithArray")] + [ValidateModelState] + [SwaggerOperation("CreateUsersWithArrayInput")] + public virtual IActionResult CreateUsersWithArrayInput([FromBody]List body) + { + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + + /// + /// Creates list of users with given input array + /// + /// List of user object + /// successful operation + [HttpPost] + [Route("/user/createWithList")] + [ValidateModelState] + [SwaggerOperation("CreateUsersWithListInput")] + public virtual IActionResult CreateUsersWithListInput([FromBody]List body) + { + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + + /// + /// Delete user + /// + /// This can only be done by the logged in user. + /// The name that needs to be deleted + /// Invalid username supplied + /// User not found + [HttpDelete] + [Route("/user/{username}")] + [ValidateModelState] + [SwaggerOperation("DeleteUser")] + public virtual IActionResult DeleteUser([FromRoute][Required]string username) + { + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + + throw new NotImplementedException(); + } + + /// + /// Get user by user name + /// + /// The name that needs to be fetched. Use user1 for testing. + /// successful operation + /// Invalid username supplied + /// User not found + [HttpGet] + [Route("/user/{username}")] + [ValidateModelState] + [SwaggerOperation("GetUserByName")] + [SwaggerResponse(statusCode: 200, type: typeof(User), description: "successful operation")] + public virtual IActionResult GetUserByName([FromRoute][Required]string username) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(User)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + string exampleJson = null; + exampleJson = "{\n \"firstName\" : \"firstName\",\n \"lastName\" : \"lastName\",\n \"password\" : \"password\",\n \"userStatus\" : 6,\n \"phone\" : \"phone\",\n \"id\" : 0,\n \"email\" : \"email\",\n \"username\" : \"username\"\n}"; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(User); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Logs user into the system + /// + /// The user name for login + /// The password for login in clear text + /// successful operation + /// Invalid username/password supplied + [HttpGet] + [Route("/user/login")] + [ValidateModelState] + [SwaggerOperation("LoginUser")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "successful operation")] + public virtual IActionResult LoginUser([FromQuery][Required()]string username, [FromQuery][Required()]string password) + { + //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(200, default(string)); + + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + string exampleJson = null; + exampleJson = "\"\""; + + var example = exampleJson != null + ? JsonConvert.DeserializeObject(exampleJson) + : default(string); //TODO: Change the data returned + return new ObjectResult(example); + } + + /// + /// Logs out current logged in user session + /// + /// successful operation + [HttpGet] + [Route("/user/logout")] + [ValidateModelState] + [SwaggerOperation("LogoutUser")] + public virtual IActionResult LogoutUser() + { + //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(0); + + throw new NotImplementedException(); + } + + /// + /// Updated user + /// + /// This can only be done by the logged in user. + /// Updated user object + /// name that need to be updated + /// Invalid user supplied + /// User not found + [HttpPut] + [Route("/user/{username}")] + [ValidateModelState] + [SwaggerOperation("UserUsernamePut")] + public virtual IActionResult UserUsernamePut([FromBody]User body, [FromRoute][Required]string username) + { + //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(400); + + //TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ... + // return StatusCode(404); + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Dockerfile b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Dockerfile new file mode 100644 index 00000000000..967c8195c2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env +WORKDIR /app + +ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 + +# copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# build runtime image +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 +WORKDIR /app +COPY --from=build-env /app/out . +ENTRYPOINT ["dotnet", "IO.Swagger.dll"] diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs new file mode 100644 index 00000000000..f3c528eada2 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs @@ -0,0 +1,50 @@ +using System.Linq; +using System.Text.RegularExpressions; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace IO.Swagger.Filters +{ + /// + /// BasePath Document Filter sets BasePath property of Swagger and removes it from the individual URL paths + /// + public class BasePathFilter : IDocumentFilter + { + /// + /// Constructor + /// + /// BasePath to remove from Operations + public BasePathFilter(string basePath) + { + BasePath = basePath; + } + + /// + /// Gets the BasePath of the Swagger Doc + /// + /// The BasePath of the Swagger Doc + public string BasePath { get; } + + /// + /// Apply the filter + /// + /// SwaggerDocument + /// FilterContext + public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context) + { + swaggerDoc.BasePath = this.BasePath; + + var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(this.BasePath)).ToList(); + + foreach (var path in pathsToModify) + { + if (path.Key.StartsWith(this.BasePath)) + { + string newKey = Regex.Replace(path.Key, $"^{this.BasePath}", string.Empty); + swaggerDoc.Paths.Remove(path.Key); + swaggerDoc.Paths.Add(newKey, path.Value); + } + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs new file mode 100644 index 00000000000..a0e2cb6871d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs @@ -0,0 +1,97 @@ +using System.ComponentModel.DataAnnotations; +using System.Linq; +using Microsoft.AspNetCore.Mvc.Controllers; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace IO.Swagger.Filters +{ + /// + /// Path Parameter Validation Rules Filter + /// + public class GeneratePathParamsValidationFilter : IOperationFilter + { + /// + /// Constructor + /// + /// Operation + /// OperationFilterContext + public void Apply(Operation operation, OperationFilterContext context) + { + var pars = context.ApiDescription.ParameterDescriptions; + + foreach (var par in pars) + { + var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name); + + var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes; + + if (attributes != null && attributes.Count() > 0 && swaggerParam != null) + { + // Required - [Required] + var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute)); + if (requiredAttr != null) + { + swaggerParam.Required = true; + } + + // Regex Pattern [RegularExpression] + var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute)); + if (regexAttr != null) + { + string regex = (string)regexAttr.ConstructorArguments[0].Value; + if (swaggerParam is NonBodyParameter) + { + ((NonBodyParameter)swaggerParam).Pattern = regex; + } + } + + // String Length [StringLength] + int? minLenght = null, maxLength = null; + var stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute)); + if (stringLengthAttr != null) + { + if (stringLengthAttr.NamedArguments.Count == 1) + { + minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value; + } + maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value; + } + + var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute)); + if (minLengthAttr != null) + { + minLenght = (int)minLengthAttr.ConstructorArguments[0].Value; + } + + var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute)); + if (maxLengthAttr != null) + { + maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value; + } + + if (swaggerParam is NonBodyParameter) + { + ((NonBodyParameter)swaggerParam).MinLength = minLenght; + ((NonBodyParameter)swaggerParam).MaxLength = maxLength; + } + + // Range [Range] + var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute)); + if (rangeAttr != null) + { + int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value; + int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value; + + if (swaggerParam is NonBodyParameter) + { + ((NonBodyParameter)swaggerParam).Minimum = rangeMin; + ((NonBodyParameter)swaggerParam).Maximum = rangeMax; + } + } + } + } + } + } +} + diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/IO.Swagger.csproj new file mode 100644 index 00000000000..616076b6078 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/IO.Swagger.csproj @@ -0,0 +1,19 @@ + + + IO.Swagger + IO.Swagger + netcoreapp2.2 + true + true + IO.Swagger + IO.Swagger + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/ApiResponse.cs new file mode 100644 index 00000000000..bde662cf557 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/ApiResponse.cs @@ -0,0 +1,147 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + /// + [DataMember(Name="message")] + public string Message { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class ApiResponse {\n"); + sb.Append(" Code: ").Append(Code).Append("\n"); + sb.Append(" Type: ").Append(Type).Append("\n"); + sb.Append(" Message: ").Append(Message).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((ApiResponse)obj); + } + + /// + /// Returns true if ApiResponse instances are equal + /// + /// Instance of ApiResponse to be compared + /// Boolean + public bool Equals(ApiResponse other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Code == other.Code || + Code != null && + Code.Equals(other.Code) + ) && + ( + Type == other.Type || + Type != null && + Type.Equals(other.Type) + ) && + ( + Message == other.Message || + Message != null && + Message.Equals(other.Message) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Code != null) + hashCode = hashCode * 59 + Code.GetHashCode(); + if (Type != null) + hashCode = hashCode * 59 + Type.GetHashCode(); + if (Message != null) + hashCode = hashCode * 59 + Message.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(ApiResponse left, ApiResponse right) + { + return Equals(left, right); + } + + public static bool operator !=(ApiResponse left, ApiResponse right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Body.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Body.cs new file mode 100644 index 00000000000..4c5cdc9511d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Body.cs @@ -0,0 +1,135 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Body : IEquatable + { + /// + /// Updated name of the pet + /// + /// Updated name of the pet + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Updated status of the pet + /// + /// Updated status of the pet + [DataMember(Name="status")] + public string Status { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Body {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" Status: ").Append(Status).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Body)obj); + } + + /// + /// Returns true if Body instances are equal + /// + /// Instance of Body to be compared + /// Boolean + public bool Equals(Body other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + Status == other.Status || + Status != null && + Status.Equals(other.Status) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (Status != null) + hashCode = hashCode * 59 + Status.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Body left, Body right) + { + return Equals(left, right); + } + + public static bool operator !=(Body left, Body right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Category.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Category.cs new file mode 100644 index 00000000000..04516cf2ef7 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Category.cs @@ -0,0 +1,133 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Category : IEquatable + { + /// + /// Gets or Sets Id + /// + [DataMember(Name="id")] + public long? Id { get; set; } + + /// + /// Gets or Sets Name + /// + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Category {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Category)obj); + } + + /// + /// Returns true if Category instances are equal + /// + /// Instance of Category to be compared + /// Boolean + public bool Equals(Category other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Category left, Category right) + { + return Equals(left, right); + } + + public static bool operator !=(Category left, Category right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Order.cs new file mode 100644 index 00000000000..f3bdd1a7cf9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Order.cs @@ -0,0 +1,213 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public enum StatusEnum + { + /// + /// Enum PlacedEnum for placed + /// + [EnumMember(Value = "placed")] + PlacedEnum = 0, + /// + /// Enum ApprovedEnum for approved + /// + [EnumMember(Value = "approved")] + ApprovedEnum = 1, + /// + /// Enum DeliveredEnum for delivered + /// + [EnumMember(Value = "delivered")] + DeliveredEnum = 2 } + + /// + /// Order Status + /// + /// Order Status + [DataMember(Name="status")] + public StatusEnum? Status { get; set; } + + /// + /// Gets or Sets Complete + /// + [DataMember(Name="complete")] + public bool? Complete { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Order {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" PetId: ").Append(PetId).Append("\n"); + sb.Append(" Quantity: ").Append(Quantity).Append("\n"); + sb.Append(" ShipDate: ").Append(ShipDate).Append("\n"); + sb.Append(" Status: ").Append(Status).Append("\n"); + sb.Append(" Complete: ").Append(Complete).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Order)obj); + } + + /// + /// Returns true if Order instances are equal + /// + /// Instance of Order to be compared + /// Boolean + public bool Equals(Order other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + PetId == other.PetId || + PetId != null && + PetId.Equals(other.PetId) + ) && + ( + Quantity == other.Quantity || + Quantity != null && + Quantity.Equals(other.Quantity) + ) && + ( + ShipDate == other.ShipDate || + ShipDate != null && + ShipDate.Equals(other.ShipDate) + ) && + ( + Status == other.Status || + Status != null && + Status.Equals(other.Status) + ) && + ( + Complete == other.Complete || + Complete != null && + Complete.Equals(other.Complete) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (PetId != null) + hashCode = hashCode * 59 + PetId.GetHashCode(); + if (Quantity != null) + hashCode = hashCode * 59 + Quantity.GetHashCode(); + if (ShipDate != null) + hashCode = hashCode * 59 + ShipDate.GetHashCode(); + if (Status != null) + hashCode = hashCode * 59 + Status.GetHashCode(); + if (Complete != null) + hashCode = hashCode * 59 + Complete.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Order left, Order right) + { + return Equals(left, right); + } + + public static bool operator !=(Order left, Order right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Pet.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Pet.cs new file mode 100644 index 00000000000..a3fe54a32b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Pet.cs @@ -0,0 +1,215 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public enum StatusEnum + { + /// + /// Enum AvailableEnum for available + /// + [EnumMember(Value = "available")] + AvailableEnum = 0, + /// + /// Enum PendingEnum for pending + /// + [EnumMember(Value = "pending")] + PendingEnum = 1, + /// + /// Enum SoldEnum for sold + /// + [EnumMember(Value = "sold")] + SoldEnum = 2 } + + /// + /// pet status in the store + /// + /// pet status in the store + [DataMember(Name="status")] + public StatusEnum? Status { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Pet {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Category: ").Append(Category).Append("\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n"); + sb.Append(" Tags: ").Append(Tags).Append("\n"); + sb.Append(" Status: ").Append(Status).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Pet)obj); + } + + /// + /// Returns true if Pet instances are equal + /// + /// Instance of Pet to be compared + /// Boolean + public bool Equals(Pet other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Category == other.Category || + Category != null && + Category.Equals(other.Category) + ) && + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + PhotoUrls == other.PhotoUrls || + PhotoUrls != null && + PhotoUrls.SequenceEqual(other.PhotoUrls) + ) && + ( + Tags == other.Tags || + Tags != null && + Tags.SequenceEqual(other.Tags) + ) && + ( + Status == other.Status || + Status != null && + Status.Equals(other.Status) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Category != null) + hashCode = hashCode * 59 + Category.GetHashCode(); + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (PhotoUrls != null) + hashCode = hashCode * 59 + PhotoUrls.GetHashCode(); + if (Tags != null) + hashCode = hashCode * 59 + Tags.GetHashCode(); + if (Status != null) + hashCode = hashCode * 59 + Status.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Pet left, Pet right) + { + return Equals(left, right); + } + + public static bool operator !=(Pet left, Pet right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Tag.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Tag.cs new file mode 100644 index 00000000000..24020bfb3d1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Tag.cs @@ -0,0 +1,133 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Tag : IEquatable + { + /// + /// Gets or Sets Id + /// + [DataMember(Name="id")] + public long? Id { get; set; } + + /// + /// Gets or Sets Name + /// + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Tag {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Tag)obj); + } + + /// + /// Returns true if Tag instances are equal + /// + /// Instance of Tag to be compared + /// Boolean + public bool Equals(Tag other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Tag left, Tag right) + { + return Equals(left, right); + } + + public static bool operator !=(Tag left, Tag right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Test.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Test.cs new file mode 100644 index 00000000000..7ae6c14633b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/Test.cs @@ -0,0 +1,105 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Test : IEquatable + { + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Test {\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Test)obj); + } + + /// + /// Returns true if Test instances are equal + /// + /// Instance of Test to be compared + /// Boolean + public bool Equals(Test other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return false; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Test left, Test right) + { + return Equals(left, right); + } + + public static bool operator !=(Test left, Test right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/User.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/User.cs new file mode 100644 index 00000000000..b8aa0b5683d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Models/User.cs @@ -0,0 +1,218 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + /// + /// User Status + [DataMember(Name="userStatus")] + public int? UserStatus { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class User {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Username: ").Append(Username).Append("\n"); + sb.Append(" FirstName: ").Append(FirstName).Append("\n"); + sb.Append(" LastName: ").Append(LastName).Append("\n"); + sb.Append(" Email: ").Append(Email).Append("\n"); + sb.Append(" Password: ").Append(Password).Append("\n"); + sb.Append(" Phone: ").Append(Phone).Append("\n"); + sb.Append(" UserStatus: ").Append(UserStatus).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((User)obj); + } + + /// + /// Returns true if User instances are equal + /// + /// Instance of User to be compared + /// Boolean + public bool Equals(User other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Username == other.Username || + Username != null && + Username.Equals(other.Username) + ) && + ( + FirstName == other.FirstName || + FirstName != null && + FirstName.Equals(other.FirstName) + ) && + ( + LastName == other.LastName || + LastName != null && + LastName.Equals(other.LastName) + ) && + ( + Email == other.Email || + Email != null && + Email.Equals(other.Email) + ) && + ( + Password == other.Password || + Password != null && + Password.Equals(other.Password) + ) && + ( + Phone == other.Phone || + Phone != null && + Phone.Equals(other.Phone) + ) && + ( + UserStatus == other.UserStatus || + UserStatus != null && + UserStatus.Equals(other.UserStatus) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Username != null) + hashCode = hashCode * 59 + Username.GetHashCode(); + if (FirstName != null) + hashCode = hashCode * 59 + FirstName.GetHashCode(); + if (LastName != null) + hashCode = hashCode * 59 + LastName.GetHashCode(); + if (Email != null) + hashCode = hashCode * 59 + Email.GetHashCode(); + if (Password != null) + hashCode = hashCode * 59 + Password.GetHashCode(); + if (Phone != null) + hashCode = hashCode * 59 + Phone.GetHashCode(); + if (UserStatus != null) + hashCode = hashCode * 59 + UserStatus.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(User left, User right) + { + return Equals(left, right); + } + + public static bool operator !=(User left, User right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Program.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Program.cs new file mode 100644 index 00000000000..ae409c1ecb8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Program.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore; + +namespace IO.Swagger +{ + /// + /// Program + /// + public class Program + { + /// + /// Main + /// + /// + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + /// + /// Create the web host builder. + /// + /// + /// IWebHostBuilder + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Properties/launchSettings.json b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Properties/launchSettings.json new file mode 100644 index 00000000000..21acfed207b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:50352/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger/", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "web": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "http://localhost:5000/swagger/", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs new file mode 100644 index 00000000000..57b5fd5dfd9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs @@ -0,0 +1,50 @@ +using System; +using System.Net.Http.Headers; +using System.Security.Claims; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace IO.Swagger.Security +{ + /// + /// class to handle api_key security. + /// + public class ApiKeyAuthenticationHandler : AuthenticationHandler + { + /// + /// scheme name for authentication handler. + /// + public const string SchemeName = "ApiKey"; + + public ApiKeyAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) + { + } + + /// + /// verify that require api key header exist and handle authorization. + /// + protected override async Task HandleAuthenticateAsync() + { + if (!Request.Headers.ContainsKey("api_key")) + { + return AuthenticateResult.Fail("Missing Authorization Header"); + } + + // do magic here! + + var claims = new[] { + new Claim(ClaimTypes.NameIdentifier, "changeme"), + new Claim(ClaimTypes.Name, "changeme"), + }; + var identity = new ClaimsIdentity(claims, Scheme.Name); + var principal = new ClaimsPrincipal(identity); + var ticket = new AuthenticationTicket(principal, Scheme.Name); + + return AuthenticateResult.Success(ticket); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Security/BearerAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Security/BearerAuthenticationHandler.cs new file mode 100644 index 00000000000..15c7ab0c928 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Security/BearerAuthenticationHandler.cs @@ -0,0 +1,58 @@ +using System; +using System.Net.Http.Headers; +using System.Security.Claims; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace IO.Swagger.Security +{ + /// + /// class to handle bearer authentication. + /// + public class BearerAuthenticationHandler : AuthenticationHandler + { + /// + /// scheme name for authentication handler. + /// + public const string SchemeName = "Bearer"; + + public BearerAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) + { + } + + /// + /// verify that require authorization header exists. + /// + protected override async Task HandleAuthenticateAsync() + { + if (!Request.Headers.ContainsKey("Authorization")) + { + return AuthenticateResult.Fail("Missing Authorization Header"); + } + try + { + var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); + + /// TODO handle token. + } + catch + { + return AuthenticateResult.Fail("Invalid Authorization Header"); + } + + var claims = new[] { + new Claim(ClaimTypes.NameIdentifier, "changeme"), + new Claim(ClaimTypes.Name, "changeme"), + }; + var identity = new ClaimsIdentity(claims, Scheme.Name); + var principal = new ClaimsPrincipal(identity); + var ticket = new AuthenticationTicket(principal, Scheme.Name); + + return AuthenticateResult.Success(ticket); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Startup.cs b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Startup.cs new file mode 100644 index 00000000000..43c2a2fea58 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/Startup.cs @@ -0,0 +1,132 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.IO; +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.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; +using IO.Swagger.Filters; +using IO.Swagger.Security; + +using Microsoft.AspNetCore.Authentication; + +namespace IO.Swagger +{ + /// + /// Startup + /// + public class Startup + { + private readonly IHostingEnvironment _hostingEnv; + + private IConfiguration Configuration { get; } + + /// + /// Constructor + /// + /// + /// + public Startup(IHostingEnvironment env, IConfiguration configuration) + { + _hostingEnv = env; + Configuration = configuration; + } + + /// + /// 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(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter { + CamelCaseText = true + }); + }) + .AddXmlSerializerFormatters(); + + services.AddAuthentication(ApiKeyAuthenticationHandler.SchemeName) + .AddScheme(ApiKeyAuthenticationHandler.SchemeName, null); + + services.AddAuthentication(BearerAuthenticationHandler.SchemeName) + .AddScheme(BearerAuthenticationHandler.SchemeName, null); + + + services + .AddSwaggerGen(c => + { + c.SwaggerDoc("1.0.0", new Info + { + Version = "1.0.0", + Title = "Swagger Petstore", + Description = "Swagger Petstore (ASP.NET Core 2.0)", + Contact = new Contact() + { + Name = "Swagger Codegen Contributors", + Url = "https://github.com/swagger-api/swagger-codegen", + Email = "apiteam@swagger.io" + }, + TermsOfService = "http://swagger.io/terms/" + }); + c.CustomSchemaIds(type => type.FriendlyId(true)); + c.DescribeAllEnumsAsStrings(); + c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); + + // 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(); + }); + } + + /// + /// 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) + { + app + .UseMvc() + .UseDefaultFiles() + .UseStaticFiles() + .UseSwagger() + .UseSwaggerUI(c => + { + //TODO: Either use the SwaggerGen generated Swagger contract (generated from C# classes) + c.SwaggerEndpoint("/swagger/1.0.0/swagger.json", "Swagger Petstore"); + + //TODO: Or alternatively use the original Swagger contract that's included in the static files + // c.SwaggerEndpoint("/swagger-original.json", "Swagger Petstore Original"); + }); + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + //TODO: Enable production exception handling (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling) + // app.UseExceptionHandler("/Home/Error"); + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/appsettings.json b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/appsettings.json new file mode 100644 index 00000000000..c6af7d9b069 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Information", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/web.config b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/web.config new file mode 100644 index 00000000000..a3b9f6add9c --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/web.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/README.md b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/README.md new file mode 100644 index 00000000000..6a0b78471a3 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/README.md @@ -0,0 +1,42 @@ +# Welcome to ASP.NET 5 Preview + +We've made some big updates in this release, so it’s **important** that you spend a few minutes to learn what’s new. + +ASP.NET 5 has been rearchitected to make it **lean** and **composable**. It's fully **open source** and available on [GitHub](http://go.microsoft.com/fwlink/?LinkID=517854). +Your new project automatically takes advantage of modern client-side utilities like [Bower](http://go.microsoft.com/fwlink/?LinkId=518004) and [npm](http://go.microsoft.com/fwlink/?LinkId=518005) (to add client-side libraries) and [Gulp](http://go.microsoft.com/fwlink/?LinkId=518007) (for client-side build and automation tasks). + +We hope you enjoy the new capabilities in ASP.NET 5 and Visual Studio 2015. +The ASP.NET Team + +### You've created a new ASP.NET 5 project. [Learn what's new](http://go.microsoft.com/fwlink/?LinkId=518016) + +### This application consists of: +* Sample pages using ASP.NET MVC 6 +* [Gulp](http://go.microsoft.com/fwlink/?LinkId=518007) and [Bower](http://go.microsoft.com/fwlink/?LinkId=518004) for managing client-side resources +* Theming using [Bootstrap](http://go.microsoft.com/fwlink/?LinkID=398939) + +#### NEW CONCEPTS +* [The 'wwwroot' explained](http://go.microsoft.com/fwlink/?LinkId=518008) +* [Configuration in ASP.NET 5](http://go.microsoft.com/fwlink/?LinkId=518012) +* [Dependency Injection](http://go.microsoft.com/fwlink/?LinkId=518013) +* [Razor TagHelpers](http://go.microsoft.com/fwlink/?LinkId=518014) +* [Manage client packages using Gulp](http://go.microsoft.com/fwlink/?LinkID=517849) +* [Develop on different platforms](http://go.microsoft.com/fwlink/?LinkID=517850) + +#### CUSTOMIZE APP +* [Add Controllers and Views](http://go.microsoft.com/fwlink/?LinkID=398600) +* [Add Data using EntityFramework](http://go.microsoft.com/fwlink/?LinkID=398602) +* [Add Authentication using Identity](http://go.microsoft.com/fwlink/?LinkID=398603) +* [Add real time support using SignalR](http://go.microsoft.com/fwlink/?LinkID=398606) +* [Add Class library](http://go.microsoft.com/fwlink/?LinkID=398604) +* [Add Web APIs with MVC 6](http://go.microsoft.com/fwlink/?LinkId=518009) +* [Add client packages using Bower](http://go.microsoft.com/fwlink/?LinkID=517848) + +#### DEPLOY +* [Run your app locally](http://go.microsoft.com/fwlink/?LinkID=517851) +* [Run your app on ASP.NET Core 5](http://go.microsoft.com/fwlink/?LinkID=517852) +* [Run commands in your 'project.json'](http://go.microsoft.com/fwlink/?LinkID=517853) +* [Publish to Microsoft Azure Web Sites](http://go.microsoft.com/fwlink/?LinkID=398609) +* [Publish to the file system](http://go.microsoft.com/fwlink/?LinkId=518019) + +We would love to hear your [feedback](http://go.microsoft.com/fwlink/?LinkId=518015) diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/index.html b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/index.html new file mode 100644 index 00000000000..cde1f2f90b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json new file mode 100644 index 00000000000..541b4da3d17 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json @@ -0,0 +1,1030 @@ +{ + "openapi" : "3.0.1", + "info" : { + "title" : "Swagger Petstore", + "description" : "This is a sample Petstore server. You can find\nout more about Swagger at\n[http://swagger.io](http://swagger.io) or on\n[irc.freenode.net, #swagger](http://swagger.io/irc/).\n", + "termsOfService" : "http://swagger.io/terms/", + "contact" : { + "email" : "apiteam@swagger.io" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + }, + "servers" : [ { + "url" : "/" + } ], + "tags" : [ { + "name" : "pet", + "description" : "Everything about your Pets", + "externalDocs" : { + "description" : "Find out more", + "url" : "http://swagger.io" + } + }, { + "name" : "store", + "description" : "Access to Petstore orders" + }, { + "name" : "user", + "description" : "Operations about user", + "externalDocs" : { + "description" : "Find out more about our store", + "url" : "http://swagger.io" + } + } ], + "paths" : { + "/pet" : { + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "operationId" : "updatePet", + "requestBody" : { + "$ref" : "#/components/requestBodies/Pet" + }, + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "operationId" : "addPet", + "requestBody" : { + "$ref" : "#/components/requestBodies/Pet" + }, + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByStatus" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by status", + "description" : "Multiple status values can be provided with comma separated strings", + "operationId" : "findPetsByStatus", + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + } + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + }, + "x-content-type" : "application/json" + } + }, + "application/xml" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + } + } + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "array", + "items" : { + "type" : "string" + } + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + }, + "x-content-type" : "application/json" + } + }, + "application/xml" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + } + } + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "deprecated" : true, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "api_key" : [ ] + } ] + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Updates a pet in the store with form data", + "operationId" : "updatePetWithForm", + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "requestBody" : { + "content" : { + "application/x-www-form-urlencoded" : { + "schema" : { + "$ref" : "#/components/schemas/body" + } + } + } + }, + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "operationId" : "deletePet", + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "operationId" : "uploadFile", + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "requestBody" : { + "content" : { + "application/octet-stream" : { + "schema" : { + "type" : "string", + "format" : "binary" + } + } + } + }, + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ApiResponse" + } + } + } + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/store/inventory" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Returns pet inventories by status", + "description" : "Returns a map of status codes to quantities", + "operationId" : "getInventory", + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + }, + "x-content-type" : "application/json" + } + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ] + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "operationId" : "placeOrder", + "requestBody" : { + "description" : "order placed for purchasing the pet", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + } + } + }, + "400" : { + "description" : "Invalid Order" + } + } + } + }, + "/store/order/{orderId}" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Find purchase order by ID", + "description" : "For valid response try integer IDs with value >= 1 and <= 10.\\ \\ Other values will generated exceptions", + "operationId" : "getOrderById", + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "maximum" : 10, + "minimum" : 1, + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + } + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + } + }, + "delete" : { + "tags" : [ "store" ], + "summary" : "Delete purchase order by ID", + "description" : "For valid response try integer IDs with positive integer value.\\ \\ Negative or non-integer values will generate API errors", + "operationId" : "deleteOrder", + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "minimum" : 1, + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + } + } + }, + "/user" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Create user", + "description" : "This can only be done by the logged in user.", + "operationId" : "createUser", + "requestBody" : { + "description" : "Created user object", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + } + }, + "required" : true + }, + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "operationId" : "createUsersWithArrayInput", + "requestBody" : { + "$ref" : "#/components/requestBodies/UserArray" + }, + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "operationId" : "createUsersWithListInput", + "requestBody" : { + "$ref" : "#/components/requestBodies/UserArray" + }, + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "operationId" : "loginUser", + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "string" + } + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "headers" : { + "X-Rate-Limit" : { + "description" : "calls per hour allowed by the user", + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int32" + } + }, + "X-Expires-After" : { + "description" : "date in UTC when token expires", + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string", + "format" : "date-time" + } + } + }, + "content" : { + "application/json" : { + "schema" : { + "type" : "string", + "x-content-type" : "application/json" + } + }, + "application/xml" : { + "schema" : { + "type" : "string" + } + } + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + } + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "operationId" : "logoutUser", + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "operationId" : "getUserByName", + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing.", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + } + } + }, + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + }, + "put" : { + "tags" : [ "user" ], + "summary" : "Updated user", + "description" : "This can only be done by the logged in user.", + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be updated", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + } ], + "requestBody" : { + "description" : "Updated user object", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + } + }, + "required" : true + }, + "responses" : { + "400" : { + "description" : "Invalid user supplied" + }, + "404" : { + "description" : "User not found" + } + } + }, + "delete" : { + "tags" : [ "user" ], + "summary" : "Delete user", + "description" : "This can only be done by the logged in user.", + "operationId" : "deleteUser", + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + } + }, + "/test" : { + "get" : { + "operationId" : "testMethod", + "responses" : { + "200" : { + "description" : "peticion realizada con exito", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Test" + }, + "x-content-type" : "application/json" + } + } + } + } + }, + "security" : [ { + "bearer" : [ ] + } ] + } + } + }, + "components" : { + "schemas" : { + "Order" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "petId" : { + "type" : "integer", + "format" : "int64" + }, + "quantity" : { + "type" : "integer", + "format" : "int32" + }, + "shipDate" : { + "type" : "string", + "format" : "date-time" + }, + "status" : { + "type" : "string", + "description" : "Order Status", + "enum" : [ "placed", "approved", "delivered" ] + }, + "complete" : { + "type" : "boolean", + "default" : false + } + }, + "example" : { + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" + }, + "xml" : { + "name" : "Order" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "example" : { + "name" : "name", + "id" : 6 + }, + "xml" : { + "name" : "Category" + } + }, + "User" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "username" : { + "type" : "string" + }, + "firstName" : { + "type" : "string" + }, + "lastName" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "password" : { + "type" : "string" + }, + "phone" : { + "type" : "string" + }, + "userStatus" : { + "type" : "integer", + "description" : "User Status", + "format" : "int32" + } + }, + "example" : { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" + }, + "xml" : { + "name" : "User" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "example" : { + "name" : "name", + "id" : 1 + }, + "xml" : { + "name" : "Tag" + } + }, + "Pet" : { + "required" : [ "name", "photoUrls" ], + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/components/schemas/Category" + }, + "name" : { + "type" : "string", + "example" : "doggie" + }, + "photoUrls" : { + "type" : "array", + "xml" : { + "name" : "photoUrl", + "wrapped" : true + }, + "items" : { + "type" : "string" + } + }, + "tags" : { + "type" : "array", + "xml" : { + "name" : "tag", + "wrapped" : true + }, + "items" : { + "$ref" : "#/components/schemas/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "example" : { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" + }, + "xml" : { + "name" : "Pet" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "example" : { + "code" : 0, + "type" : "type", + "message" : "message" + } + }, + "Test" : { + "type" : "string" + }, + "body" : { + "type" : "object", + "properties" : { + "name" : { + "type" : "string", + "description" : "Updated name of the pet" + }, + "status" : { + "type" : "string", + "description" : "Updated status of the pet" + } + } + } + }, + "requestBodies" : { + "Pet" : { + "description" : "Pet object that needs to be added to the store", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "required" : true + }, + "UserArray" : { + "description" : "List of user object", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/User" + } + } + } + }, + "required" : true + } + }, + "securitySchemes" : { + "bearer" : { + "type" : "http", + "scheme" : "bearer" + }, + "petstore_auth" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "http://petstore.swagger.io/oauth/dialog", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + } + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/web.config b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/web.config new file mode 100644 index 00000000000..e70a7778d60 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-controller/src/IO.Swagger/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-only/.swagger-codegen-ignore b/samples/server/petstore/aspnetcore-interface-only/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/aspnetcore-interface-only/.swagger-codegen/VERSION b/samples/server/petstore/aspnetcore-interface-only/.swagger-codegen/VERSION new file mode 100644 index 00000000000..78822e7720d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/.swagger-codegen/VERSION @@ -0,0 +1 @@ +3.0.9-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-interface-only/IO.Swagger.sln b/samples/server/petstore/aspnetcore-interface-only/IO.Swagger.sln new file mode 100644 index 00000000000..c21b1c96b73 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/IO.Swagger.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26114.2 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{A899BD96-9826-4AAB-A23A-C6E76B199AA1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A899BD96-9826-4AAB-A23A-C6E76B199AA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A899BD96-9826-4AAB-A23A-C6E76B199AA1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A899BD96-9826-4AAB-A23A-C6E76B199AA1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A899BD96-9826-4AAB-A23A-C6E76B199AA1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/server/petstore/aspnetcore-interface-only/NuGet.Config b/samples/server/petstore/aspnetcore-interface-only/NuGet.Config new file mode 100644 index 00000000000..01f3d1f203f --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-only/README.md b/samples/server/petstore/aspnetcore-interface-only/README.md new file mode 100644 index 00000000000..a12bcb571e3 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/README.md @@ -0,0 +1,25 @@ +# IO.Swagger - ASP.NET Core 2.0 Server + +This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + +## Run + +Linux/OS X: + +``` +sh build.sh +``` + +Windows: + +``` +build.bat +``` + +## Run in Docker + +``` +cd src/IO.Swagger +docker build -t io.swagger . +docker run -p 5000:5000 io.swagger +``` diff --git a/samples/server/petstore/aspnetcore-interface-only/build.bat b/samples/server/petstore/aspnetcore-interface-only/build.bat new file mode 100644 index 00000000000..2e041233a06 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/build.bat @@ -0,0 +1,9 @@ +:: Generated by: https://github.com/swagger-api/swagger-codegen.git +:: + +@echo off + +dotnet restore src\IO.Swagger +dotnet build src\IO.Swagger +echo Now, run the following to start the project: dotnet run -p src\IO.Swagger\IO.Swagger.csproj --launch-profile web. +echo. diff --git a/samples/server/petstore/aspnetcore-interface-only/build.sh b/samples/server/petstore/aspnetcore-interface-only/build.sh new file mode 100644 index 00000000000..ce6063a2f49 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Generated by: https://github.com/swagger-api/swagger-codegen.git +# + +dotnet restore src/IO.Swagger/ && \ + dotnet build src/IO.Swagger/ && \ + echo "Now, run the following to start the project: dotnet run -p src/IO.Swagger/IO.Swagger.csproj --launch-profile web" diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/.gitignore b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/.gitignore new file mode 100644 index 00000000000..cd9b840e549 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/.gitignore @@ -0,0 +1,208 @@ +PID + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs new file mode 100644 index 00000000000..07cfabe83cf --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs @@ -0,0 +1,61 @@ +using System.ComponentModel.DataAnnotations; +using System.Reflection; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.ModelBinding; + +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) + { + // Per https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/ + var descriptor = context.ActionDescriptor as ControllerActionDescriptor; + if (descriptor != null) + { + foreach (var parameter in descriptor.MethodInfo.GetParameters()) + { + object args = null; + if (context.ActionArguments.ContainsKey(parameter.Name)) + { + args = context.ActionArguments[parameter.Name]; + } + + ValidateAttributes(parameter, args, context.ModelState); + } + } + + if (!context.ModelState.IsValid) + { + context.Result = new BadRequestObjectResult(context.ModelState); + } + } + + private void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState) + { + foreach (var attributeData in parameter.CustomAttributes) + { + var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType); + + var validationAttribute = attributeInstance as ValidationAttribute; + if (validationAttribute != null) + { + var isValid = validationAttribute.IsValid(args); + if (!isValid) + { + modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name)); + } + } + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IDefaultApi.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IDefaultApi.cs new file mode 100644 index 00000000000..4179fad3b2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IDefaultApi.cs @@ -0,0 +1,31 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IDefaultApiController + { + /// + /// + /// + + /// peticion realizada con exito + IActionResult TestMethod(); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IPetApi.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IPetApi.cs new file mode 100644 index 00000000000..406250ef74a --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IPetApi.cs @@ -0,0 +1,90 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IPetApiController + { + /// + /// Add a new pet to the store + /// + + /// Pet object that needs to be added to the store + /// Invalid input + IActionResult AddPet([FromBody]Pet body); + + /// + /// Deletes a pet + /// + + /// Pet id to delete + /// + /// Invalid ID supplied + /// Pet not found + IActionResult DeletePet([FromRoute][Required]long? petId, [FromHeader]string apiKey); + + /// + /// Finds Pets by status + /// + /// Multiple status values can be provided with comma separated strings + /// Status values that need to be considered for filter + /// successful operation + /// Invalid status value + IActionResult FindPetsByStatus([FromQuery][Required()]List status); + + /// + /// Finds Pets by tags + /// + /// Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing. + /// Tags to filter by + /// successful operation + /// Invalid tag value + IActionResult FindPetsByTags([FromQuery][Required()]List tags); + + /// + /// Find pet by ID + /// + /// Returns a single pet + /// ID of pet to return + /// successful operation + /// Invalid ID supplied + /// Pet not found + 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 + /// Validation exception + IActionResult UpdatePet([FromBody]Pet body); + + + /// + /// uploads an image + /// + + /// ID of pet to update + /// + /// successful operation + IActionResult UploadFile([FromRoute][Required]long? petId, [FromBody]Object body); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs new file mode 100644 index 00000000000..1f664418776 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs @@ -0,0 +1,59 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IStoreApiController + { + /// + /// Delete purchase order by ID + /// + /// For valid response try integer IDs with positive integer value.\\ \\ Negative or non-integer values will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + IActionResult DeleteOrder([FromRoute][Required]long? orderId); + + /// + /// Returns pet inventories by status + /// + /// Returns a map of status codes to quantities + /// successful operation + IActionResult GetInventory(); + + /// + /// Find purchase order by ID + /// + /// For valid response try integer IDs with value >= 1 and <= 10.\\ \\ Other values will generated exceptions + /// ID of pet that needs to be fetched + /// successful operation + /// Invalid ID supplied + /// Order not found + IActionResult GetOrderById([FromRoute][Required][Range(1, 10)]long? orderId); + + /// + /// Place an order for a pet + /// + + /// order placed for purchasing the pet + /// successful operation + /// Invalid Order + IActionResult PlaceOrder([FromBody]Order body); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IUserApi.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IUserApi.cs new file mode 100644 index 00000000000..8de67b2ef74 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Controllers/IUserApi.cs @@ -0,0 +1,94 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using IO.Swagger.Models; + +namespace IO.Swagger.Controllers +{ + /// + /// + /// + public interface IUserApiController + { + /// + /// Create user + /// + /// This can only be done by the logged in user. + /// Created user object + /// successful operation + IActionResult CreateUser([FromBody]User body); + + /// + /// Creates list of users with given input array + /// + + /// List of user object + /// successful operation + IActionResult CreateUsersWithArrayInput([FromBody]List body); + + /// + /// Creates list of users with given input array + /// + + /// List of user object + /// successful operation + IActionResult CreateUsersWithListInput([FromBody]List body); + + /// + /// Delete user + /// + /// This can only be done by the logged in user. + /// The name that needs to be deleted + /// Invalid username supplied + /// User not found + 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 + /// User not found + 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 + /// Invalid username/password supplied + IActionResult LoginUser([FromQuery][Required()]string username, [FromQuery][Required()]string password); + + /// + /// Logs out current logged in user session + /// + + /// successful operation + IActionResult LogoutUser(); + + /// + /// Updated user + /// + /// This can only be done by the logged in user. + /// Updated user object + /// name that need to be updated + /// Invalid user supplied + /// User not found + IActionResult UserUsernamePut([FromBody]User body, [FromRoute][Required]string username); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Dockerfile b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Dockerfile new file mode 100644 index 00000000000..967c8195c2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env +WORKDIR /app + +ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 + +# copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# build runtime image +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 +WORKDIR /app +COPY --from=build-env /app/out . +ENTRYPOINT ["dotnet", "IO.Swagger.dll"] diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Filters/BasePathFilter.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Filters/BasePathFilter.cs new file mode 100644 index 00000000000..f3c528eada2 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Filters/BasePathFilter.cs @@ -0,0 +1,50 @@ +using System.Linq; +using System.Text.RegularExpressions; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace IO.Swagger.Filters +{ + /// + /// BasePath Document Filter sets BasePath property of Swagger and removes it from the individual URL paths + /// + public class BasePathFilter : IDocumentFilter + { + /// + /// Constructor + /// + /// BasePath to remove from Operations + public BasePathFilter(string basePath) + { + BasePath = basePath; + } + + /// + /// Gets the BasePath of the Swagger Doc + /// + /// The BasePath of the Swagger Doc + public string BasePath { get; } + + /// + /// Apply the filter + /// + /// SwaggerDocument + /// FilterContext + public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context) + { + swaggerDoc.BasePath = this.BasePath; + + var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(this.BasePath)).ToList(); + + foreach (var path in pathsToModify) + { + if (path.Key.StartsWith(this.BasePath)) + { + string newKey = Regex.Replace(path.Key, $"^{this.BasePath}", string.Empty); + swaggerDoc.Paths.Remove(path.Key); + swaggerDoc.Paths.Add(newKey, path.Value); + } + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs new file mode 100644 index 00000000000..a0e2cb6871d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs @@ -0,0 +1,97 @@ +using System.ComponentModel.DataAnnotations; +using System.Linq; +using Microsoft.AspNetCore.Mvc.Controllers; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace IO.Swagger.Filters +{ + /// + /// Path Parameter Validation Rules Filter + /// + public class GeneratePathParamsValidationFilter : IOperationFilter + { + /// + /// Constructor + /// + /// Operation + /// OperationFilterContext + public void Apply(Operation operation, OperationFilterContext context) + { + var pars = context.ApiDescription.ParameterDescriptions; + + foreach (var par in pars) + { + var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name); + + var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes; + + if (attributes != null && attributes.Count() > 0 && swaggerParam != null) + { + // Required - [Required] + var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute)); + if (requiredAttr != null) + { + swaggerParam.Required = true; + } + + // Regex Pattern [RegularExpression] + var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute)); + if (regexAttr != null) + { + string regex = (string)regexAttr.ConstructorArguments[0].Value; + if (swaggerParam is NonBodyParameter) + { + ((NonBodyParameter)swaggerParam).Pattern = regex; + } + } + + // String Length [StringLength] + int? minLenght = null, maxLength = null; + var stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute)); + if (stringLengthAttr != null) + { + if (stringLengthAttr.NamedArguments.Count == 1) + { + minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value; + } + maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value; + } + + var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute)); + if (minLengthAttr != null) + { + minLenght = (int)minLengthAttr.ConstructorArguments[0].Value; + } + + var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute)); + if (maxLengthAttr != null) + { + maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value; + } + + if (swaggerParam is NonBodyParameter) + { + ((NonBodyParameter)swaggerParam).MinLength = minLenght; + ((NonBodyParameter)swaggerParam).MaxLength = maxLength; + } + + // Range [Range] + var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute)); + if (rangeAttr != null) + { + int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value; + int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value; + + if (swaggerParam is NonBodyParameter) + { + ((NonBodyParameter)swaggerParam).Minimum = rangeMin; + ((NonBodyParameter)swaggerParam).Maximum = rangeMax; + } + } + } + } + } + } +} + diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/IO.Swagger.csproj new file mode 100644 index 00000000000..616076b6078 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/IO.Swagger.csproj @@ -0,0 +1,19 @@ + + + IO.Swagger + IO.Swagger + netcoreapp2.2 + true + true + IO.Swagger + IO.Swagger + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/ApiResponse.cs new file mode 100644 index 00000000000..bde662cf557 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/ApiResponse.cs @@ -0,0 +1,147 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + /// + [DataMember(Name="message")] + public string Message { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class ApiResponse {\n"); + sb.Append(" Code: ").Append(Code).Append("\n"); + sb.Append(" Type: ").Append(Type).Append("\n"); + sb.Append(" Message: ").Append(Message).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((ApiResponse)obj); + } + + /// + /// Returns true if ApiResponse instances are equal + /// + /// Instance of ApiResponse to be compared + /// Boolean + public bool Equals(ApiResponse other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Code == other.Code || + Code != null && + Code.Equals(other.Code) + ) && + ( + Type == other.Type || + Type != null && + Type.Equals(other.Type) + ) && + ( + Message == other.Message || + Message != null && + Message.Equals(other.Message) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Code != null) + hashCode = hashCode * 59 + Code.GetHashCode(); + if (Type != null) + hashCode = hashCode * 59 + Type.GetHashCode(); + if (Message != null) + hashCode = hashCode * 59 + Message.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(ApiResponse left, ApiResponse right) + { + return Equals(left, right); + } + + public static bool operator !=(ApiResponse left, ApiResponse right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Body.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Body.cs new file mode 100644 index 00000000000..4c5cdc9511d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Body.cs @@ -0,0 +1,135 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Body : IEquatable + { + /// + /// Updated name of the pet + /// + /// Updated name of the pet + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Updated status of the pet + /// + /// Updated status of the pet + [DataMember(Name="status")] + public string Status { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Body {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" Status: ").Append(Status).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Body)obj); + } + + /// + /// Returns true if Body instances are equal + /// + /// Instance of Body to be compared + /// Boolean + public bool Equals(Body other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + Status == other.Status || + Status != null && + Status.Equals(other.Status) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (Status != null) + hashCode = hashCode * 59 + Status.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Body left, Body right) + { + return Equals(left, right); + } + + public static bool operator !=(Body left, Body right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Category.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Category.cs new file mode 100644 index 00000000000..04516cf2ef7 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Category.cs @@ -0,0 +1,133 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Category : IEquatable + { + /// + /// Gets or Sets Id + /// + [DataMember(Name="id")] + public long? Id { get; set; } + + /// + /// Gets or Sets Name + /// + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Category {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Category)obj); + } + + /// + /// Returns true if Category instances are equal + /// + /// Instance of Category to be compared + /// Boolean + public bool Equals(Category other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Category left, Category right) + { + return Equals(left, right); + } + + public static bool operator !=(Category left, Category right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Order.cs new file mode 100644 index 00000000000..f3bdd1a7cf9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Order.cs @@ -0,0 +1,213 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public enum StatusEnum + { + /// + /// Enum PlacedEnum for placed + /// + [EnumMember(Value = "placed")] + PlacedEnum = 0, + /// + /// Enum ApprovedEnum for approved + /// + [EnumMember(Value = "approved")] + ApprovedEnum = 1, + /// + /// Enum DeliveredEnum for delivered + /// + [EnumMember(Value = "delivered")] + DeliveredEnum = 2 } + + /// + /// Order Status + /// + /// Order Status + [DataMember(Name="status")] + public StatusEnum? Status { get; set; } + + /// + /// Gets or Sets Complete + /// + [DataMember(Name="complete")] + public bool? Complete { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Order {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" PetId: ").Append(PetId).Append("\n"); + sb.Append(" Quantity: ").Append(Quantity).Append("\n"); + sb.Append(" ShipDate: ").Append(ShipDate).Append("\n"); + sb.Append(" Status: ").Append(Status).Append("\n"); + sb.Append(" Complete: ").Append(Complete).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Order)obj); + } + + /// + /// Returns true if Order instances are equal + /// + /// Instance of Order to be compared + /// Boolean + public bool Equals(Order other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + PetId == other.PetId || + PetId != null && + PetId.Equals(other.PetId) + ) && + ( + Quantity == other.Quantity || + Quantity != null && + Quantity.Equals(other.Quantity) + ) && + ( + ShipDate == other.ShipDate || + ShipDate != null && + ShipDate.Equals(other.ShipDate) + ) && + ( + Status == other.Status || + Status != null && + Status.Equals(other.Status) + ) && + ( + Complete == other.Complete || + Complete != null && + Complete.Equals(other.Complete) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (PetId != null) + hashCode = hashCode * 59 + PetId.GetHashCode(); + if (Quantity != null) + hashCode = hashCode * 59 + Quantity.GetHashCode(); + if (ShipDate != null) + hashCode = hashCode * 59 + ShipDate.GetHashCode(); + if (Status != null) + hashCode = hashCode * 59 + Status.GetHashCode(); + if (Complete != null) + hashCode = hashCode * 59 + Complete.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Order left, Order right) + { + return Equals(left, right); + } + + public static bool operator !=(Order left, Order right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Pet.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Pet.cs new file mode 100644 index 00000000000..a3fe54a32b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Pet.cs @@ -0,0 +1,215 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public enum StatusEnum + { + /// + /// Enum AvailableEnum for available + /// + [EnumMember(Value = "available")] + AvailableEnum = 0, + /// + /// Enum PendingEnum for pending + /// + [EnumMember(Value = "pending")] + PendingEnum = 1, + /// + /// Enum SoldEnum for sold + /// + [EnumMember(Value = "sold")] + SoldEnum = 2 } + + /// + /// pet status in the store + /// + /// pet status in the store + [DataMember(Name="status")] + public StatusEnum? Status { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Pet {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Category: ").Append(Category).Append("\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n"); + sb.Append(" Tags: ").Append(Tags).Append("\n"); + sb.Append(" Status: ").Append(Status).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Pet)obj); + } + + /// + /// Returns true if Pet instances are equal + /// + /// Instance of Pet to be compared + /// Boolean + public bool Equals(Pet other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Category == other.Category || + Category != null && + Category.Equals(other.Category) + ) && + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ) && + ( + PhotoUrls == other.PhotoUrls || + PhotoUrls != null && + PhotoUrls.SequenceEqual(other.PhotoUrls) + ) && + ( + Tags == other.Tags || + Tags != null && + Tags.SequenceEqual(other.Tags) + ) && + ( + Status == other.Status || + Status != null && + Status.Equals(other.Status) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Category != null) + hashCode = hashCode * 59 + Category.GetHashCode(); + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + if (PhotoUrls != null) + hashCode = hashCode * 59 + PhotoUrls.GetHashCode(); + if (Tags != null) + hashCode = hashCode * 59 + Tags.GetHashCode(); + if (Status != null) + hashCode = hashCode * 59 + Status.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Pet left, Pet right) + { + return Equals(left, right); + } + + public static bool operator !=(Pet left, Pet right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Tag.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Tag.cs new file mode 100644 index 00000000000..24020bfb3d1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Tag.cs @@ -0,0 +1,133 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Tag : IEquatable + { + /// + /// Gets or Sets Id + /// + [DataMember(Name="id")] + public long? Id { get; set; } + + /// + /// Gets or Sets Name + /// + [DataMember(Name="name")] + public string Name { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Tag {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Tag)obj); + } + + /// + /// Returns true if Tag instances are equal + /// + /// Instance of Tag to be compared + /// Boolean + public bool Equals(Tag other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Name == other.Name || + Name != null && + Name.Equals(other.Name) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Name != null) + hashCode = hashCode * 59 + Name.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Tag left, Tag right) + { + return Equals(left, right); + } + + public static bool operator !=(Tag left, Tag right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Test.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Test.cs new file mode 100644 index 00000000000..7ae6c14633b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/Test.cs @@ -0,0 +1,105 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + public partial class Test : IEquatable + { + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Test {\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Test)obj); + } + + /// + /// Returns true if Test instances are equal + /// + /// Instance of Test to be compared + /// Boolean + public bool Equals(Test other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return false; + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Test left, Test right) + { + return Equals(left, right); + } + + public static bool operator !=(Test left, Test right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/User.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/User.cs new file mode 100644 index 00000000000..b8aa0b5683d --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Models/User.cs @@ -0,0 +1,218 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +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; + +namespace IO.Swagger.Models +{ + /// + /// + /// + [DataContract] + 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 + /// + /// User Status + [DataMember(Name="userStatus")] + public int? UserStatus { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class User {\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Username: ").Append(Username).Append("\n"); + sb.Append(" FirstName: ").Append(FirstName).Append("\n"); + sb.Append(" LastName: ").Append(LastName).Append("\n"); + sb.Append(" Email: ").Append(Email).Append("\n"); + sb.Append(" Password: ").Append(Password).Append("\n"); + sb.Append(" Phone: ").Append(Phone).Append("\n"); + sb.Append(" UserStatus: ").Append(UserStatus).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((User)obj); + } + + /// + /// Returns true if User instances are equal + /// + /// Instance of User to be compared + /// Boolean + public bool Equals(User other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Id == other.Id || + Id != null && + Id.Equals(other.Id) + ) && + ( + Username == other.Username || + Username != null && + Username.Equals(other.Username) + ) && + ( + FirstName == other.FirstName || + FirstName != null && + FirstName.Equals(other.FirstName) + ) && + ( + LastName == other.LastName || + LastName != null && + LastName.Equals(other.LastName) + ) && + ( + Email == other.Email || + Email != null && + Email.Equals(other.Email) + ) && + ( + Password == other.Password || + Password != null && + Password.Equals(other.Password) + ) && + ( + Phone == other.Phone || + Phone != null && + Phone.Equals(other.Phone) + ) && + ( + UserStatus == other.UserStatus || + UserStatus != null && + UserStatus.Equals(other.UserStatus) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + var hashCode = 41; + // Suitable nullity checks etc, of course :) + if (Id != null) + hashCode = hashCode * 59 + Id.GetHashCode(); + if (Username != null) + hashCode = hashCode * 59 + Username.GetHashCode(); + if (FirstName != null) + hashCode = hashCode * 59 + FirstName.GetHashCode(); + if (LastName != null) + hashCode = hashCode * 59 + LastName.GetHashCode(); + if (Email != null) + hashCode = hashCode * 59 + Email.GetHashCode(); + if (Password != null) + hashCode = hashCode * 59 + Password.GetHashCode(); + if (Phone != null) + hashCode = hashCode * 59 + Phone.GetHashCode(); + if (UserStatus != null) + hashCode = hashCode * 59 + UserStatus.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(User left, User right) + { + return Equals(left, right); + } + + public static bool operator !=(User left, User right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Program.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Program.cs new file mode 100644 index 00000000000..ae409c1ecb8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Program.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore; + +namespace IO.Swagger +{ + /// + /// Program + /// + public class Program + { + /// + /// Main + /// + /// + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + /// + /// Create the web host builder. + /// + /// + /// IWebHostBuilder + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Properties/launchSettings.json b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Properties/launchSettings.json new file mode 100644 index 00000000000..21acfed207b --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:50352/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger/", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "web": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "http://localhost:5000/swagger/", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs new file mode 100644 index 00000000000..57b5fd5dfd9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs @@ -0,0 +1,50 @@ +using System; +using System.Net.Http.Headers; +using System.Security.Claims; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace IO.Swagger.Security +{ + /// + /// class to handle api_key security. + /// + public class ApiKeyAuthenticationHandler : AuthenticationHandler + { + /// + /// scheme name for authentication handler. + /// + public const string SchemeName = "ApiKey"; + + public ApiKeyAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) + { + } + + /// + /// verify that require api key header exist and handle authorization. + /// + protected override async Task HandleAuthenticateAsync() + { + if (!Request.Headers.ContainsKey("api_key")) + { + return AuthenticateResult.Fail("Missing Authorization Header"); + } + + // do magic here! + + var claims = new[] { + new Claim(ClaimTypes.NameIdentifier, "changeme"), + new Claim(ClaimTypes.Name, "changeme"), + }; + var identity = new ClaimsIdentity(claims, Scheme.Name); + var principal = new ClaimsPrincipal(identity); + var ticket = new AuthenticationTicket(principal, Scheme.Name); + + return AuthenticateResult.Success(ticket); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Security/BearerAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Security/BearerAuthenticationHandler.cs new file mode 100644 index 00000000000..15c7ab0c928 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Security/BearerAuthenticationHandler.cs @@ -0,0 +1,58 @@ +using System; +using System.Net.Http.Headers; +using System.Security.Claims; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace IO.Swagger.Security +{ + /// + /// class to handle bearer authentication. + /// + public class BearerAuthenticationHandler : AuthenticationHandler + { + /// + /// scheme name for authentication handler. + /// + public const string SchemeName = "Bearer"; + + public BearerAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) + { + } + + /// + /// verify that require authorization header exists. + /// + protected override async Task HandleAuthenticateAsync() + { + if (!Request.Headers.ContainsKey("Authorization")) + { + return AuthenticateResult.Fail("Missing Authorization Header"); + } + try + { + var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); + + /// TODO handle token. + } + catch + { + return AuthenticateResult.Fail("Invalid Authorization Header"); + } + + var claims = new[] { + new Claim(ClaimTypes.NameIdentifier, "changeme"), + new Claim(ClaimTypes.Name, "changeme"), + }; + var identity = new ClaimsIdentity(claims, Scheme.Name); + var principal = new ClaimsPrincipal(identity); + var ticket = new AuthenticationTicket(principal, Scheme.Name); + + return AuthenticateResult.Success(ticket); + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Startup.cs b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Startup.cs new file mode 100644 index 00000000000..43c2a2fea58 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/Startup.cs @@ -0,0 +1,132 @@ +/* + * Swagger Petstore + * + * This is a sample Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ +using System; +using System.IO; +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.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; +using IO.Swagger.Filters; +using IO.Swagger.Security; + +using Microsoft.AspNetCore.Authentication; + +namespace IO.Swagger +{ + /// + /// Startup + /// + public class Startup + { + private readonly IHostingEnvironment _hostingEnv; + + private IConfiguration Configuration { get; } + + /// + /// Constructor + /// + /// + /// + public Startup(IHostingEnvironment env, IConfiguration configuration) + { + _hostingEnv = env; + Configuration = configuration; + } + + /// + /// 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(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter { + CamelCaseText = true + }); + }) + .AddXmlSerializerFormatters(); + + services.AddAuthentication(ApiKeyAuthenticationHandler.SchemeName) + .AddScheme(ApiKeyAuthenticationHandler.SchemeName, null); + + services.AddAuthentication(BearerAuthenticationHandler.SchemeName) + .AddScheme(BearerAuthenticationHandler.SchemeName, null); + + + services + .AddSwaggerGen(c => + { + c.SwaggerDoc("1.0.0", new Info + { + Version = "1.0.0", + Title = "Swagger Petstore", + Description = "Swagger Petstore (ASP.NET Core 2.0)", + Contact = new Contact() + { + Name = "Swagger Codegen Contributors", + Url = "https://github.com/swagger-api/swagger-codegen", + Email = "apiteam@swagger.io" + }, + TermsOfService = "http://swagger.io/terms/" + }); + c.CustomSchemaIds(type => type.FriendlyId(true)); + c.DescribeAllEnumsAsStrings(); + c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); + + // 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(); + }); + } + + /// + /// 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) + { + app + .UseMvc() + .UseDefaultFiles() + .UseStaticFiles() + .UseSwagger() + .UseSwaggerUI(c => + { + //TODO: Either use the SwaggerGen generated Swagger contract (generated from C# classes) + c.SwaggerEndpoint("/swagger/1.0.0/swagger.json", "Swagger Petstore"); + + //TODO: Or alternatively use the original Swagger contract that's included in the static files + // c.SwaggerEndpoint("/swagger-original.json", "Swagger Petstore Original"); + }); + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + //TODO: Enable production exception handling (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling) + // app.UseExceptionHandler("/Home/Error"); + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/appsettings.json b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/appsettings.json new file mode 100644 index 00000000000..c6af7d9b069 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Information", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/web.config b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/web.config new file mode 100644 index 00000000000..a3b9f6add9c --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/web.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/README.md b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/README.md new file mode 100644 index 00000000000..6a0b78471a3 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/README.md @@ -0,0 +1,42 @@ +# Welcome to ASP.NET 5 Preview + +We've made some big updates in this release, so it’s **important** that you spend a few minutes to learn what’s new. + +ASP.NET 5 has been rearchitected to make it **lean** and **composable**. It's fully **open source** and available on [GitHub](http://go.microsoft.com/fwlink/?LinkID=517854). +Your new project automatically takes advantage of modern client-side utilities like [Bower](http://go.microsoft.com/fwlink/?LinkId=518004) and [npm](http://go.microsoft.com/fwlink/?LinkId=518005) (to add client-side libraries) and [Gulp](http://go.microsoft.com/fwlink/?LinkId=518007) (for client-side build and automation tasks). + +We hope you enjoy the new capabilities in ASP.NET 5 and Visual Studio 2015. +The ASP.NET Team + +### You've created a new ASP.NET 5 project. [Learn what's new](http://go.microsoft.com/fwlink/?LinkId=518016) + +### This application consists of: +* Sample pages using ASP.NET MVC 6 +* [Gulp](http://go.microsoft.com/fwlink/?LinkId=518007) and [Bower](http://go.microsoft.com/fwlink/?LinkId=518004) for managing client-side resources +* Theming using [Bootstrap](http://go.microsoft.com/fwlink/?LinkID=398939) + +#### NEW CONCEPTS +* [The 'wwwroot' explained](http://go.microsoft.com/fwlink/?LinkId=518008) +* [Configuration in ASP.NET 5](http://go.microsoft.com/fwlink/?LinkId=518012) +* [Dependency Injection](http://go.microsoft.com/fwlink/?LinkId=518013) +* [Razor TagHelpers](http://go.microsoft.com/fwlink/?LinkId=518014) +* [Manage client packages using Gulp](http://go.microsoft.com/fwlink/?LinkID=517849) +* [Develop on different platforms](http://go.microsoft.com/fwlink/?LinkID=517850) + +#### CUSTOMIZE APP +* [Add Controllers and Views](http://go.microsoft.com/fwlink/?LinkID=398600) +* [Add Data using EntityFramework](http://go.microsoft.com/fwlink/?LinkID=398602) +* [Add Authentication using Identity](http://go.microsoft.com/fwlink/?LinkID=398603) +* [Add real time support using SignalR](http://go.microsoft.com/fwlink/?LinkID=398606) +* [Add Class library](http://go.microsoft.com/fwlink/?LinkID=398604) +* [Add Web APIs with MVC 6](http://go.microsoft.com/fwlink/?LinkId=518009) +* [Add client packages using Bower](http://go.microsoft.com/fwlink/?LinkID=517848) + +#### DEPLOY +* [Run your app locally](http://go.microsoft.com/fwlink/?LinkID=517851) +* [Run your app on ASP.NET Core 5](http://go.microsoft.com/fwlink/?LinkID=517852) +* [Run commands in your 'project.json'](http://go.microsoft.com/fwlink/?LinkID=517853) +* [Publish to Microsoft Azure Web Sites](http://go.microsoft.com/fwlink/?LinkID=398609) +* [Publish to the file system](http://go.microsoft.com/fwlink/?LinkId=518019) + +We would love to hear your [feedback](http://go.microsoft.com/fwlink/?LinkId=518015) diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/index.html b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/index.html new file mode 100644 index 00000000000..cde1f2f90b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/swagger-original.json b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/swagger-original.json new file mode 100644 index 00000000000..541b4da3d17 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/swagger-original.json @@ -0,0 +1,1030 @@ +{ + "openapi" : "3.0.1", + "info" : { + "title" : "Swagger Petstore", + "description" : "This is a sample Petstore server. You can find\nout more about Swagger at\n[http://swagger.io](http://swagger.io) or on\n[irc.freenode.net, #swagger](http://swagger.io/irc/).\n", + "termsOfService" : "http://swagger.io/terms/", + "contact" : { + "email" : "apiteam@swagger.io" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version" : "1.0.0" + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + }, + "servers" : [ { + "url" : "/" + } ], + "tags" : [ { + "name" : "pet", + "description" : "Everything about your Pets", + "externalDocs" : { + "description" : "Find out more", + "url" : "http://swagger.io" + } + }, { + "name" : "store", + "description" : "Access to Petstore orders" + }, { + "name" : "user", + "description" : "Operations about user", + "externalDocs" : { + "description" : "Find out more about our store", + "url" : "http://swagger.io" + } + } ], + "paths" : { + "/pet" : { + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "operationId" : "updatePet", + "requestBody" : { + "$ref" : "#/components/requestBodies/Pet" + }, + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "operationId" : "addPet", + "requestBody" : { + "$ref" : "#/components/requestBodies/Pet" + }, + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByStatus" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by status", + "description" : "Multiple status values can be provided with comma separated strings", + "operationId" : "findPetsByStatus", + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + } + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + }, + "x-content-type" : "application/json" + } + }, + "application/xml" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + } + } + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Muliple tags can be provided with comma separated strings. Use\\ \\ tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "array", + "items" : { + "type" : "string" + } + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + }, + "x-content-type" : "application/json" + } + }, + "application/xml" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Pet" + } + } + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "deprecated" : true, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "api_key" : [ ] + } ] + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Updates a pet in the store with form data", + "operationId" : "updatePetWithForm", + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "requestBody" : { + "content" : { + "application/x-www-form-urlencoded" : { + "schema" : { + "$ref" : "#/components/schemas/body" + } + } + } + }, + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "operationId" : "deletePet", + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "operationId" : "uploadFile", + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int64" + } + } ], + "requestBody" : { + "content" : { + "application/octet-stream" : { + "schema" : { + "type" : "string", + "format" : "binary" + } + } + } + }, + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/ApiResponse" + } + } + } + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/store/inventory" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Returns pet inventories by status", + "description" : "Returns a map of status codes to quantities", + "operationId" : "getInventory", + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + }, + "x-content-type" : "application/json" + } + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ] + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "operationId" : "placeOrder", + "requestBody" : { + "description" : "order placed for purchasing the pet", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + } + } + }, + "400" : { + "description" : "Invalid Order" + } + } + } + }, + "/store/order/{orderId}" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Find purchase order by ID", + "description" : "For valid response try integer IDs with value >= 1 and <= 10.\\ \\ Other values will generated exceptions", + "operationId" : "getOrderById", + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "maximum" : 10, + "minimum" : 1, + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Order" + } + } + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + } + }, + "delete" : { + "tags" : [ "store" ], + "summary" : "Delete purchase order by ID", + "description" : "For valid response try integer IDs with positive integer value.\\ \\ Negative or non-integer values will generate API errors", + "operationId" : "deleteOrder", + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "minimum" : 1, + "type" : "integer", + "format" : "int64" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + } + } + }, + "/user" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Create user", + "description" : "This can only be done by the logged in user.", + "operationId" : "createUser", + "requestBody" : { + "description" : "Created user object", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + } + }, + "required" : true + }, + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "operationId" : "createUsersWithArrayInput", + "requestBody" : { + "$ref" : "#/components/requestBodies/UserArray" + }, + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "operationId" : "createUsersWithListInput", + "requestBody" : { + "$ref" : "#/components/requestBodies/UserArray" + }, + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "operationId" : "loginUser", + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "string" + } + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "headers" : { + "X-Rate-Limit" : { + "description" : "calls per hour allowed by the user", + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "integer", + "format" : "int32" + } + }, + "X-Expires-After" : { + "description" : "date in UTC when token expires", + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string", + "format" : "date-time" + } + } + }, + "content" : { + "application/json" : { + "schema" : { + "type" : "string", + "x-content-type" : "application/json" + } + }, + "application/xml" : { + "schema" : { + "type" : "string" + } + } + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + } + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "operationId" : "logoutUser", + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "operationId" : "getUserByName", + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing.", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + } + } + }, + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + }, + "put" : { + "tags" : [ "user" ], + "summary" : "Updated user", + "description" : "This can only be done by the logged in user.", + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be updated", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + } ], + "requestBody" : { + "description" : "Updated user object", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/User" + } + } + }, + "required" : true + }, + "responses" : { + "400" : { + "description" : "Invalid user supplied" + }, + "404" : { + "description" : "User not found" + } + } + }, + "delete" : { + "tags" : [ "user" ], + "summary" : "Delete user", + "description" : "This can only be done by the logged in user.", + "operationId" : "deleteUser", + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "style" : "simple", + "explode" : false, + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + } + }, + "/test" : { + "get" : { + "operationId" : "testMethod", + "responses" : { + "200" : { + "description" : "peticion realizada con exito", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/Test" + }, + "x-content-type" : "application/json" + } + } + } + } + }, + "security" : [ { + "bearer" : [ ] + } ] + } + } + }, + "components" : { + "schemas" : { + "Order" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "petId" : { + "type" : "integer", + "format" : "int64" + }, + "quantity" : { + "type" : "integer", + "format" : "int32" + }, + "shipDate" : { + "type" : "string", + "format" : "date-time" + }, + "status" : { + "type" : "string", + "description" : "Order Status", + "enum" : [ "placed", "approved", "delivered" ] + }, + "complete" : { + "type" : "boolean", + "default" : false + } + }, + "example" : { + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" + }, + "xml" : { + "name" : "Order" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "example" : { + "name" : "name", + "id" : 6 + }, + "xml" : { + "name" : "Category" + } + }, + "User" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "username" : { + "type" : "string" + }, + "firstName" : { + "type" : "string" + }, + "lastName" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "password" : { + "type" : "string" + }, + "phone" : { + "type" : "string" + }, + "userStatus" : { + "type" : "integer", + "description" : "User Status", + "format" : "int32" + } + }, + "example" : { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" + }, + "xml" : { + "name" : "User" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "example" : { + "name" : "name", + "id" : 1 + }, + "xml" : { + "name" : "Tag" + } + }, + "Pet" : { + "required" : [ "name", "photoUrls" ], + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/components/schemas/Category" + }, + "name" : { + "type" : "string", + "example" : "doggie" + }, + "photoUrls" : { + "type" : "array", + "xml" : { + "name" : "photoUrl", + "wrapped" : true + }, + "items" : { + "type" : "string" + } + }, + "tags" : { + "type" : "array", + "xml" : { + "name" : "tag", + "wrapped" : true + }, + "items" : { + "$ref" : "#/components/schemas/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "example" : { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" + }, + "xml" : { + "name" : "Pet" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "example" : { + "code" : 0, + "type" : "type", + "message" : "message" + } + }, + "Test" : { + "type" : "string" + }, + "body" : { + "type" : "object", + "properties" : { + "name" : { + "type" : "string", + "description" : "Updated name of the pet" + }, + "status" : { + "type" : "string", + "description" : "Updated status of the pet" + } + } + } + }, + "requestBodies" : { + "Pet" : { + "description" : "Pet object that needs to be added to the store", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "required" : true + }, + "UserArray" : { + "description" : "List of user object", + "content" : { + "application/json" : { + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/User" + } + } + } + }, + "required" : true + } + }, + "securitySchemes" : { + "bearer" : { + "type" : "http", + "scheme" : "bearer" + }, + "petstore_auth" : { + "type" : "oauth2", + "flows" : { + "implicit" : { + "authorizationUrl" : "http://petstore.swagger.io/oauth/dialog", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + } + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + } + } +} diff --git a/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/web.config b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/web.config new file mode 100644 index 00000000000..e70a7778d60 --- /dev/null +++ b/samples/server/petstore/aspnetcore-interface-only/src/IO.Swagger/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + +