From 30c2503f9f9a7cad8f3a4c6c2cba9fbf8a0d0e81 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 26 Jul 2016 14:10:48 +0800 Subject: [PATCH] [C#][NancyFX] Better "Add" for Dictionary and using {{packageName}} for NancyFX (#3449) * use square bucket for C# dictionary * use packageName for nancyfx generator, update info to debug for log * use packageName for nancyfx generator, update info to debug for log --- bin/nancyfx-petstore-server.sh | 31 +++ bin/windows/nancyfx-petstore-server.bat | 2 +- .../languages/NancyFXServerCodegen.java | 8 +- .../resources/csharp/Configuration.mustache | 12 +- .../main/resources/nancyfx/Project.mustache | 2 +- .../csharp/SwaggerClient/IO.Swagger.sln | 10 +- .../petstore/csharp/SwaggerClient/README.md | 14 +- .../src/IO.Swagger/Client/Configuration.cs | 12 +- .../src/IO.Swagger/IO.Swagger.csproj | 2 +- .../petstore/nancyfx/.swagger-codegen-ignore | 23 ++ .../server/petstore/nancyfx/IO.Swagger.sln | 10 +- samples/server/petstore/nancyfx/LICENSE | 201 ++++++++++++++++++ .../nancyfx/src/IO.Swagger/IO.Swagger.csproj | 8 +- .../nancyfx/src/IO.Swagger/IO.Swagger.nuspec | 2 +- .../src/IO.Swagger/Models/ApiResponse.cs | 185 ++++++++++++++++ .../nancyfx/src/IO.Swagger/Models/Order.cs | 1 + .../src/IO.Swagger/Modules/PetModule.cs | 65 +++--- .../src/IO.Swagger/Modules/StoreModule.cs | 14 +- .../src/IO.Swagger/Modules/UserModule.cs | 36 ++-- .../nancyfx/src/IO.Swagger/packages.config | 2 +- 20 files changed, 547 insertions(+), 93 deletions(-) create mode 100755 bin/nancyfx-petstore-server.sh create mode 100644 samples/server/petstore/nancyfx/.swagger-codegen-ignore create mode 100644 samples/server/petstore/nancyfx/LICENSE create mode 100644 samples/server/petstore/nancyfx/src/IO.Swagger/Models/ApiResponse.cs diff --git a/bin/nancyfx-petstore-server.sh b/bin/nancyfx-petstore-server.sh new file mode 100755 index 00000000000..20797fa0c1f --- /dev/null +++ b/bin/nancyfx-petstore-server.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +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 -t modules/swagger-codegen/src/main/resources/nancyfx -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l nancyfx -o samples/server/petstore/nancyfx" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/nancyfx-petstore-server.bat b/bin/windows/nancyfx-petstore-server.bat index fff39d8e86a..cfd16120caf 100644 --- a/bin/windows/nancyfx-petstore-server.bat +++ b/bin/windows/nancyfx-petstore-server.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties -set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l nancyfx -o samples\server\petstore\nancyfx\ +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l nancyfx -o samples\server\petstore\nancyfx\ java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java index 3eec3751364..571bcdef920 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java @@ -222,7 +222,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen { } private void postProcessParentModels(final Map models) { - log.info("Processing parents: " + parentModels); + log.debug("Processing parents: " + parentModels); for (final String parent : parentModels) { final CodegenModel parentModel = modelByName(parent, models); parentModel.hasChildren = true; @@ -301,7 +301,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen { } else { result = enumName; } - log.info(String.format("toEnumVarName('%s', %s) = '%s'", name, datatype, enumName)); + log.debug(String.format("toEnumVarName('%s', %s) = '%s'", name, datatype, enumName)); return result; } @@ -313,7 +313,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen { } else { apiName = capitalize(name); } - log.info(String.format("toApiName('%s') = '%s'", name, apiName)); + log.debug(String.format("toApiName('%s') = '%s'", name, apiName)); return apiName; } @@ -334,7 +334,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen { } else { result = null; } - log.info(String.format("toModelImport('%s') = '%s'", name, result)); + log.debug(String.format("toModelImport('%s') = '%s'", name, result)); return result; } diff --git a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache index b8cd6c1b330..108b85e48f8 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache @@ -158,9 +158,7 @@ namespace {{packageName}}.Client /// public void AddDefaultHeader(string key, string value) { - if (_defaultHeaderMap.ContainsKey(key)) - _defaultHeaderMap.Remove(key); - _defaultHeaderMap.Add(key, value); + _defaultHeaderMap[key] = value; } /// @@ -171,9 +169,7 @@ namespace {{packageName}}.Client /// public void AddApiKey(string key, string value) { - if (ApiKey.ContainsKey(key)) - ApiKey.Remove(key); - ApiKey.Add(key, value); + ApiKey[key] = value; } /// @@ -183,9 +179,7 @@ namespace {{packageName}}.Client /// Api Key value. public void AddApiKeyPrefix(string key, string value) { - if (ApiKeyPrefix.ContainsKey(key)) - ApiKeyPrefix.Remove(key); - ApiKeyPrefix.Add(key, value); + ApiKeyPrefix[key] = value; } /// diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache index 5b63a52feb2..c4a06b60070 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache @@ -7,7 +7,7 @@ Library Properties {{packageName}}.{{packageContext}} - {{packageTitle}} + {{packageName}} {{^supportsUWP}} v4.5 {{/supportsUWP}} diff --git a/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln b/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln index 5275707330e..95d7c51d31d 100644 --- a/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln +++ b/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{1ABB7E18-6533-446C-9EEA-0E0839F5C12A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{B7B26355-6F11-47C6-AB34-6237A673E486}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}" EndProject @@ -12,10 +12,10 @@ Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -{1ABB7E18-6533-446C-9EEA-0E0839F5C12A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{1ABB7E18-6533-446C-9EEA-0E0839F5C12A}.Debug|Any CPU.Build.0 = Debug|Any CPU -{1ABB7E18-6533-446C-9EEA-0E0839F5C12A}.Release|Any CPU.ActiveCfg = Release|Any CPU -{1ABB7E18-6533-446C-9EEA-0E0839F5C12A}.Release|Any CPU.Build.0 = Release|Any CPU +{B7B26355-6F11-47C6-AB34-6237A673E486}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{B7B26355-6F11-47C6-AB34-6237A673E486}.Debug|Any CPU.Build.0 = Debug|Any CPU +{B7B26355-6F11-47C6-AB34-6237A673E486}.Release|Any CPU.ActiveCfg = Release|Any CPU +{B7B26355-6F11-47C6-AB34-6237A673E486}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/samples/client/petstore/csharp/SwaggerClient/README.md b/samples/client/petstore/csharp/SwaggerClient/README.md index 727969d5347..6fb2bcf28f3 100644 --- a/samples/client/petstore/csharp/SwaggerClient/README.md +++ b/samples/client/petstore/csharp/SwaggerClient/README.md @@ -6,7 +6,7 @@ This C# SDK is automatically generated by the [Swagger Codegen](https://github.c - API version: 1.0.0 - SDK version: 1.0.0 -- Build date: 2016-07-24T11:20:06.818-04:00 +- Build date: 2016-07-26T00:22:48.731+08:00 - Build package: class io.swagger.codegen.languages.CSharpClientCodegen ## Frameworks supported @@ -137,6 +137,12 @@ Class | Method | HTTP request | Description ## Documentation for Authorization +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ### petstore_auth - **Type**: OAuth @@ -146,9 +152,3 @@ Class | Method | HTTP request | Description - write:pets: modify pets in your account - read:pets: read your pets -### api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs index fcefd40a36c..12f87d6e6fa 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Client/Configuration.cs @@ -179,9 +179,7 @@ namespace IO.Swagger.Client /// public void AddDefaultHeader(string key, string value) { - if (_defaultHeaderMap.ContainsKey(key)) - _defaultHeaderMap.Remove(key); - _defaultHeaderMap.Add(key, value); + _defaultHeaderMap[key] = value; } /// @@ -192,9 +190,7 @@ namespace IO.Swagger.Client /// public void AddApiKey(string key, string value) { - if (ApiKey.ContainsKey(key)) - ApiKey.Remove(key); - ApiKey.Add(key, value); + ApiKey[key] = value; } /// @@ -204,9 +200,7 @@ namespace IO.Swagger.Client /// Api Key value. public void AddApiKeyPrefix(string key, string value) { - if (ApiKeyPrefix.ContainsKey(key)) - ApiKeyPrefix.Remove(key); - ApiKeyPrefix.Add(key, value); + ApiKeyPrefix[key] = value; } /// diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj index f818f874154..e84766657af 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj @@ -24,7 +24,7 @@ limitations under the License. Debug AnyCPU - {1ABB7E18-6533-446C-9EEA-0E0839F5C12A} + {B7B26355-6F11-47C6-AB34-6237A673E486} Library Properties IO.Swagger diff --git a/samples/server/petstore/nancyfx/.swagger-codegen-ignore b/samples/server/petstore/nancyfx/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/server/petstore/nancyfx/.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/nancyfx/IO.Swagger.sln b/samples/server/petstore/nancyfx/IO.Swagger.sln index 896f0bd86f6..87b0eca9e40 100644 --- a/samples/server/petstore/nancyfx/IO.Swagger.sln +++ b/samples/server/petstore/nancyfx/IO.Swagger.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{1DE2DD8D-1AFB-4BC2-9FB5-04DE7DCA1353}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{4E6FF76E-03ED-499F-B05C-4315904C488E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -10,10 +10,10 @@ Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -{1DE2DD8D-1AFB-4BC2-9FB5-04DE7DCA1353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{1DE2DD8D-1AFB-4BC2-9FB5-04DE7DCA1353}.Debug|Any CPU.Build.0 = Debug|Any CPU -{1DE2DD8D-1AFB-4BC2-9FB5-04DE7DCA1353}.Release|Any CPU.ActiveCfg = Release|Any CPU -{1DE2DD8D-1AFB-4BC2-9FB5-04DE7DCA1353}.Release|Any CPU.Build.0 = Release|Any CPU +{4E6FF76E-03ED-499F-B05C-4315904C488E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{4E6FF76E-03ED-499F-B05C-4315904C488E}.Debug|Any CPU.Build.0 = Debug|Any CPU +{4E6FF76E-03ED-499F-B05C-4315904C488E}.Release|Any CPU.ActiveCfg = Release|Any CPU +{4E6FF76E-03ED-499F-B05C-4315904C488E}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/samples/server/petstore/nancyfx/LICENSE b/samples/server/petstore/nancyfx/LICENSE new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/samples/server/petstore/nancyfx/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj index 46fb435d419..694e6c1ad4d 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj @@ -3,11 +3,11 @@ Debug AnyCPU - {1DE2DD8D-1AFB-4BC2-9FB5-04DE7DCA1353} + {4E6FF76E-03ED-499F-B05C-4315904C488E} Library Properties IO.Swagger.v2 - + IO.Swagger v4.5 512 @@ -39,8 +39,8 @@ ..\..\packages\NodaTime.1.3.1\lib\net35-Client\NodaTime.dll True - - ..\..\packages\Sharpility.1.2.1\lib\net45\Sharpility.dll + + ..\..\packages\Sharpility.1.2.2\lib\net45\Sharpility.dll True diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.nuspec b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.nuspec index f6ab1af8e9b..889fe96ab03 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.nuspec +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.nuspec @@ -8,7 +8,7 @@ swagger-codegen false NancyFx IO.Swagger API - http://helloreverb.com/terms/ + http://swagger.io/terms/ http://www.apache.org/licenses/LICENSE-2.0.html \ No newline at end of file diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/Models/ApiResponse.cs b/samples/server/petstore/nancyfx/src/IO.Swagger/Models/ApiResponse.cs new file mode 100644 index 00000000000..8eb40938412 --- /dev/null +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/Models/ApiResponse.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Sharpility.Extensions; +using NodaTime; + +namespace IO.Swagger.v2.Models +{ + /// + /// ApiResponse + /// + public sealed class ApiResponse: IEquatable + { + /// + /// Code + /// + public int? Code { get; private set; } + + /// + /// Type + /// + public string Type { get; private set; } + + /// + /// Message + /// + public string Message { get; private set; } + + + /// + /// Empty constructor required by some serializers. + /// Use ApiResponse.Builder() for instance creation instead. + /// + [Obsolete] + public ApiResponse() + { + } + + private ApiResponse(int? Code, string Type, string Message) + { + + this.Code = Code; + + this.Type = Type; + + this.Message = Message; + + } + + /// + /// Returns builder of ApiResponse. + /// + /// ApiResponseBuilder + public static ApiResponseBuilder Builder() + { + return new ApiResponseBuilder(); + } + + /// + /// Returns ApiResponseBuilder with properties set. + /// Use it to change properties. + /// + /// ApiResponseBuilder + public ApiResponseBuilder With() + { + return Builder() + .Code(Code) + .Type(Type) + .Message(Message); + } + + public override string ToString() + { + return this.PropertiesToString(); + } + + public override bool Equals(object obj) + { + return this.EqualsByProperties(obj); + } + + public bool Equals(ApiResponse other) + { + return Equals((object) other); + } + + public override int GetHashCode() + { + return this.PropertiesHash(); + } + + /// + /// Implementation of == operator for (ApiResponse. + /// + /// Compared (ApiResponse + /// Compared (ApiResponse + /// true if compared items are equals, false otherwise + public static bool operator == (ApiResponse left, ApiResponse right) + { + return Equals(left, right); + } + + /// + /// Implementation of != operator for (ApiResponse. + /// + /// Compared (ApiResponse + /// Compared (ApiResponse + /// true if compared items are not equals, false otherwise + public static bool operator != (ApiResponse left, ApiResponse right) + { + return !Equals(left, right); + } + + /// + /// Builder of ApiResponse. + /// + public sealed class ApiResponseBuilder + { + private int? _Code; + private string _Type; + private string _Message; + + internal ApiResponseBuilder() + { + SetupDefaults(); + } + + private void SetupDefaults() + { + } + + /// + /// Sets value for ApiResponse.Code property. + /// + /// Code + public ApiResponseBuilder Code(int? value) + { + _Code = value; + return this; + } + + /// + /// Sets value for ApiResponse.Type property. + /// + /// Type + public ApiResponseBuilder Type(string value) + { + _Type = value; + return this; + } + + /// + /// Sets value for ApiResponse.Message property. + /// + /// Message + public ApiResponseBuilder Message(string value) + { + _Message = value; + return this; + } + + + /// + /// Builds instance of ApiResponse. + /// + /// ApiResponse + public ApiResponse Build() + { + Validate(); + return new ApiResponse( + Code: _Code, + Type: _Type, + Message: _Message + ); + } + + private void Validate() + { + } + } + + + } +} diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/Models/Order.cs b/samples/server/petstore/nancyfx/src/IO.Swagger/Models/Order.cs index 22245ee5bfe..7404b483830 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/Models/Order.cs +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/Models/Order.cs @@ -155,6 +155,7 @@ namespace IO.Swagger.v2.Models private void SetupDefaults() { + _Complete = false; } /// diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs index f3ab9ee2892..3f47101563f 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/PetModule.cs @@ -9,6 +9,10 @@ using NodaTime; namespace IO.Swagger.v2.Modules { + /// + /// Status values that need to be considered for filter + /// + public enum FindPetsByStatusList<StatusEnum> { }; /// /// Module processing requests of Pet domain. @@ -24,8 +28,10 @@ namespace IO.Swagger.v2.Modules Post["/pet"] = parameters => { var body = this.Bind(); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'AddPet'"); + service.AddPet(Context, body); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Delete["/pet/{petId}"] = parameters => @@ -35,18 +41,22 @@ namespace IO.Swagger.v2.Modules Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'DeletePet'"); service.DeletePet(Context, petId, apiKey); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Get["/pet/findByStatus"] = parameters => { - var status = Parameters.ValueOf>(parameters, Context.Request, "status", ParameterType.Query); + var status = Parameters.ValueOf(parameters, Context.Request, "status", ParameterType.Query); + Preconditions.IsNotNull(status, "Required parameter: 'status' is missing at 'FindPetsByStatus'"); + return service.FindPetsByStatus(Context, status); }; Get["/pet/findByTags"] = parameters => { var tags = Parameters.ValueOf>(parameters, Context.Request, "tags", ParameterType.Query); + Preconditions.IsNotNull(tags, "Required parameter: 'tags' is missing at 'FindPetsByTags'"); + return service.FindPetsByTags(Context, tags); }; @@ -61,19 +71,21 @@ namespace IO.Swagger.v2.Modules Put["/pet"] = parameters => { var body = this.Bind(); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'UpdatePet'"); + service.UpdatePet(Context, body); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Post["/pet/{petId}"] = parameters => { - var petId = Parameters.ValueOf(parameters, Context.Request, "petId", ParameterType.Path); + var petId = Parameters.ValueOf(parameters, Context.Request, "petId", ParameterType.Path); var name = Parameters.ValueOf(parameters, Context.Request, "name", ParameterType.Undefined); var status = Parameters.ValueOf(parameters, Context.Request, "status", ParameterType.Undefined); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'UpdatePetWithForm'"); service.UpdatePetWithForm(Context, petId, name, status); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Post["/pet/{petId}/uploadImage"] = parameters => @@ -83,8 +95,7 @@ namespace IO.Swagger.v2.Modules var file = Parameters.ValueOf(parameters, Context.Request, "file", ParameterType.Undefined); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'UploadFile'"); - service.UploadFile(Context, petId, additionalMetadata, file); - return new Response { ContentType = "application/json"}; + return service.UploadFile(Context, petId, additionalMetadata, file); }; } } @@ -98,7 +109,7 @@ namespace IO.Swagger.v2.Modules /// /// /// Context of request - /// Pet object that needs to be added to the store (optional) + /// Pet object that needs to be added to the store /// void AddPet(NancyContext context, Pet body); @@ -112,26 +123,26 @@ namespace IO.Swagger.v2.Modules void DeletePet(NancyContext context, long? petId, string apiKey); /// - /// Multiple status values can be provided with comma seperated strings + /// Multiple status values can be provided with comma separated strings /// /// Context of request - /// Status values that need to be considered for filter (optional, default to available) + /// Status values that need to be considered for filter /// List<Pet> - List FindPetsByStatus(NancyContext context, List status); + List FindPetsByStatus(NancyContext context, FindPetsByStatusList<StatusEnum>? status); /// - /// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. /// /// Context of request - /// Tags to filter by (optional) + /// Tags to filter by /// List<Pet> List FindPetsByTags(NancyContext context, List tags); /// - /// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + /// Returns a single pet /// /// Context of request - /// ID of pet that needs to be fetched + /// ID of pet to return /// Pet Pet GetPetById(NancyContext context, long? petId); @@ -139,7 +150,7 @@ namespace IO.Swagger.v2.Modules /// /// /// Context of request - /// Pet object that needs to be added to the store (optional) + /// Pet object that needs to be added to the store /// void UpdatePet(NancyContext context, Pet body); @@ -151,7 +162,7 @@ namespace IO.Swagger.v2.Modules /// Updated name of the pet (optional) /// Updated status of the pet (optional) /// - void UpdatePetWithForm(NancyContext context, string petId, string name, string status); + void UpdatePetWithForm(NancyContext context, long? petId, string name, string status); /// /// @@ -160,8 +171,8 @@ namespace IO.Swagger.v2.Modules /// ID of pet to update /// Additional data to pass to server (optional) /// file to upload (optional) - /// - void UploadFile(NancyContext context, long? petId, string additionalMetadata, System.IO.Stream file); + /// ApiResponse + ApiResponse UploadFile(NancyContext context, long? petId, string additionalMetadata, System.IO.Stream file); } /// @@ -179,7 +190,7 @@ namespace IO.Swagger.v2.Modules DeletePet(petId, apiKey); } - public virtual List FindPetsByStatus(NancyContext context, List status) + public virtual List FindPetsByStatus(NancyContext context, FindPetsByStatusList<StatusEnum>? status) { return FindPetsByStatus(status); } @@ -199,21 +210,21 @@ namespace IO.Swagger.v2.Modules UpdatePet(body); } - public virtual void UpdatePetWithForm(NancyContext context, string petId, string name, string status) + public virtual void UpdatePetWithForm(NancyContext context, long? petId, string name, string status) { UpdatePetWithForm(petId, name, status); } - public virtual void UploadFile(NancyContext context, long? petId, string additionalMetadata, System.IO.Stream file) + public virtual ApiResponse UploadFile(NancyContext context, long? petId, string additionalMetadata, System.IO.Stream file) { - UploadFile(petId, additionalMetadata, file); + return UploadFile(petId, additionalMetadata, file); } protected abstract void AddPet(Pet body); protected abstract void DeletePet(long? petId, string apiKey); - protected abstract List FindPetsByStatus(List status); + protected abstract List FindPetsByStatus(FindPetsByStatusList<StatusEnum>? status); protected abstract List FindPetsByTags(List tags); @@ -221,9 +232,9 @@ namespace IO.Swagger.v2.Modules protected abstract void UpdatePet(Pet body); - protected abstract void UpdatePetWithForm(string petId, string name, string status); + protected abstract void UpdatePetWithForm(long? petId, string name, string status); - protected abstract void UploadFile(long? petId, string additionalMetadata, System.IO.Stream file); + protected abstract ApiResponse UploadFile(long? petId, string additionalMetadata, System.IO.Stream file); } } diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/StoreModule.cs b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/StoreModule.cs index 06f397db408..e5eed7a2485 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/StoreModule.cs +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/StoreModule.cs @@ -27,7 +27,7 @@ namespace IO.Swagger.v2.Modules Preconditions.IsNotNull(orderId, "Required parameter: 'orderId' is missing at 'DeleteOrder'"); service.DeleteOrder(Context, orderId); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Get["/store/inventory"] = parameters => @@ -38,7 +38,7 @@ namespace IO.Swagger.v2.Modules Get["/store/order/{orderId}"] = parameters => { - var orderId = Parameters.ValueOf(parameters, Context.Request, "orderId", ParameterType.Path); + var orderId = Parameters.ValueOf(parameters, Context.Request, "orderId", ParameterType.Path); Preconditions.IsNotNull(orderId, "Required parameter: 'orderId' is missing at 'GetOrderById'"); return service.GetOrderById(Context, orderId); @@ -47,6 +47,8 @@ namespace IO.Swagger.v2.Modules Post["/store/order"] = parameters => { var body = this.Bind(); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'PlaceOrder'"); + return service.PlaceOrder(Context, body); }; } @@ -78,13 +80,13 @@ namespace IO.Swagger.v2.Modules /// Context of request /// ID of pet that needs to be fetched /// Order - Order GetOrderById(NancyContext context, string orderId); + Order GetOrderById(NancyContext context, long? orderId); /// /// /// /// Context of request - /// order placed for purchasing the pet (optional) + /// order placed for purchasing the pet /// Order Order PlaceOrder(NancyContext context, Order body); } @@ -104,7 +106,7 @@ namespace IO.Swagger.v2.Modules return GetInventory(); } - public virtual Order GetOrderById(NancyContext context, string orderId) + public virtual Order GetOrderById(NancyContext context, long? orderId) { return GetOrderById(orderId); } @@ -118,7 +120,7 @@ namespace IO.Swagger.v2.Modules protected abstract Dictionary GetInventory(); - protected abstract Order GetOrderById(string orderId); + protected abstract Order GetOrderById(long? orderId); protected abstract Order PlaceOrder(Order body); } diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/UserModule.cs b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/UserModule.cs index 8350479ef12..978013f17bb 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/UserModule.cs +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/Modules/UserModule.cs @@ -24,22 +24,28 @@ namespace IO.Swagger.v2.Modules Post["/user"] = parameters => { var body = this.Bind(); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'CreateUser'"); + service.CreateUser(Context, body); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Post["/user/createWithArray"] = parameters => { var body = this.Bind>(); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'CreateUsersWithArrayInput'"); + service.CreateUsersWithArrayInput(Context, body); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Post["/user/createWithList"] = parameters => { var body = this.Bind>(); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'CreateUsersWithListInput'"); + service.CreateUsersWithListInput(Context, body); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Delete["/user/{username}"] = parameters => @@ -48,7 +54,7 @@ namespace IO.Swagger.v2.Modules Preconditions.IsNotNull(username, "Required parameter: 'username' is missing at 'DeleteUser'"); service.DeleteUser(Context, username); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Get["/user/{username}"] = parameters => @@ -63,6 +69,10 @@ namespace IO.Swagger.v2.Modules { var username = Parameters.ValueOf(parameters, Context.Request, "username", ParameterType.Query); var password = Parameters.ValueOf(parameters, Context.Request, "password", ParameterType.Query); + Preconditions.IsNotNull(username, "Required parameter: 'username' is missing at 'LoginUser'"); + + Preconditions.IsNotNull(password, "Required parameter: 'password' is missing at 'LoginUser'"); + return service.LoginUser(Context, username, password); }; @@ -70,7 +80,7 @@ namespace IO.Swagger.v2.Modules { service.LogoutUser(Context); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; Put["/user/{username}"] = parameters => @@ -79,8 +89,10 @@ namespace IO.Swagger.v2.Modules var body = this.Bind(); Preconditions.IsNotNull(username, "Required parameter: 'username' is missing at 'UpdateUser'"); + Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'UpdateUser'"); + service.UpdateUser(Context, username, body); - return new Response { ContentType = "application/json"}; + return new Response { ContentType = "application/xml"}; }; } } @@ -94,7 +106,7 @@ namespace IO.Swagger.v2.Modules /// This can only be done by the logged in user. /// /// Context of request - /// Created user object (optional) + /// Created user object /// void CreateUser(NancyContext context, User body); @@ -102,7 +114,7 @@ namespace IO.Swagger.v2.Modules /// /// /// Context of request - /// List of user object (optional) + /// List of user object /// void CreateUsersWithArrayInput(NancyContext context, List body); @@ -110,7 +122,7 @@ namespace IO.Swagger.v2.Modules /// /// /// Context of request - /// List of user object (optional) + /// List of user object /// void CreateUsersWithListInput(NancyContext context, List body); @@ -134,8 +146,8 @@ namespace IO.Swagger.v2.Modules /// /// /// Context of request - /// The user name for login (optional) - /// The password for login in clear text (optional) + /// The user name for login + /// The password for login in clear text /// string string LoginUser(NancyContext context, string username, string password); @@ -151,7 +163,7 @@ namespace IO.Swagger.v2.Modules /// /// Context of request /// name that need to be deleted - /// Updated user object (optional) + /// Updated user object /// void UpdateUser(NancyContext context, string username, User body); } diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/packages.config b/samples/server/petstore/nancyfx/src/IO.Swagger/packages.config index 6d8651cdcf4..2575d1b4d77 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/packages.config +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/packages.config @@ -2,6 +2,6 @@ - + \ No newline at end of file