From 07a0c5b5968640e5762c2a19394a2a8d55f6fdfb Mon Sep 17 00:00:00 2001 From: HugoMario Date: Fri, 15 May 2020 06:00:48 -0500 Subject: [PATCH 1/4] added bin scripts for version 2.2 --- ....2-petstore-server-interface-controller.sh | 31 +++++++++++++++++++ ...ore-v2.2-petstore-server-interface-only.sh | 31 +++++++++++++++++++ bin/aspnetcore-v2.2-petstore-server.sh | 31 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100755 bin/aspnetcore-v2.2-petstore-server-interface-controller.sh create mode 100755 bin/aspnetcore-v2.2-petstore-server-interface-only.sh create mode 100755 bin/aspnetcore-v2.2-petstore-server.sh diff --git a/bin/aspnetcore-v2.2-petstore-server-interface-controller.sh b/bin/aspnetcore-v2.2-petstore-server-interface-controller.sh new file mode 100755 index 00000000000..76b4a0f6b7f --- /dev/null +++ b/bin/aspnetcore-v2.2-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 -DloggerPath=conf/log4j.properties" +ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/aspnetcore-v2.2-interface-controller --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties interface-controller=true --additional-properties aspnetCoreVersion=2.2" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/aspnetcore-v2.2-petstore-server-interface-only.sh b/bin/aspnetcore-v2.2-petstore-server-interface-only.sh new file mode 100755 index 00000000000..4def1987d0a --- /dev/null +++ b/bin/aspnetcore-v2.2-petstore-server-interface-only.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 -DloggerPath=conf/log4j.properties" +ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/aspnetcore-v2.2-interface-only --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties interface-only=true --additional-properties aspnetCoreVersion=2.2" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/aspnetcore-v2.2-petstore-server.sh b/bin/aspnetcore-v2.2-petstore-server.sh new file mode 100755 index 00000000000..2eca7939a43 --- /dev/null +++ b/bin/aspnetcore-v2.2-petstore-server.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 -DloggerPath=conf/log4j.properties" +ags="$@ generate -l aspnetcore -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/aspnetcore-v2.2 --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties aspnetCoreVersion=2.2" + +java $JAVA_OPTS -jar $executable $ags From dd6b4ad34865838fee166f7fdf92d69181d30e76 Mon Sep 17 00:00:00 2001 From: HugoMario Date: Fri, 15 May 2020 06:01:08 -0500 Subject: [PATCH 2/4] point 2.2 templates to the right location --- .../io/swagger/codegen/languages/AspNetCoreServerCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java index 235c6ccdbac..aa14075c5d5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AspNetCoreServerCodegen.java @@ -140,7 +140,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("Program.mustache", packageFolder, "Program.cs")); supportingFiles.add(new SupportingFile("Project.csproj.mustache", packageFolder, this.packageName + ".csproj")); supportingFiles.add(new SupportingFile("Dockerfile.mustache", packageFolder, "Dockerfile")); - } else if (this.aspNetCoreVersion.equals("2.1")) { + } else if (this.aspNetCoreVersion.equals("2.1") || this.aspNetCoreVersion.equals("2.2")) { apiTemplateFiles.put("2.1/controller.mustache", ".cs"); addInterfaceControllerTemplate(interfaceOnly, interfaceController); From b1b4c4703cfd3e93dd394669b89b266792a4dd5c Mon Sep 17 00:00:00 2001 From: HugoMario Date: Fri, 15 May 2020 06:01:24 -0500 Subject: [PATCH 3/4] fixed erros on startup templates --- .../src/main/resources/aspnetcore/3.0/Startup.mustache | 4 ++-- .../src/main/resources/aspnetcore/Startup.mustache | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/3.0/Startup.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/3.0/Startup.mustache index 6e5bfd324d2..64b3ea9b916 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/3.0/Startup.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/3.0/Startup.mustache @@ -89,8 +89,8 @@ namespace {{packageName}} Name = "{{#infoName}}{{{infoName}}}{{/infoName}}{{^infoName}}Swagger Codegen Contributors{{/infoName}}", Url = new Uri("{{#infoUrl}}{{{infoUrl}}}{{/infoUrl}}{{^infoUrl}}https://github.com/swagger-api/swagger-codegen{{/infoUrl}}"), Email = "{{#infoEmail}}{{{infoEmail}}}{{/infoEmail}}" - }{{#termsOfService}}{, - TermsOfService = new Uri("{{termsOfService}}")}{{/termsOfService}} + },{{#termsOfService}} + TermsOfService = "{{termsOfService}}"{{/termsOfService}} }); c.CustomSchemaIds(type => type.FullName); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); diff --git a/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache b/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache index 5137f2f1f17..8226e7a1b57 100644 --- a/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache +++ b/modules/swagger-codegen/src/main/resources/aspnetcore/Startup.mustache @@ -86,8 +86,8 @@ namespace {{packageName}} Name = "{{#infoName}}{{{infoName}}}{{/infoName}}{{^infoName}}Swagger Codegen Contributors{{/infoName}}", Url = "{{#infoUrl}}{{{infoUrl}}}{{/infoUrl}}{{^infoUrl}}https://github.com/swagger-api/swagger-codegen{{/infoUrl}}", Email = "{{#infoEmail}}{{{infoEmail}}}{{/infoEmail}}" - }{{#termsOfService}}{, - TermsOfService = "{{termsOfService}}"}{{/termsOfService}} + }, + TermsOfService = "{{#termsOfService}}{{{termsOfService}}}{{/termsOfService}}" }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.DescribeAllEnumsAsStrings(); From c86f03a5af07d90398fcde2b26502fe14f823757 Mon Sep 17 00:00:00 2001 From: HugoMario Date: Fri, 15 May 2020 06:01:36 -0500 Subject: [PATCH 4/4] added samples for aspnet 2.2 --- .../.swagger-codegen-ignore | 23 + .../.swagger-codegen/VERSION | 1 + .../IO.Swagger.sln | 21 + .../NuGet.Config | 9 + .../README.md | 25 + .../build.bat | 9 + .../build.sh | 8 + .../src/IO.Swagger/.gitignore | 208 ++++ .../Attributes/ValidateModelStateAttribute.cs | 61 ++ .../src/IO.Swagger/Controllers/IPetApi.cs | 100 ++ .../src/IO.Swagger/Controllers/IStoreApi.cs | 60 ++ .../src/IO.Swagger/Controllers/IUserApi.cs | 95 ++ .../src/IO.Swagger/Controllers/PetApi.cs | 244 +++++ .../src/IO.Swagger/Controllers/StoreApi.cs | 146 +++ .../src/IO.Swagger/Controllers/UserApi.cs | 220 +++++ .../src/IO.Swagger/Dockerfile | 18 + .../src/IO.Swagger/Filters/BasePathFilter.cs | 50 + .../GeneratePathParamsValidationFilter.cs | 97 ++ .../src/IO.Swagger/IO.Swagger.csproj | 19 + .../src/IO.Swagger/Models/Amount.cs | 137 +++ .../src/IO.Swagger/Models/ApiResponse.cs | 148 +++ .../src/IO.Swagger/Models/Category.cs | 134 +++ .../src/IO.Swagger/Models/Currency.cs | 106 +++ .../src/IO.Swagger/Models/Order.cs | 218 +++++ .../src/IO.Swagger/Models/Pet.cs | 220 +++++ .../src/IO.Swagger/Models/Tag.cs | 134 +++ .../src/IO.Swagger/Models/User.cs | 219 +++++ .../src/IO.Swagger/Program.cs | 29 + .../IO.Swagger/Properties/launchSettings.json | 28 + .../Security/ApiKeyAuthenticationHandler.cs | 50 + .../src/IO.Swagger/Startup.cs | 132 +++ .../src/IO.Swagger/appsettings.json | 10 + .../src/IO.Swagger/web.config | 14 + .../src/IO.Swagger/wwwroot/index.html | 1 + .../IO.Swagger/wwwroot/swagger-original.json | 901 ++++++++++++++++++ .../src/IO.Swagger/wwwroot/web.config | 9 + .../.swagger-codegen-ignore | 23 + .../.swagger-codegen/VERSION | 1 + .../IO.Swagger.sln | 21 + .../NuGet.Config | 9 + .../aspnetcore-v2.2-interface-only/README.md | 25 + .../aspnetcore-v2.2-interface-only/build.bat | 9 + .../aspnetcore-v2.2-interface-only/build.sh | 8 + .../src/IO.Swagger/.gitignore | 208 ++++ .../Attributes/ValidateModelStateAttribute.cs | 61 ++ .../src/IO.Swagger/Controllers/IPetApi.cs | 100 ++ .../src/IO.Swagger/Controllers/IStoreApi.cs | 60 ++ .../src/IO.Swagger/Controllers/IUserApi.cs | 95 ++ .../src/IO.Swagger/Dockerfile | 18 + .../src/IO.Swagger/Filters/BasePathFilter.cs | 50 + .../GeneratePathParamsValidationFilter.cs | 97 ++ .../src/IO.Swagger/IO.Swagger.csproj | 19 + .../src/IO.Swagger/Models/Amount.cs | 137 +++ .../src/IO.Swagger/Models/ApiResponse.cs | 148 +++ .../src/IO.Swagger/Models/Category.cs | 134 +++ .../src/IO.Swagger/Models/Currency.cs | 106 +++ .../src/IO.Swagger/Models/Order.cs | 218 +++++ .../src/IO.Swagger/Models/Pet.cs | 220 +++++ .../src/IO.Swagger/Models/Tag.cs | 134 +++ .../src/IO.Swagger/Models/User.cs | 219 +++++ .../src/IO.Swagger/Program.cs | 29 + .../IO.Swagger/Properties/launchSettings.json | 28 + .../Security/ApiKeyAuthenticationHandler.cs | 50 + .../src/IO.Swagger/Startup.cs | 132 +++ .../src/IO.Swagger/appsettings.json | 10 + .../src/IO.Swagger/web.config | 14 + .../src/IO.Swagger/wwwroot/index.html | 1 + .../IO.Swagger/wwwroot/swagger-original.json | 901 ++++++++++++++++++ .../src/IO.Swagger/wwwroot/web.config | 9 + .../aspnetcore-v2.2/.swagger-codegen-ignore | 23 + .../aspnetcore-v2.2/.swagger-codegen/VERSION | 1 + .../petstore/aspnetcore-v2.2/IO.Swagger.sln | 21 + .../petstore/aspnetcore-v2.2/NuGet.Config | 9 + .../server/petstore/aspnetcore-v2.2/README.md | 25 + .../server/petstore/aspnetcore-v2.2/build.bat | 9 + .../server/petstore/aspnetcore-v2.2/build.sh | 8 + .../aspnetcore-v2.2/src/IO.Swagger/.gitignore | 208 ++++ .../Attributes/ValidateModelStateAttribute.cs | 61 ++ .../src/IO.Swagger/Controllers/PetApi.cs | 244 +++++ .../src/IO.Swagger/Controllers/StoreApi.cs | 146 +++ .../src/IO.Swagger/Controllers/UserApi.cs | 220 +++++ .../aspnetcore-v2.2/src/IO.Swagger/Dockerfile | 18 + .../src/IO.Swagger/Filters/BasePathFilter.cs | 50 + .../GeneratePathParamsValidationFilter.cs | 97 ++ .../src/IO.Swagger/IO.Swagger.csproj | 19 + .../src/IO.Swagger/Models/Amount.cs | 137 +++ .../src/IO.Swagger/Models/ApiResponse.cs | 148 +++ .../src/IO.Swagger/Models/Category.cs | 134 +++ .../src/IO.Swagger/Models/Currency.cs | 106 +++ .../src/IO.Swagger/Models/Order.cs | 218 +++++ .../src/IO.Swagger/Models/Pet.cs | 220 +++++ .../src/IO.Swagger/Models/Tag.cs | 134 +++ .../src/IO.Swagger/Models/User.cs | 219 +++++ .../aspnetcore-v2.2/src/IO.Swagger/Program.cs | 29 + .../IO.Swagger/Properties/launchSettings.json | 28 + .../Security/ApiKeyAuthenticationHandler.cs | 50 + .../aspnetcore-v2.2/src/IO.Swagger/Startup.cs | 132 +++ .../src/IO.Swagger/appsettings.json | 10 + .../aspnetcore-v2.2/src/IO.Swagger/web.config | 14 + .../src/IO.Swagger/wwwroot/index.html | 1 + .../IO.Swagger/wwwroot/swagger-original.json | 901 ++++++++++++++++++ .../src/IO.Swagger/wwwroot/web.config | 9 + 102 files changed, 10847 insertions(+) create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/.swagger-codegen-ignore create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/.swagger-codegen/VERSION create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/IO.Swagger.sln create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/NuGet.Config create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/README.md create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/build.bat create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/build.sh create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/.gitignore create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/PetApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/UserApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Dockerfile create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/IO.Swagger.csproj create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Amount.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/ApiResponse.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Category.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Currency.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Order.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Pet.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Tag.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/User.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Program.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Properties/launchSettings.json create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Startup.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/appsettings.json create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/web.config create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/index.html create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/web.config create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/.swagger-codegen-ignore create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/.swagger-codegen/VERSION create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/IO.Swagger.sln create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/NuGet.Config create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/README.md create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/build.bat create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/build.sh create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/.gitignore create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IPetApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IUserApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Dockerfile create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Filters/BasePathFilter.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/IO.Swagger.csproj create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Amount.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/ApiResponse.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Category.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Currency.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Order.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Pet.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Tag.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/User.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Program.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Properties/launchSettings.json create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Startup.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/appsettings.json create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/web.config create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/index.html create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/swagger-original.json create mode 100644 samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/web.config create mode 100644 samples/server/petstore/aspnetcore-v2.2/.swagger-codegen-ignore create mode 100644 samples/server/petstore/aspnetcore-v2.2/.swagger-codegen/VERSION create mode 100644 samples/server/petstore/aspnetcore-v2.2/IO.Swagger.sln create mode 100644 samples/server/petstore/aspnetcore-v2.2/NuGet.Config create mode 100644 samples/server/petstore/aspnetcore-v2.2/README.md create mode 100644 samples/server/petstore/aspnetcore-v2.2/build.bat create mode 100644 samples/server/petstore/aspnetcore-v2.2/build.sh create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/.gitignore create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/PetApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/StoreApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/UserApi.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Dockerfile create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Filters/BasePathFilter.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/IO.Swagger.csproj create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Amount.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/ApiResponse.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Category.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Currency.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Order.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Pet.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Tag.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/User.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Program.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Properties/launchSettings.json create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Startup.cs create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/appsettings.json create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/web.config create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/index.html create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/swagger-original.json create mode 100644 samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/web.config diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/.swagger-codegen-ignore b/samples/server/petstore/aspnetcore-v2.2-interface-controller/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/.swagger-codegen/VERSION b/samples/server/petstore/aspnetcore-v2.2-interface-controller/.swagger-codegen/VERSION new file mode 100644 index 00000000000..91fb2f83cd4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.4.14-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/IO.Swagger.sln b/samples/server/petstore/aspnetcore-v2.2-interface-controller/IO.Swagger.sln new file mode 100644 index 00000000000..045f3a11a74 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/NuGet.Config b/samples/server/petstore/aspnetcore-v2.2-interface-controller/NuGet.Config new file mode 100644 index 00000000000..01f3d1f203f --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/README.md b/samples/server/petstore/aspnetcore-v2.2-interface-controller/README.md new file mode 100644 index 00000000000..730f1daffcd --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/README.md @@ -0,0 +1,25 @@ +# IO.Swagger - ASP.NET Core 2.2 Server + +This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + +## 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-v2.2-interface-controller/build.bat b/samples/server/petstore/aspnetcore-v2.2-interface-controller/build.bat new file mode 100644 index 00000000000..2e041233a06 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/build.sh b/samples/server/petstore/aspnetcore-v2.2-interface-controller/build.sh new file mode 100644 index 00000000000..ce6063a2f49 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/.gitignore b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/.gitignore new file mode 100644 index 00000000000..cd9b840e549 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs new file mode 100644 index 00000000000..07cfabe83cf --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs new file mode 100644 index 00000000000..2518b3c76d8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IPetApi.cs @@ -0,0 +1,100 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 pet value + 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 + /// + /// Multiple 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); + + /// + /// Updates a pet in the store with form data + /// + + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + /// Invalid input + IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status); + + /// + /// uploads an image + /// + + /// ID of pet to update + /// Additional data to pass to server + /// file to upload + /// successful operation + IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream _file); + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs new file mode 100644 index 00000000000..2b62c7b372c --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IStoreApi.cs @@ -0,0 +1,60 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 value < 1000. Anything above 1000 or nonintegers will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + IActionResult DeleteOrder([FromRoute][Required]string 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 <= 5 or > 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, 5)]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-v2.2-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs new file mode 100644 index 00000000000..a01e5b3a8cd --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/IUserApi.cs @@ -0,0 +1,95 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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. + /// name that need to be deleted + /// Updated user object + /// Invalid user supplied + /// User not found + IActionResult UpdateUser([FromRoute][Required]string username, [FromBody]User body); + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/PetApi.cs new file mode 100644 index 00000000000..5986bcf59e3 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/PetApi.cs @@ -0,0 +1,244 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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("/v2/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 pet value + [HttpDelete] + [Route("/v2/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); + + + 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("/v2/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 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + 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 + /// + /// Multiple 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("/v2/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 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + 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("/v2/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 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + 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("/v2/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(); + } + + /// + /// Updates a pet in the store with form data + /// + + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + /// Invalid input + [HttpPost] + [Route("/v2/pet/{petId}")] + [ValidateModelState] + [SwaggerOperation("UpdatePetWithForm")] + public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status) + { + //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 + /// Additional data to pass to server + /// file to upload + /// successful operation + [HttpPost] + [Route("/v2/pet/{petId}/uploadImage")] + [ValidateModelState] + [SwaggerOperation("UploadFile")] + [SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")] + public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream _file) + { + //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-v2.2-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs new file mode 100644 index 00000000000..f888dbb4e58 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/StoreApi.cs @@ -0,0 +1,146 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 value < 1000. Anything above 1000 or nonintegers will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + [HttpDelete] + [Route("/v2/store/order/{orderId}")] + [ValidateModelState] + [SwaggerOperation("DeleteOrder")] + public virtual IActionResult DeleteOrder([FromRoute][Required]string 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("/v2/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 <= 5 or > 10. Other values will generated exceptions + /// ID of pet that needs to be fetched + /// successful operation + /// Invalid ID supplied + /// Order not found + [HttpGet] + [Route("/v2/store/order/{orderId}")] + [ValidateModelState] + [SwaggerOperation("GetOrderById")] + [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] + public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 5)]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 123456789\n 123456789\n 123\n 2000-01-23T04:56:07.000Z\n aeiou\n true\n"; + 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("/v2/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 123456789\n 123456789\n 123\n 2000-01-23T04:56:07.000Z\n aeiou\n true\n"; + 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-v2.2-interface-controller/src/IO.Swagger/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/UserApi.cs new file mode 100644 index 00000000000..67703ff0cff --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Controllers/UserApi.cs @@ -0,0 +1,220 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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("/v2/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("/v2/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("/v2/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("/v2/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("/v2/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 123456789\n aeiou\n aeiou\n aeiou\n aeiou\n aeiou\n aeiou\n 123\n"; + 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("/v2/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 = "aeiou"; + 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("/v2/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. + /// name that need to be deleted + /// Updated user object + /// Invalid user supplied + /// User not found + [HttpPut] + [Route("/v2/user/{username}")] + [ValidateModelState] + [SwaggerOperation("UpdateUser")] + public virtual IActionResult UpdateUser([FromRoute][Required]string username, [FromBody]User 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); + + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Dockerfile b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Dockerfile new file mode 100644 index 00000000000..967c8195c2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Filters/BasePathFilter.cs new file mode 100644 index 00000000000..f3c528eada2 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs new file mode 100644 index 00000000000..a0e2cb6871d --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/IO.Swagger.csproj new file mode 100644 index 00000000000..616076b6078 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Models/Amount.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Amount.cs new file mode 100644 index 00000000000..63839c2f8a1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Amount.cs @@ -0,0 +1,137 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// some description + /// + [DataContract] + public partial class Amount : IEquatable + { + /// + /// some description + /// + /// some description + [Required] + [DataMember(Name="value")] + public double? Value { get; set; } + + /// + /// Gets or Sets Currency + /// + [Required] + [DataMember(Name="currency")] + public Currency Currency { 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 Amount {\n"); + sb.Append(" Value: ").Append(Value).Append("\n"); + sb.Append(" Currency: ").Append(Currency).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((Amount)obj); + } + + /// + /// Returns true if Amount instances are equal + /// + /// Instance of Amount to be compared + /// Boolean + public bool Equals(Amount other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Value == other.Value || + Value != null && + Value.Equals(other.Value) + ) && + ( + Currency == other.Currency || + Currency != null && + Currency.Equals(other.Currency) + ); + } + + /// + /// 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 (Value != null) + hashCode = hashCode * 59 + Value.GetHashCode(); + if (Currency != null) + hashCode = hashCode * 59 + Currency.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Amount left, Amount right) + { + return Equals(left, right); + } + + public static bool operator !=(Amount left, Amount right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/ApiResponse.cs new file mode 100644 index 00000000000..eb444479ec4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/ApiResponse.cs @@ -0,0 +1,148 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// Describes the result of uploading an image resource + /// + [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-v2.2-interface-controller/src/IO.Swagger/Models/Category.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Category.cs new file mode 100644 index 00000000000..0f9df0830c4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Category.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A category for a pet + /// + [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-v2.2-interface-controller/src/IO.Swagger/Models/Currency.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Currency.cs new file mode 100644 index 00000000000..a5a499265cb --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Currency.cs @@ -0,0 +1,106 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// some description + /// + [DataContract] + public partial class Currency : IEquatable + { + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Currency {\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((Currency)obj); + } + + /// + /// Returns true if Currency instances are equal + /// + /// Instance of Currency to be compared + /// Boolean + public bool Equals(Currency 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 ==(Currency left, Currency right) + { + return Equals(left, right); + } + + public static bool operator !=(Currency left, Currency right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Order.cs new file mode 100644 index 00000000000..1e617fdf089 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Order.cs @@ -0,0 +1,218 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// An order for a pets from the pet store + /// + [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 = 1, + + /// + /// Enum ApprovedEnum for approved + /// + [EnumMember(Value = "approved")] + ApprovedEnum = 2, + + /// + /// Enum DeliveredEnum for delivered + /// + [EnumMember(Value = "delivered")] + DeliveredEnum = 3 + } + + /// + /// 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-v2.2-interface-controller/src/IO.Swagger/Models/Pet.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Pet.cs new file mode 100644 index 00000000000..fc9884836f0 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Pet.cs @@ -0,0 +1,220 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A pet for sale in the pet store + /// + [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 = 1, + + /// + /// Enum PendingEnum for pending + /// + [EnumMember(Value = "pending")] + PendingEnum = 2, + + /// + /// Enum SoldEnum for sold + /// + [EnumMember(Value = "sold")] + SoldEnum = 3 + } + + /// + /// 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-v2.2-interface-controller/src/IO.Swagger/Models/Tag.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Tag.cs new file mode 100644 index 00000000000..d0cd5b744be --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/Tag.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A tag for a pet + /// + [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-v2.2-interface-controller/src/IO.Swagger/Models/User.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/User.cs new file mode 100644 index 00000000000..4c9df2fd429 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Models/User.cs @@ -0,0 +1,219 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A User who is purchasing from the pet store + /// + [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-v2.2-interface-controller/src/IO.Swagger/Program.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Program.cs new file mode 100644 index 00000000000..ae409c1ecb8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Properties/launchSettings.json b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Properties/launchSettings.json new file mode 100644 index 00000000000..21acfed207b --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs new file mode 100644 index 00000000000..57b5fd5dfd9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/Startup.cs b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Startup.cs new file mode 100644 index 00000000000..73dc4b97234 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/Startup.cs @@ -0,0 +1,132 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 + .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"); + // Sets the basePath property in the Swagger document generated + c.DocumentFilter("/v2"); + + // 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-v2.2-interface-controller/src/IO.Swagger/appsettings.json b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/appsettings.json new file mode 100644 index 00000000000..c6af7d9b069 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-controller/src/IO.Swagger/web.config b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/web.config new file mode 100644 index 00000000000..a3b9f6add9c --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/web.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/index.html b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/index.html new file mode 100644 index 00000000000..cde1f2f90b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json new file mode 100644 index 00000000000..55fa5c40e20 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/swagger-original.json @@ -0,0 +1,901 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "version" : "1.0.0", + "title" : "Swagger Petstore", + "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" + } + }, + "host" : "petstore.swagger.io", + "basePath" : "/v2", + "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" + } + } ], + "schemes" : [ "http" ], + "paths" : { + "/pet" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "description" : "", + "operationId" : "addPet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "description" : "", + "operationId" : "updatePet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "type" : "array", + "items" : { + "type" : "string" + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "deprecated" : true + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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", + "description" : "", + "operationId" : "updatePetWithForm", + "consumes" : [ "application/x-www-form-urlencoded" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "name", + "in" : "formData", + "description" : "Updated name of the pet", + "required" : false, + "type" : "string" + }, { + "name" : "status", + "in" : "formData", + "description" : "Updated status of the pet", + "required" : false, + "type" : "string" + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "description" : "", + "operationId" : "deletePet", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "type" : "string" + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "400" : { + "description" : "Invalid pet value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "description" : "", + "operationId" : "uploadFile", + "consumes" : [ "multipart/form-data" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "additionalMetadata", + "in" : "formData", + "description" : "Additional data to pass to server", + "required" : false, + "type" : "string" + }, { + "name" : "file", + "in" : "formData", + "description" : "file to upload", + "required" : false, + "type" : "file" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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", + "produces" : [ "application/json" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ] + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "description" : "", + "operationId" : "placeOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "order placed for purchasing the pet", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Order" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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 <= 5 or > 10. Other values will generated exceptions", + "operationId" : "getOrderById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "integer", + "maximum" : 5, + "minimum" : 1, + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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 value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId" : "deleteOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Created user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithArrayInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithListInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "description" : "", + "operationId" : "loginUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "type" : "string" + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "headers" : { + "X-Rate-Limit" : { + "type" : "integer", + "format" : "int32", + "description" : "calls per hour allowed by the user" + }, + "X-Expires-After" : { + "type" : "string", + "format" : "date-time", + "description" : "date in UTC when toekn expires" + } + }, + "schema" : { + "type" : "string" + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + } + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "description" : "", + "operationId" : "logoutUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "description" : "", + "operationId" : "getUserByName", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing.", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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.", + "operationId" : "updateUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be deleted", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "body", + "description" : "Updated user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + } + } + }, + "securityDefinitions" : { + "petstore_auth" : { + "type" : "oauth2", + "authorizationUrl" : "http://petstore.swagger.io/api/oauth/dialog", + "flow" : "implicit", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + }, + "definitions" : { + "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 + } + }, + "title" : "Pet Order", + "xml" : { + "name" : "Order" + }, + "description" : "An order for a pets from the pet store", + "example" : { + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet category", + "xml" : { + "name" : "Category" + }, + "description" : "A category for a pet", + "example" : { + "name" : "name", + "id" : 6 + } + }, + "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", + "format" : "int32", + "description" : "User Status" + } + }, + "title" : "a User", + "xml" : { + "name" : "User" + }, + "description" : "A User who is purchasing from the pet store", + "example" : { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet Tag", + "xml" : { + "name" : "Tag" + }, + "description" : "A tag for a pet", + "example" : { + "name" : "name", + "id" : 1 + } + }, + "Pet" : { + "type" : "object", + "required" : [ "name", "photoUrls" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/definitions/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" : "#/definitions/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "title" : "a Pet", + "xml" : { + "name" : "Pet" + }, + "description" : "A pet for sale in the pet store", + "example" : { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "title" : "An uploaded response", + "description" : "Describes the result of uploading an image resource", + "example" : { + "code" : 0, + "type" : "type", + "message" : "message" + } + }, + "Amount" : { + "type" : "object", + "required" : [ "currency", "value" ], + "properties" : { + "value" : { + "type" : "number", + "format" : "double", + "description" : "some description\n", + "minimum" : 0.01, + "maximum" : 1000000000000000 + }, + "currency" : { + "$ref" : "#/definitions/Currency" + } + }, + "description" : "some description\n" + }, + "Currency" : { + "type" : "string", + "pattern" : "^[A-Z]{3,3}$", + "description" : "some description\n" + } + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/web.config b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/web.config new file mode 100644 index 00000000000..e70a7778d60 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-controller/src/IO.Swagger/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/.swagger-codegen-ignore b/samples/server/petstore/aspnetcore-v2.2-interface-only/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/.swagger-codegen/VERSION b/samples/server/petstore/aspnetcore-v2.2-interface-only/.swagger-codegen/VERSION new file mode 100644 index 00000000000..91fb2f83cd4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.4.14-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/IO.Swagger.sln b/samples/server/petstore/aspnetcore-v2.2-interface-only/IO.Swagger.sln new file mode 100644 index 00000000000..045f3a11a74 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/NuGet.Config b/samples/server/petstore/aspnetcore-v2.2-interface-only/NuGet.Config new file mode 100644 index 00000000000..01f3d1f203f --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/README.md b/samples/server/petstore/aspnetcore-v2.2-interface-only/README.md new file mode 100644 index 00000000000..730f1daffcd --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/README.md @@ -0,0 +1,25 @@ +# IO.Swagger - ASP.NET Core 2.2 Server + +This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + +## 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-v2.2-interface-only/build.bat b/samples/server/petstore/aspnetcore-v2.2-interface-only/build.bat new file mode 100644 index 00000000000..2e041233a06 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/build.sh b/samples/server/petstore/aspnetcore-v2.2-interface-only/build.sh new file mode 100644 index 00000000000..ce6063a2f49 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/.gitignore b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/.gitignore new file mode 100644 index 00000000000..cd9b840e549 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs new file mode 100644 index 00000000000..07cfabe83cf --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Controllers/IPetApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IPetApi.cs new file mode 100644 index 00000000000..2518b3c76d8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IPetApi.cs @@ -0,0 +1,100 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 pet value + 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 + /// + /// Multiple 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); + + /// + /// Updates a pet in the store with form data + /// + + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + /// Invalid input + IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status); + + /// + /// uploads an image + /// + + /// ID of pet to update + /// Additional data to pass to server + /// file to upload + /// successful operation + IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream _file); + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs new file mode 100644 index 00000000000..2b62c7b372c --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IStoreApi.cs @@ -0,0 +1,60 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 value < 1000. Anything above 1000 or nonintegers will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + IActionResult DeleteOrder([FromRoute][Required]string 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 <= 5 or > 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, 5)]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-v2.2-interface-only/src/IO.Swagger/Controllers/IUserApi.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IUserApi.cs new file mode 100644 index 00000000000..a01e5b3a8cd --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Controllers/IUserApi.cs @@ -0,0 +1,95 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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. + /// name that need to be deleted + /// Updated user object + /// Invalid user supplied + /// User not found + IActionResult UpdateUser([FromRoute][Required]string username, [FromBody]User body); + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Dockerfile b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Dockerfile new file mode 100644 index 00000000000..967c8195c2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Filters/BasePathFilter.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Filters/BasePathFilter.cs new file mode 100644 index 00000000000..f3c528eada2 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs new file mode 100644 index 00000000000..a0e2cb6871d --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/IO.Swagger.csproj new file mode 100644 index 00000000000..616076b6078 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Models/Amount.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Amount.cs new file mode 100644 index 00000000000..63839c2f8a1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Amount.cs @@ -0,0 +1,137 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// some description + /// + [DataContract] + public partial class Amount : IEquatable + { + /// + /// some description + /// + /// some description + [Required] + [DataMember(Name="value")] + public double? Value { get; set; } + + /// + /// Gets or Sets Currency + /// + [Required] + [DataMember(Name="currency")] + public Currency Currency { 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 Amount {\n"); + sb.Append(" Value: ").Append(Value).Append("\n"); + sb.Append(" Currency: ").Append(Currency).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((Amount)obj); + } + + /// + /// Returns true if Amount instances are equal + /// + /// Instance of Amount to be compared + /// Boolean + public bool Equals(Amount other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Value == other.Value || + Value != null && + Value.Equals(other.Value) + ) && + ( + Currency == other.Currency || + Currency != null && + Currency.Equals(other.Currency) + ); + } + + /// + /// 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 (Value != null) + hashCode = hashCode * 59 + Value.GetHashCode(); + if (Currency != null) + hashCode = hashCode * 59 + Currency.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Amount left, Amount right) + { + return Equals(left, right); + } + + public static bool operator !=(Amount left, Amount right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/ApiResponse.cs new file mode 100644 index 00000000000..eb444479ec4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/ApiResponse.cs @@ -0,0 +1,148 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// Describes the result of uploading an image resource + /// + [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-v2.2-interface-only/src/IO.Swagger/Models/Category.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Category.cs new file mode 100644 index 00000000000..0f9df0830c4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Category.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A category for a pet + /// + [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-v2.2-interface-only/src/IO.Swagger/Models/Currency.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Currency.cs new file mode 100644 index 00000000000..a5a499265cb --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Currency.cs @@ -0,0 +1,106 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// some description + /// + [DataContract] + public partial class Currency : IEquatable + { + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Currency {\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((Currency)obj); + } + + /// + /// Returns true if Currency instances are equal + /// + /// Instance of Currency to be compared + /// Boolean + public bool Equals(Currency 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 ==(Currency left, Currency right) + { + return Equals(left, right); + } + + public static bool operator !=(Currency left, Currency right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Order.cs new file mode 100644 index 00000000000..1e617fdf089 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Order.cs @@ -0,0 +1,218 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// An order for a pets from the pet store + /// + [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 = 1, + + /// + /// Enum ApprovedEnum for approved + /// + [EnumMember(Value = "approved")] + ApprovedEnum = 2, + + /// + /// Enum DeliveredEnum for delivered + /// + [EnumMember(Value = "delivered")] + DeliveredEnum = 3 + } + + /// + /// 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-v2.2-interface-only/src/IO.Swagger/Models/Pet.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Pet.cs new file mode 100644 index 00000000000..fc9884836f0 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Pet.cs @@ -0,0 +1,220 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A pet for sale in the pet store + /// + [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 = 1, + + /// + /// Enum PendingEnum for pending + /// + [EnumMember(Value = "pending")] + PendingEnum = 2, + + /// + /// Enum SoldEnum for sold + /// + [EnumMember(Value = "sold")] + SoldEnum = 3 + } + + /// + /// 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-v2.2-interface-only/src/IO.Swagger/Models/Tag.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Tag.cs new file mode 100644 index 00000000000..d0cd5b744be --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/Tag.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A tag for a pet + /// + [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-v2.2-interface-only/src/IO.Swagger/Models/User.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/User.cs new file mode 100644 index 00000000000..4c9df2fd429 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Models/User.cs @@ -0,0 +1,219 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A User who is purchasing from the pet store + /// + [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-v2.2-interface-only/src/IO.Swagger/Program.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Program.cs new file mode 100644 index 00000000000..ae409c1ecb8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Properties/launchSettings.json b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Properties/launchSettings.json new file mode 100644 index 00000000000..21acfed207b --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs new file mode 100644 index 00000000000..57b5fd5dfd9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/Startup.cs b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Startup.cs new file mode 100644 index 00000000000..73dc4b97234 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/Startup.cs @@ -0,0 +1,132 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 + .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"); + // Sets the basePath property in the Swagger document generated + c.DocumentFilter("/v2"); + + // 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-v2.2-interface-only/src/IO.Swagger/appsettings.json b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/appsettings.json new file mode 100644 index 00000000000..c6af7d9b069 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-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-v2.2-interface-only/src/IO.Swagger/web.config b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/web.config new file mode 100644 index 00000000000..a3b9f6add9c --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/web.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/index.html b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/index.html new file mode 100644 index 00000000000..cde1f2f90b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/swagger-original.json b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/swagger-original.json new file mode 100644 index 00000000000..55fa5c40e20 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/swagger-original.json @@ -0,0 +1,901 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "version" : "1.0.0", + "title" : "Swagger Petstore", + "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" + } + }, + "host" : "petstore.swagger.io", + "basePath" : "/v2", + "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" + } + } ], + "schemes" : [ "http" ], + "paths" : { + "/pet" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "description" : "", + "operationId" : "addPet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "description" : "", + "operationId" : "updatePet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "type" : "array", + "items" : { + "type" : "string" + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "deprecated" : true + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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", + "description" : "", + "operationId" : "updatePetWithForm", + "consumes" : [ "application/x-www-form-urlencoded" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "name", + "in" : "formData", + "description" : "Updated name of the pet", + "required" : false, + "type" : "string" + }, { + "name" : "status", + "in" : "formData", + "description" : "Updated status of the pet", + "required" : false, + "type" : "string" + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "description" : "", + "operationId" : "deletePet", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "type" : "string" + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "400" : { + "description" : "Invalid pet value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "description" : "", + "operationId" : "uploadFile", + "consumes" : [ "multipart/form-data" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "additionalMetadata", + "in" : "formData", + "description" : "Additional data to pass to server", + "required" : false, + "type" : "string" + }, { + "name" : "file", + "in" : "formData", + "description" : "file to upload", + "required" : false, + "type" : "file" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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", + "produces" : [ "application/json" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ] + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "description" : "", + "operationId" : "placeOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "order placed for purchasing the pet", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Order" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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 <= 5 or > 10. Other values will generated exceptions", + "operationId" : "getOrderById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "integer", + "maximum" : 5, + "minimum" : 1, + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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 value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId" : "deleteOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Created user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithArrayInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithListInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "description" : "", + "operationId" : "loginUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "type" : "string" + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "headers" : { + "X-Rate-Limit" : { + "type" : "integer", + "format" : "int32", + "description" : "calls per hour allowed by the user" + }, + "X-Expires-After" : { + "type" : "string", + "format" : "date-time", + "description" : "date in UTC when toekn expires" + } + }, + "schema" : { + "type" : "string" + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + } + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "description" : "", + "operationId" : "logoutUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "description" : "", + "operationId" : "getUserByName", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing.", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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.", + "operationId" : "updateUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be deleted", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "body", + "description" : "Updated user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + } + } + }, + "securityDefinitions" : { + "petstore_auth" : { + "type" : "oauth2", + "authorizationUrl" : "http://petstore.swagger.io/api/oauth/dialog", + "flow" : "implicit", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + }, + "definitions" : { + "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 + } + }, + "title" : "Pet Order", + "xml" : { + "name" : "Order" + }, + "description" : "An order for a pets from the pet store", + "example" : { + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet category", + "xml" : { + "name" : "Category" + }, + "description" : "A category for a pet", + "example" : { + "name" : "name", + "id" : 6 + } + }, + "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", + "format" : "int32", + "description" : "User Status" + } + }, + "title" : "a User", + "xml" : { + "name" : "User" + }, + "description" : "A User who is purchasing from the pet store", + "example" : { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet Tag", + "xml" : { + "name" : "Tag" + }, + "description" : "A tag for a pet", + "example" : { + "name" : "name", + "id" : 1 + } + }, + "Pet" : { + "type" : "object", + "required" : [ "name", "photoUrls" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/definitions/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" : "#/definitions/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "title" : "a Pet", + "xml" : { + "name" : "Pet" + }, + "description" : "A pet for sale in the pet store", + "example" : { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "title" : "An uploaded response", + "description" : "Describes the result of uploading an image resource", + "example" : { + "code" : 0, + "type" : "type", + "message" : "message" + } + }, + "Amount" : { + "type" : "object", + "required" : [ "currency", "value" ], + "properties" : { + "value" : { + "type" : "number", + "format" : "double", + "description" : "some description\n", + "minimum" : 0.01, + "maximum" : 1000000000000000 + }, + "currency" : { + "$ref" : "#/definitions/Currency" + } + }, + "description" : "some description\n" + }, + "Currency" : { + "type" : "string", + "pattern" : "^[A-Z]{3,3}$", + "description" : "some description\n" + } + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/web.config b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/web.config new file mode 100644 index 00000000000..e70a7778d60 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2-interface-only/src/IO.Swagger/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2/.swagger-codegen-ignore b/samples/server/petstore/aspnetcore-v2.2/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/.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-v2.2/.swagger-codegen/VERSION b/samples/server/petstore/aspnetcore-v2.2/.swagger-codegen/VERSION new file mode 100644 index 00000000000..91fb2f83cd4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.4.14-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-v2.2/IO.Swagger.sln b/samples/server/petstore/aspnetcore-v2.2/IO.Swagger.sln new file mode 100644 index 00000000000..045f3a11a74 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/server/petstore/aspnetcore-v2.2/NuGet.Config b/samples/server/petstore/aspnetcore-v2.2/NuGet.Config new file mode 100644 index 00000000000..01f3d1f203f --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2/README.md b/samples/server/petstore/aspnetcore-v2.2/README.md new file mode 100644 index 00000000000..730f1daffcd --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/README.md @@ -0,0 +1,25 @@ +# IO.Swagger - ASP.NET Core 2.2 Server + +This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + +## 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-v2.2/build.bat b/samples/server/petstore/aspnetcore-v2.2/build.bat new file mode 100644 index 00000000000..2e041233a06 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/build.sh b/samples/server/petstore/aspnetcore-v2.2/build.sh new file mode 100644 index 00000000000..ce6063a2f49 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/.gitignore b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/.gitignore new file mode 100644 index 00000000000..cd9b840e549 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Attributes/ValidateModelStateAttribute.cs new file mode 100644 index 00000000000..07cfabe83cf --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Controllers/PetApi.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/PetApi.cs new file mode 100644 index 00000000000..8a4a9e71928 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/PetApi.cs @@ -0,0 +1,244 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 + { + /// + /// Add a new pet to the store + /// + + /// Pet object that needs to be added to the store + /// Invalid input + [HttpPost] + [Route("/v2/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 pet value + [HttpDelete] + [Route("/v2/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); + + + 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("/v2/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 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + 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 + /// + /// Multiple 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("/v2/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 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + 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("/v2/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 123456789\n doggie\n \n aeiou\n \n \n \n aeiou\n"; + 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("/v2/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(); + } + + /// + /// Updates a pet in the store with form data + /// + + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + /// Invalid input + [HttpPost] + [Route("/v2/pet/{petId}")] + [ValidateModelState] + [SwaggerOperation("UpdatePetWithForm")] + public virtual IActionResult UpdatePetWithForm([FromRoute][Required]long? petId, [FromForm]string name, [FromForm]string status) + { + //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 + /// Additional data to pass to server + /// file to upload + /// successful operation + [HttpPost] + [Route("/v2/pet/{petId}/uploadImage")] + [ValidateModelState] + [SwaggerOperation("UploadFile")] + [SwaggerResponse(statusCode: 200, type: typeof(ApiResponse), description: "successful operation")] + public virtual IActionResult UploadFile([FromRoute][Required]long? petId, [FromForm]string additionalMetadata, [FromForm]System.IO.Stream _file) + { + //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-v2.2/src/IO.Swagger/Controllers/StoreApi.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/StoreApi.cs new file mode 100644 index 00000000000..306edc31d52 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/StoreApi.cs @@ -0,0 +1,146 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 + { + /// + /// Delete purchase order by ID + /// + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// ID of the order that needs to be deleted + /// Invalid ID supplied + /// Order not found + [HttpDelete] + [Route("/v2/store/order/{orderId}")] + [ValidateModelState] + [SwaggerOperation("DeleteOrder")] + public virtual IActionResult DeleteOrder([FromRoute][Required]string 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("/v2/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 <= 5 or > 10. Other values will generated exceptions + /// ID of pet that needs to be fetched + /// successful operation + /// Invalid ID supplied + /// Order not found + [HttpGet] + [Route("/v2/store/order/{orderId}")] + [ValidateModelState] + [SwaggerOperation("GetOrderById")] + [SwaggerResponse(statusCode: 200, type: typeof(Order), description: "successful operation")] + public virtual IActionResult GetOrderById([FromRoute][Required][Range(1, 5)]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 123456789\n 123456789\n 123\n 2000-01-23T04:56:07.000Z\n aeiou\n true\n"; + 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("/v2/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 123456789\n 123456789\n 123\n 2000-01-23T04:56:07.000Z\n aeiou\n true\n"; + 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-v2.2/src/IO.Swagger/Controllers/UserApi.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/UserApi.cs new file mode 100644 index 00000000000..29e97a7b35e --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Controllers/UserApi.cs @@ -0,0 +1,220 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 + { + /// + /// Create user + /// + /// This can only be done by the logged in user. + /// Created user object + /// successful operation + [HttpPost] + [Route("/v2/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("/v2/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("/v2/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("/v2/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("/v2/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 123456789\n aeiou\n aeiou\n aeiou\n aeiou\n aeiou\n aeiou\n 123\n"; + 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("/v2/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 = "aeiou"; + 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("/v2/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. + /// name that need to be deleted + /// Updated user object + /// Invalid user supplied + /// User not found + [HttpPut] + [Route("/v2/user/{username}")] + [ValidateModelState] + [SwaggerOperation("UpdateUser")] + public virtual IActionResult UpdateUser([FromRoute][Required]string username, [FromBody]User 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); + + + throw new NotImplementedException(); + } + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Dockerfile b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Dockerfile new file mode 100644 index 00000000000..967c8195c2b --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Filters/BasePathFilter.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Filters/BasePathFilter.cs new file mode 100644 index 00000000000..f3c528eada2 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Filters/GeneratePathParamsValidationFilter.cs new file mode 100644 index 00000000000..a0e2cb6871d --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/IO.Swagger.csproj new file mode 100644 index 00000000000..616076b6078 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Models/Amount.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Amount.cs new file mode 100644 index 00000000000..63839c2f8a1 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Amount.cs @@ -0,0 +1,137 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// some description + /// + [DataContract] + public partial class Amount : IEquatable + { + /// + /// some description + /// + /// some description + [Required] + [DataMember(Name="value")] + public double? Value { get; set; } + + /// + /// Gets or Sets Currency + /// + [Required] + [DataMember(Name="currency")] + public Currency Currency { 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 Amount {\n"); + sb.Append(" Value: ").Append(Value).Append("\n"); + sb.Append(" Currency: ").Append(Currency).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((Amount)obj); + } + + /// + /// Returns true if Amount instances are equal + /// + /// Instance of Amount to be compared + /// Boolean + public bool Equals(Amount other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return + ( + Value == other.Value || + Value != null && + Value.Equals(other.Value) + ) && + ( + Currency == other.Currency || + Currency != null && + Currency.Equals(other.Currency) + ); + } + + /// + /// 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 (Value != null) + hashCode = hashCode * 59 + Value.GetHashCode(); + if (Currency != null) + hashCode = hashCode * 59 + Currency.GetHashCode(); + return hashCode; + } + } + + #region Operators + #pragma warning disable 1591 + + public static bool operator ==(Amount left, Amount right) + { + return Equals(left, right); + } + + public static bool operator !=(Amount left, Amount right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/ApiResponse.cs new file mode 100644 index 00000000000..eb444479ec4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/ApiResponse.cs @@ -0,0 +1,148 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// Describes the result of uploading an image resource + /// + [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-v2.2/src/IO.Swagger/Models/Category.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Category.cs new file mode 100644 index 00000000000..0f9df0830c4 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Category.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A category for a pet + /// + [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-v2.2/src/IO.Swagger/Models/Currency.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Currency.cs new file mode 100644 index 00000000000..a5a499265cb --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Currency.cs @@ -0,0 +1,106 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// some description + /// + [DataContract] + public partial class Currency : IEquatable + { + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class Currency {\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((Currency)obj); + } + + /// + /// Returns true if Currency instances are equal + /// + /// Instance of Currency to be compared + /// Boolean + public bool Equals(Currency 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 ==(Currency left, Currency right) + { + return Equals(left, right); + } + + public static bool operator !=(Currency left, Currency right) + { + return !Equals(left, right); + } + + #pragma warning restore 1591 + #endregion Operators + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Order.cs new file mode 100644 index 00000000000..1e617fdf089 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Order.cs @@ -0,0 +1,218 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// An order for a pets from the pet store + /// + [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 = 1, + + /// + /// Enum ApprovedEnum for approved + /// + [EnumMember(Value = "approved")] + ApprovedEnum = 2, + + /// + /// Enum DeliveredEnum for delivered + /// + [EnumMember(Value = "delivered")] + DeliveredEnum = 3 + } + + /// + /// 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-v2.2/src/IO.Swagger/Models/Pet.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Pet.cs new file mode 100644 index 00000000000..fc9884836f0 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Pet.cs @@ -0,0 +1,220 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A pet for sale in the pet store + /// + [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 = 1, + + /// + /// Enum PendingEnum for pending + /// + [EnumMember(Value = "pending")] + PendingEnum = 2, + + /// + /// Enum SoldEnum for sold + /// + [EnumMember(Value = "sold")] + SoldEnum = 3 + } + + /// + /// 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-v2.2/src/IO.Swagger/Models/Tag.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Tag.cs new file mode 100644 index 00000000000..d0cd5b744be --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/Tag.cs @@ -0,0 +1,134 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A tag for a pet + /// + [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-v2.2/src/IO.Swagger/Models/User.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/User.cs new file mode 100644 index 00000000000..4c9df2fd429 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Models/User.cs @@ -0,0 +1,219 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 +{ + /// + /// A User who is purchasing from the pet store + /// + [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-v2.2/src/IO.Swagger/Program.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Program.cs new file mode 100644 index 00000000000..ae409c1ecb8 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Properties/launchSettings.json b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Properties/launchSettings.json new file mode 100644 index 00000000000..21acfed207b --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Security/ApiKeyAuthenticationHandler.cs new file mode 100644 index 00000000000..57b5fd5dfd9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/Startup.cs b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Startup.cs new file mode 100644 index 00000000000..73dc4b97234 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/Startup.cs @@ -0,0 +1,132 @@ +/* + * Swagger Petstore + * + * This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * 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 + .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"); + // Sets the basePath property in the Swagger document generated + c.DocumentFilter("/v2"); + + // 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-v2.2/src/IO.Swagger/appsettings.json b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/appsettings.json new file mode 100644 index 00000000000..c6af7d9b069 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/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-v2.2/src/IO.Swagger/web.config b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/web.config new file mode 100644 index 00000000000..a3b9f6add9c --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/web.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/index.html b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/index.html new file mode 100644 index 00000000000..cde1f2f90b9 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/swagger-original.json b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/swagger-original.json new file mode 100644 index 00000000000..55fa5c40e20 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/swagger-original.json @@ -0,0 +1,901 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "This is a sample server 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/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "version" : "1.0.0", + "title" : "Swagger Petstore", + "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" + } + }, + "host" : "petstore.swagger.io", + "basePath" : "/v2", + "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" + } + } ], + "schemes" : [ "http" ], + "paths" : { + "/pet" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "description" : "", + "operationId" : "addPet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "description" : "", + "operationId" : "updatePet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "type" : "array", + "items" : { + "type" : "string" + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "deprecated" : true + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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", + "description" : "", + "operationId" : "updatePetWithForm", + "consumes" : [ "application/x-www-form-urlencoded" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "name", + "in" : "formData", + "description" : "Updated name of the pet", + "required" : false, + "type" : "string" + }, { + "name" : "status", + "in" : "formData", + "description" : "Updated status of the pet", + "required" : false, + "type" : "string" + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "description" : "", + "operationId" : "deletePet", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "type" : "string" + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "400" : { + "description" : "Invalid pet value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ] + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "description" : "", + "operationId" : "uploadFile", + "consumes" : [ "multipart/form-data" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "additionalMetadata", + "in" : "formData", + "description" : "Additional data to pass to server", + "required" : false, + "type" : "string" + }, { + "name" : "file", + "in" : "formData", + "description" : "file to upload", + "required" : false, + "type" : "file" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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", + "produces" : [ "application/json" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ] + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "description" : "", + "operationId" : "placeOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "order placed for purchasing the pet", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Order" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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 <= 5 or > 10. Other values will generated exceptions", + "operationId" : "getOrderById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "integer", + "maximum" : 5, + "minimum" : 1, + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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 value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId" : "deleteOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Created user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithArrayInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithListInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "description" : "", + "operationId" : "loginUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "type" : "string" + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "headers" : { + "X-Rate-Limit" : { + "type" : "integer", + "format" : "int32", + "description" : "calls per hour allowed by the user" + }, + "X-Expires-After" : { + "type" : "string", + "format" : "date-time", + "description" : "date in UTC when toekn expires" + } + }, + "schema" : { + "type" : "string" + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + } + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "description" : "", + "operationId" : "logoutUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ ], + "responses" : { + "default" : { + "description" : "successful operation" + } + } + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "description" : "", + "operationId" : "getUserByName", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing.", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/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.", + "operationId" : "updateUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be deleted", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "body", + "description" : "Updated user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "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", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + } + } + } + }, + "securityDefinitions" : { + "petstore_auth" : { + "type" : "oauth2", + "authorizationUrl" : "http://petstore.swagger.io/api/oauth/dialog", + "flow" : "implicit", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + }, + "definitions" : { + "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 + } + }, + "title" : "Pet Order", + "xml" : { + "name" : "Order" + }, + "description" : "An order for a pets from the pet store", + "example" : { + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet category", + "xml" : { + "name" : "Category" + }, + "description" : "A category for a pet", + "example" : { + "name" : "name", + "id" : 6 + } + }, + "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", + "format" : "int32", + "description" : "User Status" + } + }, + "title" : "a User", + "xml" : { + "name" : "User" + }, + "description" : "A User who is purchasing from the pet store", + "example" : { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet Tag", + "xml" : { + "name" : "Tag" + }, + "description" : "A tag for a pet", + "example" : { + "name" : "name", + "id" : 1 + } + }, + "Pet" : { + "type" : "object", + "required" : [ "name", "photoUrls" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/definitions/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" : "#/definitions/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "title" : "a Pet", + "xml" : { + "name" : "Pet" + }, + "description" : "A pet for sale in the pet store", + "example" : { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "title" : "An uploaded response", + "description" : "Describes the result of uploading an image resource", + "example" : { + "code" : 0, + "type" : "type", + "message" : "message" + } + }, + "Amount" : { + "type" : "object", + "required" : [ "currency", "value" ], + "properties" : { + "value" : { + "type" : "number", + "format" : "double", + "description" : "some description\n", + "minimum" : 0.01, + "maximum" : 1000000000000000 + }, + "currency" : { + "$ref" : "#/definitions/Currency" + } + }, + "description" : "some description\n" + }, + "Currency" : { + "type" : "string", + "pattern" : "^[A-Z]{3,3}$", + "description" : "some description\n" + } + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + } +} diff --git a/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/web.config b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/web.config new file mode 100644 index 00000000000..e70a7778d60 --- /dev/null +++ b/samples/server/petstore/aspnetcore-v2.2/src/IO.Swagger/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + +