From 0e1460fc228a37abaf081effc7bb52bf845af169 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 11 Feb 2017 22:47:07 +0800 Subject: [PATCH 001/146] show travis master status --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9a4b63a596..935603c9c5c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Swagger Code Generator -[![Build Status](https://img.shields.io/travis/swagger-api/swagger-codegen.svg?label=Petstore%20Integration%20Test)](https://travis-ci.org/swagger-api/swagger-codegen) +[![Build Status](https://img.shields.io/travis/swagger-api/swagger-codegen/master.svg?label=Petstore%20Integration%20Test)](https://travis-ci.org/swagger-api/swagger-codegen) [![Run Status](https://img.shields.io/shippable/5782588a3be4f4faa56c5bea.svg?label=Mustache%20Template%20Test)](https://app.shippable.com/projects/5782588a3be4f4faa56c5bea) [![Windows Test](https://ci.appveyor.com/api/projects/status/github/swagger-api/swagger-codegen?branch=master&svg=true&passingText=Windows%20Test%20-%20OK&failingText=Windows%20Test%20-%20Fails)](https://ci.appveyor.com/project/WilliamCheng/swagger-codegen-wh2wu) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project/badge.svg?style=plastic)](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project) From 1d52c62565c1d5bf0f6360882f37f8e9dbc7bdc2 Mon Sep 17 00:00:00 2001 From: Matthew Davis Date: Sat, 11 Feb 2017 06:50:12 -0800 Subject: [PATCH 002/146] Added Fotition as a company using swagger-codegen (#4773) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 935603c9c5c..40767c2b202 100644 --- a/README.md +++ b/README.md @@ -849,6 +849,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you - [Flat](https://flat.io) - [Finder](http://en.finder.pl/) - [FH Münster - University of Applied Sciences](http://www.fh-muenster.de) +- [Fotition](https://www.fotition.com/) - [Gear Zero Network](https://www.gearzero.ca) - [Germin8](http://www.germin8.com) - [goTransverse](http://www.gotransverse.com/api) From a956966ff2f2b9cd4eceaf2383bf88f66c803e2e Mon Sep 17 00:00:00 2001 From: BastiOfBerlin Date: Mon, 13 Feb 2017 11:03:48 +0100 Subject: [PATCH 003/146] Update gitignore (#4767) ignore dist folder --- .../src/main/resources/typescript-angular2/gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/gitignore b/modules/swagger-codegen/src/main/resources/typescript-angular2/gitignore index 35e2fb2b02e..149b5765472 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/gitignore +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/gitignore @@ -1,3 +1,4 @@ wwwroot/*.js node_modules typings +dist From 74da89c6ac2517ea086d22a4d1d957f1f82aff12 Mon Sep 17 00:00:00 2001 From: Clem Date: Mon, 13 Feb 2017 11:07:00 +0100 Subject: [PATCH 004/146] Fix issue when the swagger model contains an 'Object' class (#4695) If the swagger model contains a class named 'Object' some mustache templates will generate non compiling **Java** code. --- .../src/main/resources/JavaInflector/pojo.mustache | 4 ++-- .../src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache | 4 ++-- .../src/main/resources/JavaJaxRS/cxf/pojo.mustache | 2 +- .../src/main/resources/JavaJaxRS/resteasy/pojo.mustache | 4 ++-- .../src/main/resources/JavaJaxRS/spec/pojo.mustache | 4 ++-- .../swagger-codegen/src/main/resources/undertow/pojo.mustache | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaInflector/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaInflector/pojo.mustache index 56869755b79..d5d57bc6910 100644 --- a/modules/swagger-codegen/src/main/resources/JavaInflector/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaInflector/pojo.mustache @@ -47,7 +47,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{/vars}} @Override - public boolean equals(Object o) { + public boolean equals(java.lang.Object o) { if (this == o) { return true; } @@ -79,7 +79,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ - private String toIndentedString(Object o) { + private String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache index 93f920d4d12..04a5b76ea45 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf-cdi/pojo.mustache @@ -37,7 +37,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{/vars}} @Override - public boolean equals(Object o) { + public boolean equals(java.lang.Object o) { if (this == o) { return true; } @@ -69,7 +69,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ - private String toIndentedString(Object o) { + private String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index 09c8fc1fecc..c071a0d9c80 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -94,7 +94,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ - private static String toIndentedString(Object o) { + private static String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pojo.mustache index 4c84bc6e6a0..612767afd14 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pojo.mustache @@ -29,7 +29,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{/vars}} @Override - public boolean equals(Object o) { + public boolean equals(java.lang.Object o) { if (this == o) { return true; } @@ -61,7 +61,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ - private String toIndentedString(Object o) { + private String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/pojo.mustache index 51090c995e1..4d43b69319c 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/pojo.mustache @@ -33,7 +33,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{/vars}} @Override - public boolean equals(Object o) { + public boolean equals(java.lang.Object o) { if (this == o) { return true; } @@ -65,7 +65,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ - private String toIndentedString(Object o) { + private String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } diff --git a/modules/swagger-codegen/src/main/resources/undertow/pojo.mustache b/modules/swagger-codegen/src/main/resources/undertow/pojo.mustache index e63ecfe2f47..69dce348fe3 100644 --- a/modules/swagger-codegen/src/main/resources/undertow/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/undertow/pojo.mustache @@ -32,7 +32,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{/vars}} @Override - public boolean equals(Object o) { + public boolean equals(java.lang.Object o) { if (this == o) { return true; } @@ -64,7 +64,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ - private String toIndentedString(Object o) { + private String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } From 8f2e9bce6deb6ada27e331525d5f50c75c36f80b Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 13 Feb 2017 18:53:34 +0800 Subject: [PATCH 005/146] remove trailing whitespaces in java api client (#4784) --- .../Java/libraries/feign/ApiClient.mustache | 24 +++++++++++++------ .../libraries/retrofit/ApiClient.mustache | 23 ++++++++++++------ .../libraries/retrofit2/ApiClient.mustache | 24 +++++++++++++------ .../java/io/swagger/client/ApiClient.java | 8 +++---- .../java/io/swagger/client/ApiClient.java | 10 ++++---- .../java/io/swagger/client/ApiClient.java | 8 +++---- .../java/io/swagger/client/ApiClient.java | 8 +++---- 7 files changed, 68 insertions(+), 37 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/feign/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/feign/ApiClient.mustache index d33a86763ff..17d0e96f313 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/feign/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/feign/ApiClient.mustache @@ -45,17 +45,27 @@ public class ApiClient { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { {{#hasAuthMethods}} + for(String authName : authNames) { + {{#hasAuthMethods}} RequestInterceptor auth; - {{#authMethods}}if ("{{name}}".equals(authName)) { {{#isBasic}} - auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}} - auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}} - auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");{{/isOAuth}} + {{#authMethods}}if ("{{name}}".equals(authName)) { + {{#isBasic}} + auth = new HttpBasicAuth(); + {{/isBasic}} + {{#isApiKey}} + auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"); + {{/isApiKey}} + {{#isOAuth}} + auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}"); + {{/isOAuth}} } else {{/authMethods}}{ throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); } - addAuthorization(authName, auth);{{/hasAuthMethods}}{{^hasAuthMethods}} - throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");{{/hasAuthMethods}} + addAuthorization(authName, auth); + {{/hasAuthMethods}} + {{^hasAuthMethods}} + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); + {{/hasAuthMethods}} } } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache index 30de5917a34..7c45e926bcf 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache @@ -52,17 +52,26 @@ public class ApiClient { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { {{#hasAuthMethods}} + for(String authName : authNames) { + {{#hasAuthMethods}} Interceptor auth; - {{#authMethods}}if ("{{name}}".equals(authName)) { {{#isBasic}} - auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}} - auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}} - auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");{{/isOAuth}} + {{#authMethods}}if ("{{name}}".equals(authName)) { + {{#isBasic}} + auth = new HttpBasicAuth(); + {{/isBasic}} + {{#isApiKey}} + auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}} + {{#isOAuth}} + auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}"); + {{/isOAuth}} } else {{/authMethods}}{ throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); } - addAuthorization(authName, auth);{{/hasAuthMethods}}{{^hasAuthMethods}} - throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");{{/hasAuthMethods}} + addAuthorization(authName, auth); + {{/hasAuthMethods}} + {{^hasAuthMethods}} + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); + {{/hasAuthMethods}} } } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache index 191b689c8c8..cc6b993e6ab 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache @@ -58,17 +58,27 @@ public class ApiClient { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { {{#hasAuthMethods}} + for(String authName : authNames) { + {{#hasAuthMethods}} Interceptor auth; - {{#authMethods}}if ("{{name}}".equals(authName)) { {{#isBasic}} - auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}} - auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}} - auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");{{/isOAuth}} + {{#authMethods}}if ("{{name}}".equals(authName)) { + {{#isBasic}} + auth = new HttpBasicAuth(); + {{/isBasic}} + {{#isApiKey}} + auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"); + {{/isApiKey}} + {{#isOAuth}} + auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}"); + {{/isOAuth}} } else {{/authMethods}}{ throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); } - addAuthorization(authName, auth);{{/hasAuthMethods}}{{^hasAuthMethods}} - throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");{{/hasAuthMethods}} + addAuthorization(authName, auth); + {{/hasAuthMethods}} + {{^hasAuthMethods}} + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); + {{/hasAuthMethods}} } } diff --git a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java index 90c60875979..51483828c52 100644 --- a/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java @@ -40,13 +40,13 @@ public ApiClient() { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { + for(String authName : authNames) { RequestInterceptor auth; - if ("api_key".equals(authName)) { + if ("api_key".equals(authName)) { auth = new ApiKeyAuth("header", "api_key"); - } else if ("http_basic_test".equals(authName)) { + } else if ("http_basic_test".equals(authName)) { auth = new HttpBasicAuth(); - } else if ("petstore_auth".equals(authName)) { + } else if ("petstore_auth".equals(authName)) { auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets"); } else { throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java index ed9821db8f7..250c8f9550a 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java @@ -52,13 +52,15 @@ public ApiClient() { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { + for(String authName : authNames) { Interceptor auth; - if ("api_key".equals(authName)) { + if ("api_key".equals(authName)) { auth = new ApiKeyAuth("header", "api_key"); - } else if ("http_basic_test".equals(authName)) { + } else if ("http_basic_test".equals(authName)) { auth = new HttpBasicAuth(); - } else if ("petstore_auth".equals(authName)) { + + } else if ("petstore_auth".equals(authName)) { + auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets"); } else { throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java index 4be862d52ff..99586dcab59 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java @@ -51,13 +51,13 @@ public ApiClient() { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { + for(String authName : authNames) { Interceptor auth; - if ("api_key".equals(authName)) { + if ("api_key".equals(authName)) { auth = new ApiKeyAuth("header", "api_key"); - } else if ("http_basic_test".equals(authName)) { + } else if ("http_basic_test".equals(authName)) { auth = new HttpBasicAuth(); - } else if ("petstore_auth".equals(authName)) { + } else if ("petstore_auth".equals(authName)) { auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets"); } else { throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java index d3eb060514f..e3436cf56d0 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java @@ -51,13 +51,13 @@ public ApiClient() { public ApiClient(String[] authNames) { this(); - for(String authName : authNames) { + for(String authName : authNames) { Interceptor auth; - if (authName == "api_key") { + if ("api_key".equals(authName)) { auth = new ApiKeyAuth("header", "api_key"); - } else if (authName == "http_basic_test") { + } else if ("http_basic_test".equals(authName)) { auth = new HttpBasicAuth(); - } else if (authName == "petstore_auth") { + } else if ("petstore_auth".equals(authName)) { auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets"); } else { throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); From 9cf147f21572d25a2ea46a08a2e758bc52d72f78 Mon Sep 17 00:00:00 2001 From: Sreenidhi Sreesha Date: Mon, 13 Feb 2017 03:45:42 -0800 Subject: [PATCH 006/146] [Java] Change Boolean fields of CodegenParameter and CodegenResponse to boolean. (#4747) CodegenOperation and CodegenProperty classes have boolean fields instead of Boolean. This fix changes Boolean fields of CodegenParameter and CodegenResponse to boolean as well. Boolean fields are not necessary. Other classes interacting with them have to check for null before interacting with them which is unnecessary and leads to ugly code. --- .../io/swagger/codegen/CodegenParameter.java | 141 +++++++++--------- .../io/swagger/codegen/CodegenResponse.java | 52 +++---- .../io/swagger/codegen/DefaultCodegen.java | 14 +- .../languages/HaskellServantCodegen.java | 4 +- .../languages/JavascriptClientCodegen.java | 4 +- .../codegen/languages/RubyClientCodegen.java | 2 +- .../languages/StaticHtml2Generator.java | 2 +- .../java/io/swagger/codegen/CodegenTest.java | 12 +- 8 files changed, 113 insertions(+), 118 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index 3a0db92c5a4..e30159f9553 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -6,28 +6,29 @@ import java.util.List; public class CodegenParameter { - public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam, + public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, hasMore, isContainer, secondaryParam, isCollectionFormatMulti, isPrimitiveType; - public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName; + public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, + collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName; public String example; // example value (x-example) public String jsonSchema; - public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; - public Boolean isListContainer, isMapContainer; - public Boolean isFile, notFile; + public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; + public boolean isListContainer, isMapContainer; + public boolean isFile, notFile; public boolean isEnum; public List _enum; public Map allowableValues; public CodegenProperty items; public Map vendorExtensions; - public Boolean hasValidation; + public boolean hasValidation; /** * Determines whether this parameter is mandatory. If the parameter is in "path", * this property is required and its value MUST be true. Otherwise, the property * MAY be included and its default value is false. */ - public Boolean required; + public boolean required; /** * See http://json-schema.org/latest/json-schema-validation.html#anchor17. @@ -36,7 +37,7 @@ public class CodegenParameter { /** * See http://json-schema.org/latest/json-schema-validation.html#anchor17 */ - public Boolean exclusiveMaximum; + public boolean exclusiveMaximum; /** * See http://json-schema.org/latest/json-schema-validation.html#anchor21 */ @@ -44,7 +45,7 @@ public class CodegenParameter { /** * See http://json-schema.org/latest/json-schema-validation.html#anchor21 */ - public Boolean exclusiveMinimum; + public boolean exclusiveMinimum; /** * See http://json-schema.org/latest/json-schema-validation.html#anchor26 */ @@ -68,7 +69,7 @@ public class CodegenParameter { /** * See http://json-schema.org/latest/json-schema-validation.html#anchor49 */ - public Boolean uniqueItems; + public boolean uniqueItems; /** * See http://json-schema.org/latest/json-schema-validation.html#anchor14 */ @@ -156,27 +157,27 @@ public boolean equals(Object o) { CodegenParameter that = (CodegenParameter) o; if (isEnum != that.isEnum) return false; - if (isFormParam != null ? !isFormParam.equals(that.isFormParam) : that.isFormParam != null) + if (isFormParam != that.isFormParam) return false; - if (isQueryParam != null ? !isQueryParam.equals(that.isQueryParam) : that.isQueryParam != null) + if (isQueryParam != that.isQueryParam) return false; - if (isPathParam != null ? !isPathParam.equals(that.isPathParam) : that.isPathParam != null) + if (isPathParam != that.isPathParam) return false; - if (isHeaderParam != null ? !isHeaderParam.equals(that.isHeaderParam) : that.isHeaderParam != null) + if (isHeaderParam != that.isHeaderParam) return false; - if (isCookieParam != null ? !isCookieParam.equals(that.isCookieParam) : that.isCookieParam != null) + if (isCookieParam != that.isCookieParam) return false; - if (isBodyParam != null ? !isBodyParam.equals(that.isBodyParam) : that.isBodyParam != null) + if (isBodyParam != that.isBodyParam) return false; - if (hasMore != null ? !hasMore.equals(that.hasMore) : that.hasMore != null) + if (hasMore != that.hasMore) return false; - if (isContainer != null ? !isContainer.equals(that.isContainer) : that.isContainer != null) + if (isContainer != that.isContainer) return false; - if (secondaryParam != null ? !secondaryParam.equals(that.secondaryParam) : that.secondaryParam != null) + if (secondaryParam != that.secondaryParam) return false; - if (isCollectionFormatMulti != null ? !isCollectionFormatMulti.equals(that.isCollectionFormatMulti) : that.isCollectionFormatMulti != null) + if (isCollectionFormatMulti != that.isCollectionFormatMulti) return false; - if (isPrimitiveType != null ? !isPrimitiveType.equals(that.isPrimitiveType) : that.isPrimitiveType != null) + if (isPrimitiveType != that.isPrimitiveType) return false; if (baseName != null ? !baseName.equals(that.baseName) : that.baseName != null) return false; @@ -204,33 +205,33 @@ public boolean equals(Object o) { return false; if (jsonSchema != null ? !jsonSchema.equals(that.jsonSchema) : that.jsonSchema != null) return false; - if (isString != null ? !isString.equals(that.isString) : that.isString != null) + if (isString != that.isString) return false; - if (isInteger != null ? !isInteger.equals(that.isInteger) : that.isInteger != null) + if (isInteger != that.isInteger) return false; - if (isLong != null ? !isLong.equals(that.isLong) : that.isLong != null) + if (isLong != that.isLong) return false; - if (isFloat != null ? !isFloat.equals(that.isFloat) : that.isFloat != null) + if (isFloat != that.isFloat) return false; - if (isDouble != null ? !isDouble.equals(that.isDouble) : that.isDouble != null) + if (isDouble != that.isDouble) return false; - if (isByteArray != null ? !isByteArray.equals(that.isByteArray) : that.isByteArray != null) + if (isByteArray != that.isByteArray) return false; - if (isBinary != null ? !isBinary.equals(that.isBinary) : that.isBinary != null) + if (isBinary != that.isBinary) return false; - if (isBoolean != null ? !isBoolean.equals(that.isBoolean) : that.isBoolean != null) + if (isBoolean != that.isBoolean) return false; - if (isDate != null ? !isDate.equals(that.isDate) : that.isDate != null) + if (isDate != that.isDate) return false; - if (isDateTime != null ? !isDateTime.equals(that.isDateTime) : that.isDateTime != null) + if (isDateTime != that.isDateTime) return false; - if (isListContainer != null ? !isListContainer.equals(that.isListContainer) : that.isListContainer != null) + if (isListContainer != that.isListContainer) return false; - if (isMapContainer != null ? !isMapContainer.equals(that.isMapContainer) : that.isMapContainer != null) + if (isMapContainer != that.isMapContainer) return false; - if (isFile != null ? !isFile.equals(that.isFile) : that.isFile != null) + if (isFile != that.isFile) return false; - if (notFile != null ? !notFile.equals(that.notFile) : that.notFile != null) + if (notFile != that.notFile) return false; if (_enum != null ? !_enum.equals(that._enum) : that._enum != null) return false; @@ -240,17 +241,17 @@ public boolean equals(Object o) { return false; if (vendorExtensions != null ? !vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions != null) return false; - if (hasValidation != null ? !hasValidation.equals(that.hasValidation) : that.hasValidation != null) + if (hasValidation != that.hasValidation) return false; - if (required != null ? !required.equals(that.required) : that.required != null) + if (required != that.required) return false; if (maximum != null ? !maximum.equals(that.maximum) : that.maximum != null) return false; - if (exclusiveMaximum != null ? !exclusiveMaximum.equals(that.exclusiveMaximum) : that.exclusiveMaximum != null) + if (exclusiveMaximum != that.exclusiveMaximum) return false; if (minimum != null ? !minimum.equals(that.minimum) : that.minimum != null) return false; - if (exclusiveMinimum != null ? !exclusiveMinimum.equals(that.exclusiveMinimum) : that.exclusiveMinimum != null) + if (exclusiveMinimum != that.exclusiveMinimum) return false; if (maxLength != null ? !maxLength.equals(that.maxLength) : that.maxLength != null) return false; @@ -262,7 +263,7 @@ public boolean equals(Object o) { return false; if (minItems != null ? !minItems.equals(that.minItems) : that.minItems != null) return false; - if (uniqueItems != null ? !uniqueItems.equals(that.uniqueItems) : that.uniqueItems != null) + if (uniqueItems != that.uniqueItems) return false; return multipleOf != null ? multipleOf.equals(that.multipleOf) : that.multipleOf == null; @@ -270,17 +271,17 @@ public boolean equals(Object o) { @Override public int hashCode() { - int result = isFormParam != null ? isFormParam.hashCode() : 0; - result = 31 * result + (isQueryParam != null ? isQueryParam.hashCode() : 0); - result = 31 * result + (isPathParam != null ? isPathParam.hashCode() : 0); - result = 31 * result + (isHeaderParam != null ? isHeaderParam.hashCode() : 0); - result = 31 * result + (isCookieParam != null ? isCookieParam.hashCode() : 0); - result = 31 * result + (isBodyParam != null ? isBodyParam.hashCode() : 0); - result = 31 * result + (hasMore != null ? hasMore.hashCode() : 0); - result = 31 * result + (isContainer != null ? isContainer.hashCode() : 0); - result = 31 * result + (secondaryParam != null ? secondaryParam.hashCode() : 0); - result = 31 * result + (isCollectionFormatMulti != null ? isCollectionFormatMulti.hashCode() : 0); - result = 31 * result + (isPrimitiveType != null ? isPrimitiveType.hashCode() : 0); + int result = isFormParam ? 13:31; + result = 31 * result + (isQueryParam ? 13:31); + result = 31 * result + (isPathParam ? 13:31); + result = 31 * result + (isHeaderParam ? 13:31); + result = 31 * result + (isCookieParam ? 13:31); + result = 31 * result + (isBodyParam ? 13:31); + result = 31 * result + (hasMore ? 13:31); + result = 31 * result + (isContainer ? 13:31); + result = 31 * result + (secondaryParam ? 13:31); + result = 31 * result + (isCollectionFormatMulti ? 13:31); + result = 31 * result + (isPrimitiveType ? 13:31); result = 31 * result + (baseName != null ? baseName.hashCode() : 0); result = 31 * result + (paramName != null ? paramName.hashCode() : 0); result = 31 * result + (dataType != null ? dataType.hashCode() : 0); @@ -294,37 +295,37 @@ public int hashCode() { result = 31 * result + (defaultValue != null ? defaultValue.hashCode() : 0); result = 31 * result + (example != null ? example.hashCode() : 0); result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0); - result = 31 * result + (isString != null ? isString.hashCode() : 0); - result = 31 * result + (isInteger != null ? isInteger.hashCode() : 0); - result = 31 * result + (isLong != null ? isLong.hashCode() : 0); - result = 31 * result + (isFloat != null ? isFloat.hashCode() : 0); - result = 31 * result + (isDouble != null ? isDouble.hashCode() : 0); - result = 31 * result + (isByteArray != null ? isByteArray.hashCode() : 0); - result = 31 * result + (isBinary != null ? isBinary.hashCode() : 0); - result = 31 * result + (isBoolean != null ? isBoolean.hashCode() : 0); - result = 31 * result + (isDate != null ? isDate.hashCode() : 0); - result = 31 * result + (isDateTime != null ? isDateTime.hashCode() : 0); - result = 31 * result + (isListContainer != null ? isListContainer.hashCode() : 0); - result = 31 * result + (isMapContainer != null ? isMapContainer.hashCode() : 0); - result = 31 * result + (isFile != null ? isFile.hashCode() : 0); - result = 31 * result + (notFile != null ? notFile.hashCode() : 0); + result = 31 * result + (isString ? 13:31); + result = 31 * result + (isInteger ? 13:31); + result = 31 * result + (isLong ? 13:31); + result = 31 * result + (isFloat ? 13:31); + result = 31 * result + (isDouble ? 13:31); + result = 31 * result + (isByteArray ? 13:31); + result = 31 * result + (isBinary ? 13:31); + result = 31 * result + (isBoolean ? 13:31); + result = 31 * result + (isDate ? 13:31); + result = 31 * result + (isDateTime ? 13:31); + result = 31 * result + (isListContainer ? 13:31); + result = 31 * result + (isMapContainer ? 13:31); + result = 31 * result + (isFile ? 13:31); + result = 31 * result + (notFile ? 13:31); result = 31 * result + (isEnum ? 1 : 0); result = 31 * result + (_enum != null ? _enum.hashCode() : 0); result = 31 * result + (allowableValues != null ? allowableValues.hashCode() : 0); result = 31 * result + (items != null ? items.hashCode() : 0); result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0); - result = 31 * result + (hasValidation != null ? hasValidation.hashCode() : 0); - result = 31 * result + (required != null ? required.hashCode() : 0); + result = 31 * result + (hasValidation ? 13:31); + result = 31 * result + (required ? 13:31); result = 31 * result + (maximum != null ? maximum.hashCode() : 0); - result = 31 * result + (exclusiveMaximum != null ? exclusiveMaximum.hashCode() : 0); + result = 31 * result + (exclusiveMaximum ? 13:31); result = 31 * result + (minimum != null ? minimum.hashCode() : 0); - result = 31 * result + (exclusiveMinimum != null ? exclusiveMinimum.hashCode() : 0); + result = 31 * result + (exclusiveMinimum ? 13:31); result = 31 * result + (maxLength != null ? maxLength.hashCode() : 0); result = 31 * result + (minLength != null ? minLength.hashCode() : 0); result = 31 * result + (pattern != null ? pattern.hashCode() : 0); result = 31 * result + (maxItems != null ? maxItems.hashCode() : 0); result = 31 * result + (minItems != null ? minItems.hashCode() : 0); - result = 31 * result + (uniqueItems != null ? uniqueItems.hashCode() : 0); + result = 31 * result + (uniqueItems ? 13:31); result = 31 * result + (multipleOf != null ? multipleOf.hashCode() : 0); return result; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java index 4f1c9c54c3e..52fd5f4f76b 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java @@ -7,24 +7,20 @@ public class CodegenResponse { public final List headers = new ArrayList(); public String code, message; - public Boolean hasMore; + public boolean hasMore; public List> examples; public String dataType, baseType, containerType; - public Boolean isDefault; - public Boolean simpleType; - public Boolean primitiveType; - public Boolean isMapContainer; - public Boolean isListContainer; - public Boolean isBinary = Boolean.FALSE; - public Boolean isFile = Boolean.FALSE; + public boolean isDefault; + public boolean simpleType; + public boolean primitiveType; + public boolean isMapContainer; + public boolean isListContainer; + public boolean isBinary = false; + public boolean isFile = false; public Object schema; public String jsonSchema; public Map vendorExtensions; - public boolean isWildcard() { - return "0".equals(code) || "default".equals(code); - } - @Override public String toString() { return String.format("%s(%s)", code, containerType); @@ -43,7 +39,7 @@ public boolean equals(Object o) { return false; if (message != null ? !message.equals(that.message) : that.message != null) return false; - if (hasMore != null ? !hasMore.equals(that.hasMore) : that.hasMore != null) + if (hasMore != that.hasMore) return false; if (examples != null ? !examples.equals(that.examples) : that.examples != null) return false; @@ -53,19 +49,19 @@ public boolean equals(Object o) { return false; if (containerType != null ? !containerType.equals(that.containerType) : that.containerType != null) return false; - if (isDefault != null ? !isDefault.equals(that.isDefault) : that.isDefault != null) + if (isDefault != that.isDefault) return false; - if (simpleType != null ? !simpleType.equals(that.simpleType) : that.simpleType != null) + if (simpleType != that.simpleType) return false; - if (primitiveType != null ? !primitiveType.equals(that.primitiveType) : that.primitiveType != null) + if (primitiveType != that.primitiveType) return false; - if (isMapContainer != null ? !isMapContainer.equals(that.isMapContainer) : that.isMapContainer != null) + if (isMapContainer != that.isMapContainer) return false; - if (isListContainer != null ? !isListContainer.equals(that.isListContainer) : that.isListContainer != null) + if (isListContainer != that.isListContainer) return false; - if (isBinary != null ? !isBinary.equals(that.isBinary) : that.isBinary != null) + if (isBinary != that.isBinary) return false; - if (isFile != null ? !isFile.equals(that.isFile) : that.isFile != null) + if (isFile != that.isFile) return false; if (schema != null ? !schema.equals(that.schema) : that.schema != null) return false; @@ -80,18 +76,18 @@ public int hashCode() { int result = headers.hashCode(); result = 31 * result + (code != null ? code.hashCode() : 0); result = 31 * result + (message != null ? message.hashCode() : 0); - result = 31 * result + (hasMore != null ? hasMore.hashCode() : 0); + result = 31 * result + (hasMore ? 13:31); result = 31 * result + (examples != null ? examples.hashCode() : 0); result = 31 * result + (dataType != null ? dataType.hashCode() : 0); result = 31 * result + (baseType != null ? baseType.hashCode() : 0); result = 31 * result + (containerType != null ? containerType.hashCode() : 0); - result = 31 * result + (isDefault != null ? isDefault.hashCode() : 0); - result = 31 * result + (simpleType != null ? simpleType.hashCode() : 0); - result = 31 * result + (primitiveType != null ? primitiveType.hashCode() : 0); - result = 31 * result + (isMapContainer != null ? isMapContainer.hashCode() : 0); - result = 31 * result + (isListContainer != null ? isListContainer.hashCode() : 0); - result = 31 * result + (isBinary != null ? isBinary.hashCode() : 0); - result = 31 * result + (isFile != null ? isFile.hashCode() : 0); + result = 31 * result + (isDefault ? 13:31); + result = 31 * result + (simpleType ? 13:31); + result = 31 * result + (primitiveType ? 13:31); + result = 31 * result + (isMapContainer ? 13:31); + result = 31 * result + (isListContainer ? 13:31); + result = 31 * result + (isBinary ? 13:31); + result = 31 * result + (isFile ? 13:31); result = 31 * result + (schema != null ? schema.hashCode() : 0); result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0); result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 99b9ba4f381..9ac1cbba689 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2161,7 +2161,7 @@ public CodegenOperation fromOperation(String path, } else if (param instanceof FormParameter) { formParams.add(p.copy()); } - if (p.required == null || !p.required) { + if (!p.required) { op.hasOptionalParams = true; } } @@ -2179,10 +2179,8 @@ public CodegenOperation fromOperation(String path, Collections.sort(allParams, new Comparator() { @Override public int compare(CodegenParameter one, CodegenParameter another) { - boolean oneRequired = one.required == null ? false : one.required; - boolean anotherRequired = another.required == null ? false : another.required; - if (oneRequired == anotherRequired) return 0; - else if (oneRequired) return -1; + if (one.required == another.required) return 0; + else if (one.required) return -1; else return 1; } }); @@ -2410,14 +2408,14 @@ public CodegenParameter fromParameter(Parameter param, Set imports) { p.minimum = qp.getMinimum() == null ? null : String.valueOf(qp.getMinimum()); } - p.exclusiveMaximum = qp.isExclusiveMaximum(); - p.exclusiveMinimum = qp.isExclusiveMinimum(); + p.exclusiveMaximum = qp.isExclusiveMaximum() == null ? false : qp.isExclusiveMaximum(); + p.exclusiveMinimum = qp.isExclusiveMinimum() == null ? false : qp.isExclusiveMinimum(); p.maxLength = qp.getMaxLength(); p.minLength = qp.getMinLength(); p.pattern = toRegularExpression(qp.getPattern()); p.maxItems = qp.getMaxItems(); p.minItems = qp.getMinItems(); - p.uniqueItems = qp.isUniqueItems(); + p.uniqueItems = qp.isUniqueItems() == null ? false : qp.isUniqueItems(); p.multipleOf = qp.getMultipleOf(); // exclusive* are noop without corresponding min/max diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/HaskellServantCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/HaskellServantCodegen.java index 97f73fcebb6..96a8a7bb926 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/HaskellServantCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/HaskellServantCodegen.java @@ -389,7 +389,7 @@ public CodegenOperation fromOperation(String resourcePath, String httpMethod, Op // Query parameters appended to routes for (CodegenParameter param : op.queryParams) { String paramType = param.dataType; - if(param.isListContainer != null && param.isListContainer) { + if (param.isListContainer) { paramType = makeQueryListType(paramType, param.collectionFormat); } path.add("QueryParam \"" + param.baseName + "\" " + paramType); @@ -420,7 +420,7 @@ public CodegenOperation fromOperation(String resourcePath, String httpMethod, Op path.add("Header \"" + param.baseName + "\" " + param.dataType); String paramType = param.dataType; - if(param.isListContainer != null && param.isListContainer) { + if (param.isListContainer) { paramType = makeQueryListType(paramType, param.collectionFormat); } type.add("Maybe " + paramType); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java index 8b68dcdbd16..dd211512906 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java @@ -710,7 +710,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation CodegenParameter lastRequired = null; CodegenParameter lastOptional = null; for (CodegenParameter p : op.allParams) { - if (p.required != null && p.required) { + if (p.required) { lastRequired = p; } else { lastOptional = p; @@ -866,7 +866,7 @@ public Map postProcessOperations(Map objs) { List argList = new ArrayList(); boolean hasOptionalParams = false; for (CodegenParameter p : operation.allParams) { - if (p.required != null && p.required) { + if (p.required) { argList.add(p.paramName); } else { hasOptionalParams = true; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java index 4dca4806180..cab74966da1 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java @@ -272,7 +272,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation CodegenParameter lastRequired = null; CodegenParameter lastOptional = null; for (CodegenParameter p : op.allParams) { - if (p.required != null && p.required) { + if (p.required) { lastRequired = p; } else { lastOptional = p; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtml2Generator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtml2Generator.java index 06c23075e8e..3fbfd90e5e0 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtml2Generator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtml2Generator.java @@ -158,7 +158,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation CodegenParameter lastRequired = null; CodegenParameter lastOptional = null; for (CodegenParameter p : op.allParams) { - if (p.required != null && p.required) { + if (p.required) { lastRequired = p; } else { lastOptional = p; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java index a661ba4ea42..b5079ead853 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/CodegenTest.java @@ -58,9 +58,9 @@ public void fileUploadParamTest() { final CodegenParameter file = op.formParams.get(1); Assert.assertTrue(file.isFormParam); Assert.assertEquals(file.dataType, "File"); - Assert.assertNull(file.required); + Assert.assertFalse(file.required); Assert.assertTrue(file.isFile); - Assert.assertNull(file.hasMore); + Assert.assertFalse(file.hasMore); } @Test(description = "read formParam values from a 2.0 spec") @@ -87,7 +87,7 @@ public void formParamTest() { Assert.assertTrue(idParam.isPathParam); Assert.assertEquals(idParam.dataType, "String"); Assert.assertTrue(idParam.required); - Assert.assertNull(idParam.hasMore); + Assert.assertFalse(idParam.hasMore); Assert.assertEquals(op.allParams.size(), 3); Assert.assertEquals(op.formParams.size(), 2); @@ -96,15 +96,15 @@ public void formParamTest() { Assert.assertTrue(nameParam.isFormParam); Assert.assertTrue(nameParam.notFile); Assert.assertEquals(nameParam.dataType, "String"); - Assert.assertNull(nameParam.required); + Assert.assertFalse(nameParam.required); Assert.assertTrue(nameParam.hasMore); final CodegenParameter statusParam = op.formParams.get(1); Assert.assertTrue(statusParam.isFormParam); Assert.assertTrue(statusParam.notFile); Assert.assertEquals(statusParam.dataType, "String"); - Assert.assertNull(statusParam.required); - Assert.assertNull(statusParam.hasMore); + Assert.assertFalse(statusParam.required); + Assert.assertFalse(statusParam.hasMore); } @Test(description = "handle enum array in query parameter test") From 7df1f8e2006a824a30ad2f665cc076b3c1c653d0 Mon Sep 17 00:00:00 2001 From: Igor Khomenko Date: Mon, 13 Feb 2017 14:59:36 +0200 Subject: [PATCH 007/146] Update DefaultGenerator.java (#4760) --- .../src/main/java/io/swagger/codegen/DefaultGenerator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index 03433e64580..f6983d0340f 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -154,8 +154,10 @@ private void configureSwaggerInfo() { // set a default description if none if provided config.additionalProperties().put("appDescription", "No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)"); + config.additionalProperties().put("unescapedAppDescription", "No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)"); } else { config.additionalProperties().put("appDescription", config.escapeText(info.getDescription())); + config.additionalProperties().put("unescapedAppDescription", info.getDescription()); } if (info.getContact() != null) { From 56251bf21409e388fcba3584f51b5a243aa88dad Mon Sep 17 00:00:00 2001 From: Igor Khomenko Date: Mon, 13 Feb 2017 15:47:51 +0200 Subject: [PATCH 008/146] added QuickBlox to 'Companies/Projects using Swagger Codegen' section (#4786) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 40767c2b202..b5c3886edf5 100644 --- a/README.md +++ b/README.md @@ -888,6 +888,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you - [Prill Tecnologia](http://www.prill.com.br) - [QAdept](http://qadept.com/) - [QuantiModo](https://quantimo.do/) +- [QuickBlox](https://quickblox.com/) - [Rapid7](https://rapid7.com/) - [Reload! A/S](https://reload.dk/) - [REstore](https://www.restore.eu) From ee23f8e50c9ac6e184b1e94a6eaba78be38a909b Mon Sep 17 00:00:00 2001 From: clasnake Date: Mon, 13 Feb 2017 22:33:55 +0800 Subject: [PATCH 009/146] Fix finch package name. (#4755) --- .../codegen/languages/FinchServerCodegen.java | 6 +- samples/server/petstore/finch/LICENSE | 201 -------------- .../finch/src/main/scala/DataAccessor.scala | 248 +++++++++--------- .../finch/src/main/scala/Server.scala | 11 +- .../finch/src/main/scala/endpoint.scala | 44 ++-- .../finch/src/main/scala/errors.scala | 2 +- .../main/scala/io/swagger/apis/PetApi.scala | 149 +++++++++++ .../main/scala/io/swagger/apis/StoreApi.scala | 96 +++++++ .../main/scala/io/swagger/apis/UserApi.scala | 150 +++++++++++ .../scala/io/swagger/models/ApiResponse.scala | 26 ++ .../scala/io/swagger/models/Category.scala | 24 ++ .../main/scala/io/swagger/models/Order.scala | 33 +++ .../main/scala/io/swagger/models/Pet.scala | 35 +++ .../main/scala/io/swagger/models/Tag.scala | 24 ++ .../main/scala/io/swagger/models/User.scala | 36 +++ .../io/swagger/petstore/apis/PetApi.scala | 148 ----------- .../io/swagger/petstore/apis/StoreApi.scala | 95 ------- .../io/swagger/petstore/apis/UserApi.scala | 149 ----------- .../swagger/petstore/models/ApiResponse.scala | 27 -- .../io/swagger/petstore/models/Category.scala | 25 -- .../io/swagger/petstore/models/Order.scala | 34 --- .../io/swagger/petstore/models/Pet.scala | 36 --- .../io/swagger/petstore/models/Tag.scala | 25 -- .../io/swagger/petstore/models/User.scala | 37 --- 24 files changed, 729 insertions(+), 932 deletions(-) delete mode 100644 samples/server/petstore/finch/LICENSE create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala create mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala delete mode 100644 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java index 4a3eed3a01b..f807325c144 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java @@ -15,12 +15,12 @@ import java.util.Map; public class FinchServerCodegen extends DefaultCodegen implements CodegenConfig { - protected String invokerPackage = "io.swagger.petstore.client"; + protected String invokerPackage = "io.swagger.client"; protected String groupId = "io.swagger"; protected String artifactId = "finch-server"; protected String artifactVersion = "1.0.0"; protected String sourceFolder = "src/main/scala"; - protected String packageName = "io.swagger.petstore"; + protected String packageName = "io.swagger"; public FinchServerCodegen() { super(); @@ -156,7 +156,7 @@ public FinchServerCodegen() { importMapping.put("LocalTime", "java.time.LocalTime"); cliOptions.clear(); - cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Finch package name (e.g. io.swagger.petstore).") + cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Finch package name (e.g. io.swagger).") .defaultValue(this.packageName)); cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC)); cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC)); diff --git a/samples/server/petstore/finch/LICENSE b/samples/server/petstore/finch/LICENSE deleted file mode 100644 index 8dada3edaf5..00000000000 --- a/samples/server/petstore/finch/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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/finch/src/main/scala/DataAccessor.scala b/samples/server/petstore/finch/src/main/scala/DataAccessor.scala index bcbd036637c..4c9d06b2ea9 100644 --- a/samples/server/petstore/finch/src/main/scala/DataAccessor.scala +++ b/samples/server/petstore/finch/src/main/scala/DataAccessor.scala @@ -1,133 +1,133 @@ -package io.swagger.petstore +package io.swagger // TODO: properly handle custom imports import java.io._ import java.util.Date -import io.swagger.petstore.models._ +import io.swagger.models._ trait DataAccessor { - // TODO: apiInfo -> apis -> operations = ??? - // NOTE: ??? throws a not implemented exception - - /** - * - * @return A Unit - */ - def Pet_addPet(body: Pet): Unit = ??? - - /** - * - * @return A Unit - */ - def Pet_deletePet(petId: Long, apiKey: String): Unit = ??? - - /** - * - * @return A Seq[Pet] - */ - def Pet_findPetsByStatus(status: Seq[String]): Seq[Pet] = ??? - - /** - * - * @return A Seq[Pet] - */ - def Pet_findPetsByTags(tags: Seq[String]): Seq[Pet] = ??? - - /** - * - * @return A Pet - */ - def Pet_getPetById(petId: Long): Pet = ??? - - /** - * - * @return A Unit - */ - def Pet_updatePet(body: Pet): Unit = ??? - - /** - * - * @return A Unit - */ - def Pet_updatePetWithForm(petId: Long, name: String, status: String): Unit = ??? - - /** - * - * @return A ApiResponse - */ - def Pet_uploadFile(petId: Long, additionalMetadata: String, file: File): ApiResponse = ??? - - /** - * - * @return A Unit - */ - def Store_deleteOrder(orderId: String): Unit = ??? - - /** - * - * @return A Map[String, Int] - */ - def Store_getInventory(): Map[String, Int] = ??? - - /** - * - * @return A Order - */ - def Store_getOrderById(orderId: Long): Order = ??? - - /** - * - * @return A Order - */ - def Store_placeOrder(body: Order): Order = ??? - - /** - * - * @return A Unit - */ - def User_createUser(body: User): Unit = ??? - - /** - * - * @return A Unit - */ - def User_createUsersWithArrayInput(body: Seq[User]): Unit = ??? - - /** - * - * @return A Unit - */ - def User_createUsersWithListInput(body: Seq[User]): Unit = ??? - - /** - * - * @return A Unit - */ - def User_deleteUser(username: String): Unit = ??? - - /** - * - * @return A User - */ - def User_getUserByName(username: String): User = ??? - - /** - * - * @return A String - */ - def User_loginUser(username: String, password: String): String = ??? - - /** - * - * @return A Unit - */ - def User_logoutUser(): Unit = ??? - - /** - * - * @return A Unit - */ - def User_updateUser(username: String, body: User): Unit = ??? + // TODO: apiInfo -> apis -> operations = ??? + // NOTE: ??? throws a not implemented exception + + /** + * + * @return A Unit + */ + def Pet_addPet(body: Pet): Unit = ??? + + /** + * + * @return A Unit + */ + def Pet_deletePet(petId: Long, apiKey: String): Unit = ??? + + /** + * + * @return A Seq[Pet] + */ + def Pet_findPetsByStatus(status: Seq[String]): Seq[Pet] = ??? + + /** + * + * @return A Seq[Pet] + */ + def Pet_findPetsByTags(tags: Seq[String]): Seq[Pet] = ??? + + /** + * + * @return A Pet + */ + def Pet_getPetById(petId: Long): Pet = ??? + + /** + * + * @return A Unit + */ + def Pet_updatePet(body: Pet): Unit = ??? + + /** + * + * @return A Unit + */ + def Pet_updatePetWithForm(petId: Long, name: String, status: String): Unit = ??? + + /** + * + * @return A ApiResponse + */ + def Pet_uploadFile(petId: Long, additionalMetadata: String, file: File): ApiResponse = ??? + + /** + * + * @return A Unit + */ + def Store_deleteOrder(orderId: String): Unit = ??? + + /** + * + * @return A Map[String, Int] + */ + def Store_getInventory(): Map[String, Int] = ??? + + /** + * + * @return A Order + */ + def Store_getOrderById(orderId: Long): Order = ??? + + /** + * + * @return A Order + */ + def Store_placeOrder(body: Order): Order = ??? + + /** + * + * @return A Unit + */ + def User_createUser(body: User): Unit = ??? + + /** + * + * @return A Unit + */ + def User_createUsersWithArrayInput(body: Seq[User]): Unit = ??? + + /** + * + * @return A Unit + */ + def User_createUsersWithListInput(body: Seq[User]): Unit = ??? + + /** + * + * @return A Unit + */ + def User_deleteUser(username: String): Unit = ??? + + /** + * + * @return A User + */ + def User_getUserByName(username: String): User = ??? + + /** + * + * @return A String + */ + def User_loginUser(username: String, password: String): String = ??? + + /** + * + * @return A Unit + */ + def User_logoutUser(): Unit = ??? + + /** + * + * @return A Unit + */ + def User_updateUser(username: String, body: User): Unit = ??? } \ No newline at end of file diff --git a/samples/server/petstore/finch/src/main/scala/Server.scala b/samples/server/petstore/finch/src/main/scala/Server.scala index 716b6eae52e..ec3ed482e27 100644 --- a/samples/server/petstore/finch/src/main/scala/Server.scala +++ b/samples/server/petstore/finch/src/main/scala/Server.scala @@ -1,22 +1,23 @@ -package io.swagger.petstore +package io.swagger import io.finch._ import io.finch.circe._ -import io.circe.{ Decoder, ObjectEncoder } +import io.circe.{Decoder, ObjectEncoder} import io.circe.generic.auto._ import io.circe.generic.semiauto import io.circe.generic.semiauto._ import io.circe.java8.time._ import com.twitter.finagle.Http import com.twitter.finagle.util.LoadService -import com.twitter.util.{ Await, Future } +import com.twitter.util.{Await, Future} + class Server { - // Loads implementation defined in resources/META-INF/services/io.swagger.petstore.DataAccessor + // Loads implementation defined in resources/META-INF/services/io.swagger.DataAccessor val db = LoadService[DataAccessor]() match { case accessor :: _ => accessor - case _ => new DataAccessor {} + case _ => new DataAccessor { } } val service = endpoint.makeService(db) diff --git a/samples/server/petstore/finch/src/main/scala/endpoint.scala b/samples/server/petstore/finch/src/main/scala/endpoint.scala index df0093b7b13..5241b51bbd8 100644 --- a/samples/server/petstore/finch/src/main/scala/endpoint.scala +++ b/samples/server/petstore/finch/src/main/scala/endpoint.scala @@ -1,15 +1,15 @@ -package io.swagger.petstore +package io.swagger import com.twitter.finagle.Service -import com.twitter.finagle.http.{ Request, Response } +import com.twitter.finagle.http.{Request, Response} import com.twitter.finagle.http.exp.Multipart.FileUpload import com.twitter.util.Future import io.finch._, items._ -import io.circe.{ Encoder, Json } +import io.circe.{Encoder, Json} import io.finch.circe._ import io.circe.generic.semiauto._ -import io.swagger.petstore.apis._ +import io.swagger.apis._ /** * Provides the paths and endpoints for all the API's public service methods. @@ -17,32 +17,32 @@ import io.swagger.petstore.apis._ object endpoint { def errorToJson(e: Exception): Json = e match { - case Error.NotPresent(_) => - Json.obj("error" -> Json.fromString("something_not_present")) - case Error.NotParsed(_, _, _) => - Json.obj("error" -> Json.fromString("something_not_parsed")) - case Error.NotValid(_, _) => - Json.obj("error" -> Json.fromString("something_not_valid")) - case error: PetstoreError => - Json.obj("error" -> Json.fromString(error.message)) + case Error.NotPresent(_) => + Json.obj("error" -> Json.fromString("something_not_present")) + case Error.NotParsed(_, _, _) => + Json.obj("error" -> Json.fromString("something_not_parsed")) + case Error.NotValid(_, _) => + Json.obj("error" -> Json.fromString("something_not_valid")) + case error: PetstoreError => + Json.obj("error" -> Json.fromString(error.message)) } implicit val ee: Encoder[Exception] = Encoder.instance { - case e: Error => errorToJson(e) - case Errors(nel) => Json.arr(nel.toList.map(errorToJson): _*) + case e: Error => errorToJson(e) + case Errors(nel) => Json.arr(nel.toList.map(errorToJson): _*) } /** - * Compiles together all the endpoints relating to public service methods. - * - * @return A service that contains all provided endpoints of the API. - */ + * Compiles together all the endpoints relating to public service methods. + * + * @return A service that contains all provided endpoints of the API. + */ def makeService(da: DataAccessor): Service[Request, Response] = ( - PetApi.endpoints(da) :+: - StoreApi.endpoints(da) :+: - UserApi.endpoints(da) + PetApi.endpoints(da) :+: + StoreApi.endpoints(da) :+: + UserApi.endpoints(da) ).handle({ case e: PetstoreError => NotFound(e) - }).toService + }).toService } \ No newline at end of file diff --git a/samples/server/petstore/finch/src/main/scala/errors.scala b/samples/server/petstore/finch/src/main/scala/errors.scala index 69e3831c15d..162549e0f23 100644 --- a/samples/server/petstore/finch/src/main/scala/errors.scala +++ b/samples/server/petstore/finch/src/main/scala/errors.scala @@ -1,4 +1,4 @@ -package io.swagger.petstore +package io.swagger /** * The parent error from which most PetstoreAPI errors extend. Thrown whenever something in the api goes wrong. diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala new file mode 100644 index 00000000000..74a01c56f51 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala @@ -0,0 +1,149 @@ +package io.swagger.apis + +import java.io._ +import java.util.Date +import io.swagger._ +import io.swagger.models._ +import io.swagger.models.ApiResponse +import java.io.File +import io.swagger.models.Pet +import io.finch.circe._ +import io.circe.generic.semiauto._ +import com.twitter.concurrent.AsyncStream +import com.twitter.finagle.Service +import com.twitter.finagle.Http +import com.twitter.finagle.http.{Request, Response} +import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload} +import com.twitter.util.Future +import com.twitter.io.Buf +import io.finch._, items._ +import java.io.File + +object PetApi { + /** + * Compiles all service endpoints. + * @return Bundled compilation of all service endpoints. + */ + def endpoints(da: DataAccessor) = + addPet(da) :+: + deletePet(da) :+: + findPetsByStatus(da) :+: + findPetsByTags(da) :+: + getPetById(da) :+: + updatePet(da) :+: + updatePetWithForm(da) :+: + uploadFile(da) + + /** + * + * @return And endpoint representing a Unit + */ + private def addPet(da: DataAccessor): Endpoint[Unit] = + post("pet" :: jsonBody[Pet]) { (body: Pet) => + da.Pet_addPet(body) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def deletePet(da: DataAccessor): Endpoint[Unit] = + delete("pet" :: long :: string) { (petId: Long, apiKey: String) => + da.Pet_deletePet(petId, apiKey) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Seq[Pet] + */ + private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] = + get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) => + Ok(da.Pet_findPetsByStatus(status)) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Seq[Pet] + */ + private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] = + get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) => + Ok(da.Pet_findPetsByTags(tags)) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Pet + */ + private def getPetById(da: DataAccessor): Endpoint[Pet] = + get("pet" :: long ) { (petId: Long) => + Ok(da.Pet_getPetById(petId)) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def updatePet(da: DataAccessor): Endpoint[Unit] = + put("pet" :: jsonBody[Pet]) { (body: Pet) => + da.Pet_updatePet(body) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] = + post("pet" :: long :: string :: string) { (petId: Long, name: String, status: String) => + da.Pet_updatePetWithForm(petId, name, status) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a ApiResponse + */ + private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] = + post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: String, file: FileUpload) => + Ok(da.Pet_uploadFile(petId, additionalMetadata, file)) + } handle { + case e: Exception => BadRequest(e) + } + + + implicit private def fileUploadToFile(fileUpload: FileUpload) : File = { + fileUpload match { + case upload: InMemoryFileUpload => + bytesToFile(Buf.ByteArray.Owned.extract(upload.content)) + case upload: OnDiskFileUpload => + upload.content + case _ => null + } + } + + private def bytesToFile(input: Array[Byte]): java.io.File = { + val file = File.createTempFile("tmpPetApi", null) + val output = new FileOutputStream(file) + output.write(input) + file + } + + // This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere. + implicit def seqList[A](input: Seq[A]): List[A] = input.toList +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala new file mode 100644 index 00000000000..02186ce1f65 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala @@ -0,0 +1,96 @@ +package io.swagger.apis + +import java.io._ +import java.util.Date +import io.swagger._ +import io.swagger.models._ +import io.swagger.models.Order +import io.finch.circe._ +import io.circe.generic.semiauto._ +import com.twitter.concurrent.AsyncStream +import com.twitter.finagle.Service +import com.twitter.finagle.Http +import com.twitter.finagle.http.{Request, Response} +import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload} +import com.twitter.util.Future +import com.twitter.io.Buf +import io.finch._, items._ +import java.io.File + +object StoreApi { + /** + * Compiles all service endpoints. + * @return Bundled compilation of all service endpoints. + */ + def endpoints(da: DataAccessor) = + deleteOrder(da) :+: + getInventory(da) :+: + getOrderById(da) :+: + placeOrder(da) + + /** + * + * @return And endpoint representing a Unit + */ + private def deleteOrder(da: DataAccessor): Endpoint[Unit] = + delete("store" :: "order" :: string ) { (orderId: String) => + da.Store_deleteOrder(orderId) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Map[String, Int] + */ + private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] = + get("store" :: "inventory" ) { + Ok(da.Store_getInventory()) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Order + */ + private def getOrderById(da: DataAccessor): Endpoint[Order] = + get("store" :: "order" :: long ) { (orderId: Long) => + Ok(da.Store_getOrderById(orderId)) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Order + */ + private def placeOrder(da: DataAccessor): Endpoint[Order] = + post("store" :: "order" :: jsonBody[Order]) { (body: Order) => + Ok(da.Store_placeOrder(body)) + } handle { + case e: Exception => BadRequest(e) + } + + + implicit private def fileUploadToFile(fileUpload: FileUpload) : File = { + fileUpload match { + case upload: InMemoryFileUpload => + bytesToFile(Buf.ByteArray.Owned.extract(upload.content)) + case upload: OnDiskFileUpload => + upload.content + case _ => null + } + } + + private def bytesToFile(input: Array[Byte]): java.io.File = { + val file = File.createTempFile("tmpStoreApi", null) + val output = new FileOutputStream(file) + output.write(input) + file + } + + // This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere. + implicit def seqList[A](input: Seq[A]): List[A] = input.toList +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala new file mode 100644 index 00000000000..dfb49b4291a --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala @@ -0,0 +1,150 @@ +package io.swagger.apis + +import java.io._ +import java.util.Date +import io.swagger._ +import io.swagger.models._ +import scala.collection.immutable.Seq +import io.swagger.models.User +import io.finch.circe._ +import io.circe.generic.semiauto._ +import com.twitter.concurrent.AsyncStream +import com.twitter.finagle.Service +import com.twitter.finagle.Http +import com.twitter.finagle.http.{Request, Response} +import com.twitter.finagle.http.exp.Multipart.{FileUpload, InMemoryFileUpload, OnDiskFileUpload} +import com.twitter.util.Future +import com.twitter.io.Buf +import io.finch._, items._ +import java.io.File + +object UserApi { + /** + * Compiles all service endpoints. + * @return Bundled compilation of all service endpoints. + */ + def endpoints(da: DataAccessor) = + createUser(da) :+: + createUsersWithArrayInput(da) :+: + createUsersWithListInput(da) :+: + deleteUser(da) :+: + getUserByName(da) :+: + loginUser(da) :+: + logoutUser(da) :+: + updateUser(da) + + /** + * + * @return And endpoint representing a Unit + */ + private def createUser(da: DataAccessor): Endpoint[Unit] = + post("user" :: jsonBody[User]) { (body: User) => + da.User_createUser(body) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] = + post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) => + da.User_createUsersWithArrayInput(body) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] = + post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) => + da.User_createUsersWithListInput(body) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def deleteUser(da: DataAccessor): Endpoint[Unit] = + delete("user" :: string ) { (username: String) => + da.User_deleteUser(username) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a User + */ + private def getUserByName(da: DataAccessor): Endpoint[User] = + get("user" :: string ) { (username: String) => + Ok(da.User_getUserByName(username)) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a String + */ + private def loginUser(da: DataAccessor): Endpoint[String] = + get("user" :: "login" :: string :: string) { (username: String, password: String) => + Ok(da.User_loginUser(username, password)) + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def logoutUser(da: DataAccessor): Endpoint[Unit] = + get("user" :: "logout" ) { + da.User_logoutUser() + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + /** + * + * @return And endpoint representing a Unit + */ + private def updateUser(da: DataAccessor): Endpoint[Unit] = + put("user" :: string :: jsonBody[User]) { (username: String, body: User) => + da.User_updateUser(username, body) + NoContent[Unit] + } handle { + case e: Exception => BadRequest(e) + } + + + implicit private def fileUploadToFile(fileUpload: FileUpload) : File = { + fileUpload match { + case upload: InMemoryFileUpload => + bytesToFile(Buf.ByteArray.Owned.extract(upload.content)) + case upload: OnDiskFileUpload => + upload.content + case _ => null + } + } + + private def bytesToFile(input: Array[Byte]): java.io.File = { + val file = File.createTempFile("tmpUserApi", null) + val output = new FileOutputStream(file) + output.write(input) + file + } + + // This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere. + implicit def seqList[A](input: Seq[A]): List[A] = input.toList +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala new file mode 100644 index 00000000000..9e603aadec6 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/ApiResponse.scala @@ -0,0 +1,26 @@ +package io.swagger.models + +import io.circe._ +import io.finch.circe._ +import io.circe.generic.semiauto._ +import io.circe.java8.time._ +import io.swagger._ + +/** + * Describes the result of uploading an image resource + * @param code + * @param _type + * @param message + */ +case class ApiResponse(code: Option[Int], + _type: Option[String], + message: Option[String] + ) + +object ApiResponse { + /** + * Creates the codec for converting ApiResponse from and to JSON. + */ + implicit val decoder: Decoder[ApiResponse] = deriveDecoder + implicit val encoder: ObjectEncoder[ApiResponse] = deriveEncoder +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala new file mode 100644 index 00000000000..be697aa298e --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Category.scala @@ -0,0 +1,24 @@ +package io.swagger.models + +import io.circe._ +import io.finch.circe._ +import io.circe.generic.semiauto._ +import io.circe.java8.time._ +import io.swagger._ + +/** + * A category for a pet + * @param id + * @param name + */ +case class Category(id: Option[Long], + name: Option[String] + ) + +object Category { + /** + * Creates the codec for converting Category from and to JSON. + */ + implicit val decoder: Decoder[Category] = deriveDecoder + implicit val encoder: ObjectEncoder[Category] = deriveEncoder +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala new file mode 100644 index 00000000000..2934ee921b3 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Order.scala @@ -0,0 +1,33 @@ +package io.swagger.models + +import io.circe._ +import io.finch.circe._ +import io.circe.generic.semiauto._ +import io.circe.java8.time._ +import io.swagger._ +import java.time.LocalDateTime + +/** + * An order for a pets from the pet store + * @param id + * @param petId + * @param quantity + * @param shipDate + * @param status Order Status + * @param complete + */ +case class Order(id: Option[Long], + petId: Option[Long], + quantity: Option[Int], + shipDate: Option[LocalDateTime], + status: Option[String], + complete: Option[Boolean] + ) + +object Order { + /** + * Creates the codec for converting Order from and to JSON. + */ + implicit val decoder: Decoder[Order] = deriveDecoder + implicit val encoder: ObjectEncoder[Order] = deriveEncoder +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala new file mode 100644 index 00000000000..e78617c7db8 --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Pet.scala @@ -0,0 +1,35 @@ +package io.swagger.models + +import io.circe._ +import io.finch.circe._ +import io.circe.generic.semiauto._ +import io.circe.java8.time._ +import io.swagger._ +import io.swagger.models.Category +import io.swagger.models.Tag +import scala.collection.immutable.Seq + +/** + * A pet for sale in the pet store + * @param id + * @param category + * @param name + * @param photoUrls + * @param tags + * @param status pet status in the store + */ +case class Pet(id: Option[Long], + category: Option[Category], + name: String, + photoUrls: Seq[String], + tags: Option[Seq[Tag]], + status: Option[String] + ) + +object Pet { + /** + * Creates the codec for converting Pet from and to JSON. + */ + implicit val decoder: Decoder[Pet] = deriveDecoder + implicit val encoder: ObjectEncoder[Pet] = deriveEncoder +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala new file mode 100644 index 00000000000..242ffcfc86e --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/Tag.scala @@ -0,0 +1,24 @@ +package io.swagger.models + +import io.circe._ +import io.finch.circe._ +import io.circe.generic.semiauto._ +import io.circe.java8.time._ +import io.swagger._ + +/** + * A tag for a pet + * @param id + * @param name + */ +case class Tag(id: Option[Long], + name: Option[String] + ) + +object Tag { + /** + * Creates the codec for converting Tag from and to JSON. + */ + implicit val decoder: Decoder[Tag] = deriveDecoder + implicit val encoder: ObjectEncoder[Tag] = deriveEncoder +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala new file mode 100644 index 00000000000..18253b5deae --- /dev/null +++ b/samples/server/petstore/finch/src/main/scala/io/swagger/models/User.scala @@ -0,0 +1,36 @@ +package io.swagger.models + +import io.circe._ +import io.finch.circe._ +import io.circe.generic.semiauto._ +import io.circe.java8.time._ +import io.swagger._ + +/** + * A User who is purchasing from the pet store + * @param id + * @param username + * @param firstName + * @param lastName + * @param email + * @param password + * @param phone + * @param userStatus User Status + */ +case class User(id: Option[Long], + username: Option[String], + firstName: Option[String], + lastName: Option[String], + email: Option[String], + password: Option[String], + phone: Option[String], + userStatus: Option[Int] + ) + +object User { + /** + * Creates the codec for converting User from and to JSON. + */ + implicit val decoder: Decoder[User] = deriveDecoder + implicit val encoder: ObjectEncoder[User] = deriveEncoder +} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala deleted file mode 100644 index 420279685d3..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala +++ /dev/null @@ -1,148 +0,0 @@ -package io.swagger.petstore.apis - -import java.io._ -import java.util.Date -import io.swagger.petstore._ -import io.swagger.petstore.models._ -import io.swagger.petstore.models.Pet -import java.io.File -import io.swagger.petstore.models.ApiResponse -import io.finch.circe._ -import io.circe.generic.semiauto._ -import com.twitter.concurrent.AsyncStream -import com.twitter.finagle.Service -import com.twitter.finagle.Http -import com.twitter.finagle.http.{ Request, Response } -import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload } -import com.twitter.util.Future -import com.twitter.io.Buf -import io.finch._, items._ -import java.io.File - -object PetApi { - /** - * Compiles all service endpoints. - * @return Bundled compilation of all service endpoints. - */ - def endpoints(da: DataAccessor) = - addPet(da) :+: - deletePet(da) :+: - findPetsByStatus(da) :+: - findPetsByTags(da) :+: - getPetById(da) :+: - updatePet(da) :+: - updatePetWithForm(da) :+: - uploadFile(da) - - /** - * - * @return And endpoint representing a Unit - */ - private def addPet(da: DataAccessor): Endpoint[Unit] = - post("pet" :: jsonBody[Pet]) { (body: Pet) => - da.Pet_addPet(body) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def deletePet(da: DataAccessor): Endpoint[Unit] = - delete("pet" :: long :: string) { (petId: Long, apiKey: String) => - da.Pet_deletePet(petId, apiKey) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Seq[Pet] - */ - private def findPetsByStatus(da: DataAccessor): Endpoint[Seq[Pet]] = - get("pet" :: "findByStatus" :: params("status")) { (status: Seq[String]) => - Ok(da.Pet_findPetsByStatus(status)) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Seq[Pet] - */ - private def findPetsByTags(da: DataAccessor): Endpoint[Seq[Pet]] = - get("pet" :: "findByTags" :: params("tags")) { (tags: Seq[String]) => - Ok(da.Pet_findPetsByTags(tags)) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Pet - */ - private def getPetById(da: DataAccessor): Endpoint[Pet] = - get("pet" :: long) { (petId: Long) => - Ok(da.Pet_getPetById(petId)) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def updatePet(da: DataAccessor): Endpoint[Unit] = - put("pet" :: jsonBody[Pet]) { (body: Pet) => - da.Pet_updatePet(body) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def updatePetWithForm(da: DataAccessor): Endpoint[Unit] = - post("pet" :: long :: string :: string) { (petId: Long, name: String, status: String) => - da.Pet_updatePetWithForm(petId, name, status) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a ApiResponse - */ - private def uploadFile(da: DataAccessor): Endpoint[ApiResponse] = - post("pet" :: long :: "uploadImage" :: string :: fileUpload("file")) { (petId: Long, additionalMetadata: String, file: FileUpload) => - Ok(da.Pet_uploadFile(petId, additionalMetadata, file)) - } handle { - case e: Exception => BadRequest(e) - } - - implicit private def fileUploadToFile(fileUpload: FileUpload): File = { - fileUpload match { - case upload: InMemoryFileUpload => - bytesToFile(Buf.ByteArray.Owned.extract(upload.content)) - case upload: OnDiskFileUpload => - upload.content - case _ => null - } - } - - private def bytesToFile(input: Array[Byte]): java.io.File = { - val file = File.createTempFile("tmpPetApi", null) - val output = new FileOutputStream(file) - output.write(input) - file - } - - // This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere. - implicit def seqList[A](input: Seq[A]): List[A] = input.toList -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala deleted file mode 100644 index 38dda7b4786..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala +++ /dev/null @@ -1,95 +0,0 @@ -package io.swagger.petstore.apis - -import java.io._ -import java.util.Date -import io.swagger.petstore._ -import io.swagger.petstore.models._ -import io.swagger.petstore.models.Order -import io.finch.circe._ -import io.circe.generic.semiauto._ -import com.twitter.concurrent.AsyncStream -import com.twitter.finagle.Service -import com.twitter.finagle.Http -import com.twitter.finagle.http.{ Request, Response } -import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload } -import com.twitter.util.Future -import com.twitter.io.Buf -import io.finch._, items._ -import java.io.File - -object StoreApi { - /** - * Compiles all service endpoints. - * @return Bundled compilation of all service endpoints. - */ - def endpoints(da: DataAccessor) = - deleteOrder(da) :+: - getInventory(da) :+: - getOrderById(da) :+: - placeOrder(da) - - /** - * - * @return And endpoint representing a Unit - */ - private def deleteOrder(da: DataAccessor): Endpoint[Unit] = - delete("store" :: "order" :: string) { (orderId: String) => - da.Store_deleteOrder(orderId) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Map[String, Int] - */ - private def getInventory(da: DataAccessor): Endpoint[Map[String, Int]] = - get("store" :: "inventory") { - Ok(da.Store_getInventory()) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Order - */ - private def getOrderById(da: DataAccessor): Endpoint[Order] = - get("store" :: "order" :: long) { (orderId: Long) => - Ok(da.Store_getOrderById(orderId)) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Order - */ - private def placeOrder(da: DataAccessor): Endpoint[Order] = - post("store" :: "order" :: jsonBody[Order]) { (body: Order) => - Ok(da.Store_placeOrder(body)) - } handle { - case e: Exception => BadRequest(e) - } - - implicit private def fileUploadToFile(fileUpload: FileUpload): File = { - fileUpload match { - case upload: InMemoryFileUpload => - bytesToFile(Buf.ByteArray.Owned.extract(upload.content)) - case upload: OnDiskFileUpload => - upload.content - case _ => null - } - } - - private def bytesToFile(input: Array[Byte]): java.io.File = { - val file = File.createTempFile("tmpStoreApi", null) - val output = new FileOutputStream(file) - output.write(input) - file - } - - // This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere. - implicit def seqList[A](input: Seq[A]): List[A] = input.toList -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala deleted file mode 100644 index 560509a349c..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala +++ /dev/null @@ -1,149 +0,0 @@ -package io.swagger.petstore.apis - -import java.io._ -import java.util.Date -import io.swagger.petstore._ -import io.swagger.petstore.models._ -import io.swagger.petstore.models.User -import scala.collection.immutable.Seq -import io.finch.circe._ -import io.circe.generic.semiauto._ -import com.twitter.concurrent.AsyncStream -import com.twitter.finagle.Service -import com.twitter.finagle.Http -import com.twitter.finagle.http.{ Request, Response } -import com.twitter.finagle.http.exp.Multipart.{ FileUpload, InMemoryFileUpload, OnDiskFileUpload } -import com.twitter.util.Future -import com.twitter.io.Buf -import io.finch._, items._ -import java.io.File - -object UserApi { - /** - * Compiles all service endpoints. - * @return Bundled compilation of all service endpoints. - */ - def endpoints(da: DataAccessor) = - createUser(da) :+: - createUsersWithArrayInput(da) :+: - createUsersWithListInput(da) :+: - deleteUser(da) :+: - getUserByName(da) :+: - loginUser(da) :+: - logoutUser(da) :+: - updateUser(da) - - /** - * - * @return And endpoint representing a Unit - */ - private def createUser(da: DataAccessor): Endpoint[Unit] = - post("user" :: jsonBody[User]) { (body: User) => - da.User_createUser(body) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def createUsersWithArrayInput(da: DataAccessor): Endpoint[Unit] = - post("user" :: "createWithArray" :: jsonBody[Seq[User]]) { (body: Seq[User]) => - da.User_createUsersWithArrayInput(body) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def createUsersWithListInput(da: DataAccessor): Endpoint[Unit] = - post("user" :: "createWithList" :: jsonBody[Seq[User]]) { (body: Seq[User]) => - da.User_createUsersWithListInput(body) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def deleteUser(da: DataAccessor): Endpoint[Unit] = - delete("user" :: string) { (username: String) => - da.User_deleteUser(username) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a User - */ - private def getUserByName(da: DataAccessor): Endpoint[User] = - get("user" :: string) { (username: String) => - Ok(da.User_getUserByName(username)) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a String - */ - private def loginUser(da: DataAccessor): Endpoint[String] = - get("user" :: "login" :: string :: string) { (username: String, password: String) => - Ok(da.User_loginUser(username, password)) - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def logoutUser(da: DataAccessor): Endpoint[Unit] = - get("user" :: "logout") { - da.User_logoutUser() - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - /** - * - * @return And endpoint representing a Unit - */ - private def updateUser(da: DataAccessor): Endpoint[Unit] = - put("user" :: string :: jsonBody[User]) { (username: String, body: User) => - da.User_updateUser(username, body) - NoContent[Unit] - } handle { - case e: Exception => BadRequest(e) - } - - implicit private def fileUploadToFile(fileUpload: FileUpload): File = { - fileUpload match { - case upload: InMemoryFileUpload => - bytesToFile(Buf.ByteArray.Owned.extract(upload.content)) - case upload: OnDiskFileUpload => - upload.content - case _ => null - } - } - - private def bytesToFile(input: Array[Byte]): java.io.File = { - val file = File.createTempFile("tmpUserApi", null) - val output = new FileOutputStream(file) - output.write(input) - file - } - - // This assists in params(string) application (which must be Seq[A] in parameter list) when the param is used as a List[A] elsewhere. - implicit def seqList[A](input: Seq[A]): List[A] = input.toList -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala deleted file mode 100644 index 248833a4e75..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/ApiResponse.scala +++ /dev/null @@ -1,27 +0,0 @@ -package io.swagger.petstore.models - -import io.circe._ -import io.finch.circe._ -import io.circe.generic.semiauto._ -import io.circe.java8.time._ -import io.swagger.petstore._ - -/** - * Describes the result of uploading an image resource - * @param code - * @param _type - * @param message - */ -case class ApiResponse( - code: Option[Int], - _type: Option[String], - message: Option[String] -) - -object ApiResponse { - /** - * Creates the codec for converting ApiResponse from and to JSON. - */ - implicit val decoder: Decoder[ApiResponse] = deriveDecoder - implicit val encoder: ObjectEncoder[ApiResponse] = deriveEncoder -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala deleted file mode 100644 index ceb17f6b7e7..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Category.scala +++ /dev/null @@ -1,25 +0,0 @@ -package io.swagger.petstore.models - -import io.circe._ -import io.finch.circe._ -import io.circe.generic.semiauto._ -import io.circe.java8.time._ -import io.swagger.petstore._ - -/** - * A category for a pet - * @param id - * @param name - */ -case class Category( - id: Option[Long], - name: Option[String] -) - -object Category { - /** - * Creates the codec for converting Category from and to JSON. - */ - implicit val decoder: Decoder[Category] = deriveDecoder - implicit val encoder: ObjectEncoder[Category] = deriveEncoder -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala deleted file mode 100644 index 08743ebbf13..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Order.scala +++ /dev/null @@ -1,34 +0,0 @@ -package io.swagger.petstore.models - -import io.circe._ -import io.finch.circe._ -import io.circe.generic.semiauto._ -import io.circe.java8.time._ -import io.swagger.petstore._ -import java.time.LocalDateTime - -/** - * An order for a pets from the pet store - * @param id - * @param petId - * @param quantity - * @param shipDate - * @param status Order Status - * @param complete - */ -case class Order( - id: Option[Long], - petId: Option[Long], - quantity: Option[Int], - shipDate: Option[LocalDateTime], - status: Option[String], - complete: Option[Boolean] -) - -object Order { - /** - * Creates the codec for converting Order from and to JSON. - */ - implicit val decoder: Decoder[Order] = deriveDecoder - implicit val encoder: ObjectEncoder[Order] = deriveEncoder -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala deleted file mode 100644 index 4a17021b726..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Pet.scala +++ /dev/null @@ -1,36 +0,0 @@ -package io.swagger.petstore.models - -import io.circe._ -import io.finch.circe._ -import io.circe.generic.semiauto._ -import io.circe.java8.time._ -import io.swagger.petstore._ -import io.swagger.petstore.models.Category -import io.swagger.petstore.models.Tag -import scala.collection.immutable.Seq - -/** - * A pet for sale in the pet store - * @param id - * @param category - * @param name - * @param photoUrls - * @param tags - * @param status pet status in the store - */ -case class Pet( - id: Option[Long], - category: Option[Category], - name: String, - photoUrls: Seq[String], - tags: Option[Seq[Tag]], - status: Option[String] -) - -object Pet { - /** - * Creates the codec for converting Pet from and to JSON. - */ - implicit val decoder: Decoder[Pet] = deriveDecoder - implicit val encoder: ObjectEncoder[Pet] = deriveEncoder -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala deleted file mode 100644 index 5fb213c0c3f..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/Tag.scala +++ /dev/null @@ -1,25 +0,0 @@ -package io.swagger.petstore.models - -import io.circe._ -import io.finch.circe._ -import io.circe.generic.semiauto._ -import io.circe.java8.time._ -import io.swagger.petstore._ - -/** - * A tag for a pet - * @param id - * @param name - */ -case class Tag( - id: Option[Long], - name: Option[String] -) - -object Tag { - /** - * Creates the codec for converting Tag from and to JSON. - */ - implicit val decoder: Decoder[Tag] = deriveDecoder - implicit val encoder: ObjectEncoder[Tag] = deriveEncoder -} diff --git a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala b/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala deleted file mode 100644 index 6556cdb437a..00000000000 --- a/samples/server/petstore/finch/src/main/scala/io/swagger/petstore/models/User.scala +++ /dev/null @@ -1,37 +0,0 @@ -package io.swagger.petstore.models - -import io.circe._ -import io.finch.circe._ -import io.circe.generic.semiauto._ -import io.circe.java8.time._ -import io.swagger.petstore._ - -/** - * A User who is purchasing from the pet store - * @param id - * @param username - * @param firstName - * @param lastName - * @param email - * @param password - * @param phone - * @param userStatus User Status - */ -case class User( - id: Option[Long], - username: Option[String], - firstName: Option[String], - lastName: Option[String], - email: Option[String], - password: Option[String], - phone: Option[String], - userStatus: Option[Int] -) - -object User { - /** - * Creates the codec for converting User from and to JSON. - */ - implicit val decoder: Decoder[User] = deriveDecoder - implicit val encoder: ObjectEncoder[User] = deriveEncoder -} From 24474126e1f6c05009b60897b422c9061bfee767 Mon Sep 17 00:00:00 2001 From: Adnan Baruni Date: Tue, 14 Feb 2017 00:20:13 -0600 Subject: [PATCH 010/146] Issue 4742 (#4763) * add boolean datatype flags to CodegenResponse and logic to set them in DefaultCodegen * use Boolean.TRUE.equals to check for isResponseBinary or isResponseFile --- .../io/swagger/codegen/CodegenResponse.java | 1 + .../io/swagger/codegen/DefaultCodegen.java | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java index 52fd5f4f76b..ec0f7f11bb5 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java @@ -10,6 +10,7 @@ public class CodegenResponse { public boolean hasMore; public List> examples; public String dataType, baseType, containerType; + public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBoolean, isDate, isDateTime; public boolean isDefault; public boolean simpleType; public boolean primitiveType; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 9ac1cbba689..d264523e08c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2046,10 +2046,10 @@ public CodegenOperation fromOperation(String path, } r.isDefault = response == methodResponse; op.responses.add(r); - if (r.isBinary && r.isDefault){ + if (Boolean.TRUE.equals(r.isBinary) && Boolean.TRUE.equals(r.isDefault)){ op.isResponseBinary = Boolean.TRUE; } - if (r.isFile && r.isDefault){ + if (Boolean.TRUE.equals(r.isFile) && Boolean.TRUE.equals(r.isDefault)){ op.isResponseFile = Boolean.TRUE; } } @@ -2249,8 +2249,33 @@ public CodegenResponse fromResponse(String responseCode, Response response) { } } r.dataType = cm.datatype; - r.isBinary = isDataTypeBinary(cm.datatype); - r.isFile = isDataTypeFile(cm.datatype); + + if (Boolean.TRUE.equals(cm.isString)) { + r.isString = true; + } else if (Boolean.TRUE.equals(cm.isBoolean)) { + r.isBoolean = true; + } else if (Boolean.TRUE.equals(cm.isLong)) { + r.isLong = true; + } else if (Boolean.TRUE.equals(cm.isInteger)) { + r.isInteger = true; + } else if (Boolean.TRUE.equals(cm.isDouble)) { + r.isDouble = true; + } else if (Boolean.TRUE.equals(cm.isFloat)) { + r.isFloat = true; + } else if (Boolean.TRUE.equals(cm.isByteArray)) { + r.isByteArray = true; + } else if (Boolean.TRUE.equals(cm.isBinary)) { + r.isBinary = true; + } else if (Boolean.TRUE.equals(cm.isFile)) { + r.isFile = true; + } else if (Boolean.TRUE.equals(cm.isDate)) { + r.isDate = true; + } else if (Boolean.TRUE.equals(cm.isDateTime)) { + r.isDateTime = true; + } else { + LOGGER.debug("Property type is not primitive: " + cm.datatype); + } + if (cm.isContainer) { r.simpleType = false; r.containerType = cm.containerType; From 26b1aa2b60105fdced5d6782743019125a3ea014 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 15 Feb 2017 16:24:57 +0800 Subject: [PATCH 011/146] update ts fetch petstore samples --- .../typescript-fetch/builds/default/api.ts | 80 +++++++++---------- .../typescript-fetch/builds/es6-target/api.ts | 80 +++++++++---------- .../builds/with-npm-version/api.ts | 80 +++++++++---------- 3 files changed, 120 insertions(+), 120 deletions(-) diff --git a/samples/client/petstore/typescript-fetch/builds/default/api.ts b/samples/client/petstore/typescript-fetch/builds/default/api.ts index 1e821763c07..1ab5a830727 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/api.ts @@ -102,7 +102,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -131,7 +131,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; fetchOptions.headers = assign({ "api_key": params["apiKey"], }, contentTypeHeader); @@ -153,7 +153,7 @@ export const PetApiFetchParamCreator = { }); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -175,7 +175,7 @@ export const PetApiFetchParamCreator = { }); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -199,7 +199,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -218,7 +218,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "PUT" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -248,7 +248,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; fetchOptions.body = querystring.stringify({ "name": params["name"], @@ -279,7 +279,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; fetchOptions.body = querystring.stringify({ "additionalMetadata": params["additionalMetadata"], @@ -304,7 +304,7 @@ export const PetApiFp = { * * @param body Pet object that needs to be added to the store */ - addPet(params: { "body"?: Pet; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + addPet(params: { "body"?: Pet; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.addPet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -322,7 +322,7 @@ export const PetApiFp = { * @param petId Pet id to delete * @param apiKey */ - deletePet(params: { "petId": number; "apiKey"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deletePet(params: { "petId": number; "apiKey"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.deletePet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -339,7 +339,7 @@ export const PetApiFp = { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - findPetsByStatus(params: { "status"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise> { + findPetsByStatus(params: { "status"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise> { const fetchArgs = PetApiFetchParamCreator.findPetsByStatus(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -356,7 +356,7 @@ export const PetApiFp = { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - findPetsByTags(params: { "tags"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise> { + findPetsByTags(params: { "tags"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise> { const fetchArgs = PetApiFetchParamCreator.findPetsByTags(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -373,7 +373,7 @@ export const PetApiFp = { * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched */ - getPetById(params: { "petId": number; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getPetById(params: { "petId": number; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.getPetById(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -390,7 +390,7 @@ export const PetApiFp = { * * @param body Pet object that needs to be added to the store */ - updatePet(params: { "body"?: Pet; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updatePet(params: { "body"?: Pet; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.updatePet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -409,7 +409,7 @@ export const PetApiFp = { * @param name Updated name of the pet * @param status Updated status of the pet */ - updatePetWithForm(params: { "petId": string; "name"?: string; "status"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updatePetWithForm(params: { "petId": string; "name"?: string; "status"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.updatePetWithForm(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -428,7 +428,7 @@ export const PetApiFp = { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - uploadFile(params: { "petId": number; "additionalMetadata"?: string; "file"?: any; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + uploadFile(params: { "petId": number; "additionalMetadata"?: string; "file"?: any; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.uploadFile(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -614,7 +614,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -632,7 +632,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -656,7 +656,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -675,7 +675,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -699,7 +699,7 @@ export const StoreApiFp = { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - deleteOrder(params: { "orderId": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deleteOrder(params: { "orderId": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.deleteOrder(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -715,7 +715,7 @@ export const StoreApiFp = { * Returns pet inventories by status * Returns a map of status codes to quantities */ - getInventory(options?: any): (fetch: FetchAPI, basePath?: string) => Promise<{ [key: string]: number; }> { + getInventory(options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{ [key: string]: number; }> { const fetchArgs = StoreApiFetchParamCreator.getInventory(options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -732,7 +732,7 @@ export const StoreApiFp = { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - getOrderById(params: { "orderId": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getOrderById(params: { "orderId": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.getOrderById(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -749,7 +749,7 @@ export const StoreApiFp = { * * @param body order placed for purchasing the pet */ - placeOrder(params: { "body"?: Order; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + placeOrder(params: { "body"?: Order; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.placeOrder(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -854,7 +854,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -877,7 +877,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -900,7 +900,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -928,7 +928,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -952,7 +952,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -976,7 +976,7 @@ export const UserApiFetchParamCreator = { }); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -994,7 +994,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -1019,7 +1019,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "PUT" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -1043,7 +1043,7 @@ export const UserApiFp = { * This can only be done by the logged in user. * @param body Created user object */ - createUser(params: { "body"?: User; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUser(params: { "body"?: User; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1060,7 +1060,7 @@ export const UserApiFp = { * * @param body List of user object */ - createUsersWithArrayInput(params: { "body"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUsersWithArrayInput(params: { "body"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUsersWithArrayInput(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1077,7 +1077,7 @@ export const UserApiFp = { * * @param body List of user object */ - createUsersWithListInput(params: { "body"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUsersWithListInput(params: { "body"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUsersWithListInput(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1094,7 +1094,7 @@ export const UserApiFp = { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - deleteUser(params: { "username": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deleteUser(params: { "username": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.deleteUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1111,7 +1111,7 @@ export const UserApiFp = { * * @param username The name that needs to be fetched. Use user1 for testing. */ - getUserByName(params: { "username": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getUserByName(params: { "username": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.getUserByName(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1129,7 +1129,7 @@ export const UserApiFp = { * @param username The user name for login * @param password The password for login in clear text */ - loginUser(params: { "username"?: string; "password"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + loginUser(params: { "username"?: string; "password"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.loginUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1145,7 +1145,7 @@ export const UserApiFp = { * Logs out current logged in user session * */ - logoutUser(options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + logoutUser(options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.logoutUser(options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1163,7 +1163,7 @@ export const UserApiFp = { * @param username name that need to be deleted * @param body Updated user object */ - updateUser(params: { "username": string; "body"?: User; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updateUser(params: { "username": string; "body"?: User; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.updateUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts index c5809c95808..5b787dc84bb 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts @@ -101,7 +101,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -130,7 +130,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; fetchOptions.headers = Object.assign({ "api_key": params["apiKey"], }, contentTypeHeader); @@ -152,7 +152,7 @@ export const PetApiFetchParamCreator = { }); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -174,7 +174,7 @@ export const PetApiFetchParamCreator = { }); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -198,7 +198,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -217,7 +217,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "PUT" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -247,7 +247,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; fetchOptions.body = querystring.stringify({ "name": params["name"], @@ -278,7 +278,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; fetchOptions.body = querystring.stringify({ "additionalMetadata": params["additionalMetadata"], @@ -303,7 +303,7 @@ export const PetApiFp = { * * @param body Pet object that needs to be added to the store */ - addPet(params: { "body"?: Pet; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + addPet(params: { "body"?: Pet; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.addPet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -321,7 +321,7 @@ export const PetApiFp = { * @param petId Pet id to delete * @param apiKey */ - deletePet(params: { "petId": number; "apiKey"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deletePet(params: { "petId": number; "apiKey"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.deletePet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -338,7 +338,7 @@ export const PetApiFp = { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - findPetsByStatus(params: { "status"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise> { + findPetsByStatus(params: { "status"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise> { const fetchArgs = PetApiFetchParamCreator.findPetsByStatus(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -355,7 +355,7 @@ export const PetApiFp = { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - findPetsByTags(params: { "tags"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise> { + findPetsByTags(params: { "tags"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise> { const fetchArgs = PetApiFetchParamCreator.findPetsByTags(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -372,7 +372,7 @@ export const PetApiFp = { * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched */ - getPetById(params: { "petId": number; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getPetById(params: { "petId": number; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.getPetById(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -389,7 +389,7 @@ export const PetApiFp = { * * @param body Pet object that needs to be added to the store */ - updatePet(params: { "body"?: Pet; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updatePet(params: { "body"?: Pet; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.updatePet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -408,7 +408,7 @@ export const PetApiFp = { * @param name Updated name of the pet * @param status Updated status of the pet */ - updatePetWithForm(params: { "petId": string; "name"?: string; "status"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updatePetWithForm(params: { "petId": string; "name"?: string; "status"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.updatePetWithForm(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -427,7 +427,7 @@ export const PetApiFp = { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - uploadFile(params: { "petId": number; "additionalMetadata"?: string; "file"?: any; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + uploadFile(params: { "petId": number; "additionalMetadata"?: string; "file"?: any; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.uploadFile(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -613,7 +613,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -631,7 +631,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -655,7 +655,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -674,7 +674,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -698,7 +698,7 @@ export const StoreApiFp = { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - deleteOrder(params: { "orderId": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deleteOrder(params: { "orderId": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.deleteOrder(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -714,7 +714,7 @@ export const StoreApiFp = { * Returns pet inventories by status * Returns a map of status codes to quantities */ - getInventory(options?: any): (fetch: FetchAPI, basePath?: string) => Promise<{ [key: string]: number; }> { + getInventory(options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{ [key: string]: number; }> { const fetchArgs = StoreApiFetchParamCreator.getInventory(options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -731,7 +731,7 @@ export const StoreApiFp = { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - getOrderById(params: { "orderId": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getOrderById(params: { "orderId": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.getOrderById(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -748,7 +748,7 @@ export const StoreApiFp = { * * @param body order placed for purchasing the pet */ - placeOrder(params: { "body"?: Order; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + placeOrder(params: { "body"?: Order; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.placeOrder(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -853,7 +853,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -876,7 +876,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -899,7 +899,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -927,7 +927,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -951,7 +951,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -975,7 +975,7 @@ export const UserApiFetchParamCreator = { }); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -993,7 +993,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -1018,7 +1018,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = Object.assign({}, { method: "PUT" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -1042,7 +1042,7 @@ export const UserApiFp = { * This can only be done by the logged in user. * @param body Created user object */ - createUser(params: { "body"?: User; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUser(params: { "body"?: User; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1059,7 +1059,7 @@ export const UserApiFp = { * * @param body List of user object */ - createUsersWithArrayInput(params: { "body"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUsersWithArrayInput(params: { "body"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUsersWithArrayInput(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1076,7 +1076,7 @@ export const UserApiFp = { * * @param body List of user object */ - createUsersWithListInput(params: { "body"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUsersWithListInput(params: { "body"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUsersWithListInput(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1093,7 +1093,7 @@ export const UserApiFp = { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - deleteUser(params: { "username": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deleteUser(params: { "username": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.deleteUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1110,7 +1110,7 @@ export const UserApiFp = { * * @param username The name that needs to be fetched. Use user1 for testing. */ - getUserByName(params: { "username": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getUserByName(params: { "username": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.getUserByName(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1128,7 +1128,7 @@ export const UserApiFp = { * @param username The user name for login * @param password The password for login in clear text */ - loginUser(params: { "username"?: string; "password"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + loginUser(params: { "username"?: string; "password"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.loginUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1144,7 +1144,7 @@ export const UserApiFp = { * Logs out current logged in user session * */ - logoutUser(options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + logoutUser(options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.logoutUser(options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1162,7 +1162,7 @@ export const UserApiFp = { * @param username name that need to be deleted * @param body Updated user object */ - updateUser(params: { "username": string; "body"?: User; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updateUser(params: { "username": string; "body"?: User; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.updateUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts index 1e821763c07..1ab5a830727 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts @@ -102,7 +102,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -131,7 +131,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; fetchOptions.headers = assign({ "api_key": params["apiKey"], }, contentTypeHeader); @@ -153,7 +153,7 @@ export const PetApiFetchParamCreator = { }); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -175,7 +175,7 @@ export const PetApiFetchParamCreator = { }); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -199,7 +199,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -218,7 +218,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "PUT" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -248,7 +248,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; fetchOptions.body = querystring.stringify({ "name": params["name"], @@ -279,7 +279,7 @@ export const PetApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; fetchOptions.body = querystring.stringify({ "additionalMetadata": params["additionalMetadata"], @@ -304,7 +304,7 @@ export const PetApiFp = { * * @param body Pet object that needs to be added to the store */ - addPet(params: { "body"?: Pet; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + addPet(params: { "body"?: Pet; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.addPet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -322,7 +322,7 @@ export const PetApiFp = { * @param petId Pet id to delete * @param apiKey */ - deletePet(params: { "petId": number; "apiKey"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deletePet(params: { "petId": number; "apiKey"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.deletePet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -339,7 +339,7 @@ export const PetApiFp = { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - findPetsByStatus(params: { "status"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise> { + findPetsByStatus(params: { "status"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise> { const fetchArgs = PetApiFetchParamCreator.findPetsByStatus(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -356,7 +356,7 @@ export const PetApiFp = { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - findPetsByTags(params: { "tags"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise> { + findPetsByTags(params: { "tags"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise> { const fetchArgs = PetApiFetchParamCreator.findPetsByTags(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -373,7 +373,7 @@ export const PetApiFp = { * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched */ - getPetById(params: { "petId": number; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getPetById(params: { "petId": number; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.getPetById(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -390,7 +390,7 @@ export const PetApiFp = { * * @param body Pet object that needs to be added to the store */ - updatePet(params: { "body"?: Pet; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updatePet(params: { "body"?: Pet; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.updatePet(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -409,7 +409,7 @@ export const PetApiFp = { * @param name Updated name of the pet * @param status Updated status of the pet */ - updatePetWithForm(params: { "petId": string; "name"?: string; "status"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updatePetWithForm(params: { "petId": string; "name"?: string; "status"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.updatePetWithForm(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -428,7 +428,7 @@ export const PetApiFp = { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - uploadFile(params: { "petId": number; "additionalMetadata"?: string; "file"?: any; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + uploadFile(params: { "petId": number; "additionalMetadata"?: string; "file"?: any; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = PetApiFetchParamCreator.uploadFile(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -614,7 +614,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -632,7 +632,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -656,7 +656,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -675,7 +675,7 @@ export const StoreApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -699,7 +699,7 @@ export const StoreApiFp = { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - deleteOrder(params: { "orderId": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deleteOrder(params: { "orderId": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.deleteOrder(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -715,7 +715,7 @@ export const StoreApiFp = { * Returns pet inventories by status * Returns a map of status codes to quantities */ - getInventory(options?: any): (fetch: FetchAPI, basePath?: string) => Promise<{ [key: string]: number; }> { + getInventory(options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{ [key: string]: number; }> { const fetchArgs = StoreApiFetchParamCreator.getInventory(options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -732,7 +732,7 @@ export const StoreApiFp = { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - getOrderById(params: { "orderId": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getOrderById(params: { "orderId": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.getOrderById(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -749,7 +749,7 @@ export const StoreApiFp = { * * @param body order placed for purchasing the pet */ - placeOrder(params: { "body"?: Order; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + placeOrder(params: { "body"?: Order; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = StoreApiFetchParamCreator.placeOrder(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -854,7 +854,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -877,7 +877,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -900,7 +900,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -928,7 +928,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "DELETE" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -952,7 +952,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -976,7 +976,7 @@ export const UserApiFetchParamCreator = { }); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -994,7 +994,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -1019,7 +1019,7 @@ export const UserApiFetchParamCreator = { let urlObj = url.parse(baseUrl, true); let fetchOptions: RequestInit = assign({}, { method: "PUT" }, options); - let contentTypeHeader: Dictionary; + let contentTypeHeader: Dictionary = {}; contentTypeHeader = { "Content-Type": "application/json" }; if (params["body"]) { fetchOptions.body = JSON.stringify(params["body"] || {}); @@ -1043,7 +1043,7 @@ export const UserApiFp = { * This can only be done by the logged in user. * @param body Created user object */ - createUser(params: { "body"?: User; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUser(params: { "body"?: User; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1060,7 +1060,7 @@ export const UserApiFp = { * * @param body List of user object */ - createUsersWithArrayInput(params: { "body"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUsersWithArrayInput(params: { "body"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUsersWithArrayInput(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1077,7 +1077,7 @@ export const UserApiFp = { * * @param body List of user object */ - createUsersWithListInput(params: { "body"?: Array; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + createUsersWithListInput(params: { "body"?: Array; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.createUsersWithListInput(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1094,7 +1094,7 @@ export const UserApiFp = { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - deleteUser(params: { "username": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + deleteUser(params: { "username": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.deleteUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1111,7 +1111,7 @@ export const UserApiFp = { * * @param username The name that needs to be fetched. Use user1 for testing. */ - getUserByName(params: { "username": string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + getUserByName(params: { "username": string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.getUserByName(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1129,7 +1129,7 @@ export const UserApiFp = { * @param username The user name for login * @param password The password for login in clear text */ - loginUser(params: { "username"?: string; "password"?: string; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + loginUser(params: { "username"?: string; "password"?: string; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.loginUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1145,7 +1145,7 @@ export const UserApiFp = { * Logs out current logged in user session * */ - logoutUser(options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + logoutUser(options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.logoutUser(options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { @@ -1163,7 +1163,7 @@ export const UserApiFp = { * @param username name that need to be deleted * @param body Updated user object */ - updateUser(params: { "username": string; "body"?: User; }, options?: any): (fetch: FetchAPI, basePath?: string) => Promise { + updateUser(params: { "username": string; "body"?: User; }, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { const fetchArgs = UserApiFetchParamCreator.updateUser(params, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { From accd1763828f87ac48f8ef7e2a422813662ce5e2 Mon Sep 17 00:00:00 2001 From: Paul English Date: Thu, 16 Feb 2017 02:00:26 -0700 Subject: [PATCH 012/146] Ensure that `ApiInvoker.scala` can support `UUID` types (#4807) --- .../src/main/resources/scala/apiInvoker.mustache | 2 ++ .../scala/src/main/scala/io/swagger/client/ApiInvoker.scala | 2 ++ 2 files changed, 4 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache index 29b3f5ba96f..e1e420d7c6d 100644 --- a/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/scala/apiInvoker.mustache @@ -13,6 +13,7 @@ import com.sun.jersey.multipart.file.FileDataBodyPart import java.io.File import java.net.URLEncoder +import java.util.UUID import javax.ws.rs.core.MediaType import scala.collection.JavaConverters._ @@ -55,6 +56,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, def escape(value: Long): String = value.toString def escape(value: Double): String = value.toString def escape(value: Float): String = value.toString + def escape(value: UUID): String = value.toString def deserialize(json: String, containerType: String, cls: Class[_]) = { if (cls == classOf[String]) { diff --git a/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala b/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala index 3e8b4496287..0db8a5c88e6 100644 --- a/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala +++ b/samples/client/petstore/scala/src/main/scala/io/swagger/client/ApiInvoker.scala @@ -24,6 +24,7 @@ import com.sun.jersey.multipart.file.FileDataBodyPart import java.io.File import java.net.URLEncoder +import java.util.UUID import javax.ws.rs.core.MediaType import scala.collection.JavaConverters._ @@ -66,6 +67,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, def escape(value: Long): String = value.toString def escape(value: Double): String = value.toString def escape(value: Float): String = value.toString + def escape(value: UUID): String = value.toString def deserialize(json: String, containerType: String, cls: Class[_]) = { if (cls == classOf[String]) { From bb81fc130aedd64a4d35232d5173b12ce758e967 Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 16 Feb 2017 17:39:06 +0800 Subject: [PATCH 013/146] remove unused files for nodejs gcf (#4808) --- .../index.mustache | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 modules/swagger-codegen/src/main/resources/nodejs-google-cloud-functions/index.mustache diff --git a/modules/swagger-codegen/src/main/resources/nodejs-google-cloud-functions/index.mustache b/modules/swagger-codegen/src/main/resources/nodejs-google-cloud-functions/index.mustache deleted file mode 100644 index b406ff7f140..00000000000 --- a/modules/swagger-codegen/src/main/resources/nodejs-google-cloud-functions/index.mustache +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -var swaggerTools = require('swagger-tools'); -var jsyaml = require('js-yaml'); -var fs = require('fs'); - -// swaggerRouter configuration -var options = { - controllers: './controllers', - useStubs: false -}; - -// The Swagger document (require it, build it programmatically, fetch it from a URL, ...) -var spec = fs.readFileSync('./api/swagger.yaml', 'utf8'); -var swaggerDoc = jsyaml.safeLoad(spec); - -function toPromise(f, req, res) { - return new Promise(function(resolve, reject) { - f(req, res, function(err) { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }); -} - -exports.{{exportedName}} = function(req, res) { - swaggerTools.initializeMiddleware(swaggerDoc, function(middleware) { - var metadata = middleware.swaggerMetadata(); - var validator = middleware.swaggerValidator(); - var router = middleware.swaggerRouter(options); - req.url = swaggerDoc.basePath + req.url; - toPromise(metadata, req, res).then(function() { - return toPromise(validator, req, res); - }).then(function() { - return toPromise(router, req, res); - }).catch(function(err) { - console.error(err); - res.status(res.statusCode || 400).send(err); - }); - }); -}; From 23d114e1eb183617358da47813846222f5f1a8b1 Mon Sep 17 00:00:00 2001 From: Tristan Sokol Date: Sun, 19 Feb 2017 23:13:06 -0800 Subject: [PATCH 014/146] Fix minor spelling mistake in readme (#4818) --- .../swagger-codegen/src/main/resources/csharp/README.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/csharp/README.mustache b/modules/swagger-codegen/src/main/resources/csharp/README.mustache index 8c08c0e8667..066a7e93577 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/README.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/README.mustache @@ -31,7 +31,7 @@ This C# SDK is automatically generated by the [Swagger Codegen](https://github.c - [RestSharp](https://www.nuget.org/packages/RestSharp) - 105.1.0 or later - [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 7.0.0 or later -The DLLs included in the package may not be the latest version. We recommned using [NuGet] (https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages: +The DLLs included in the package may not be the latest version. We recommend using [NuGet] (https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages: ``` Install-Package RestSharp Install-Package Newtonsoft.Json From 6746632834dad01834829a28b2a6e2ac535b8168 Mon Sep 17 00:00:00 2001 From: jsone-studios Date: Mon, 20 Feb 2017 09:18:09 +0100 Subject: [PATCH 015/146] Fix for #1940 - Show response headers (#4825) --- .../io/swagger/codegen/CodegenResponse.java | 1 + .../io/swagger/codegen/DefaultCodegen.java | 1 + .../main/resources/htmlDocs2/index.mustache | 65 ++- .../resources/2_0/responseHeaderTest.yaml | 41 ++ samples/html2/index.html | 405 +++++++++++++----- 5 files changed, 382 insertions(+), 131 deletions(-) create mode 100644 modules/swagger-codegen/src/test/resources/2_0/responseHeaderTest.yaml diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java index ec0f7f11bb5..b2a734fc9b2 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenResponse.java @@ -10,6 +10,7 @@ public class CodegenResponse { public boolean hasMore; public List> examples; public String dataType, baseType, containerType; + public boolean hasHeaders; public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBoolean, isDate, isDateTime; public boolean isDefault; public boolean simpleType; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index d264523e08c..586a95fefb4 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2231,6 +2231,7 @@ public CodegenResponse fromResponse(String responseCode, Response response) { r.jsonSchema = Json.pretty(response); r.vendorExtensions = response.getVendorExtensions(); addHeaders(response, r.headers); + r.hasHeaders = !r.headers.isEmpty(); if (r.schema != null) { Property responseProperty = response.getSchema(); diff --git a/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache b/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache index 01f9f2eb720..fc0f5f38204 100644 --- a/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache +++ b/modules/swagger-codegen/src/main/resources/htmlDocs2/index.mustache @@ -336,24 +336,30 @@ {{#responses}}

Status: {{code}} - {{message}}

- {{#schema}} -