From c791146b62dd12f5fa97dcb61b87b04b1927273b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 5 May 2018 21:02:18 +0800 Subject: [PATCH] Update Dart petstore with OAS3, fix mustache format (#227) * update dart petstore with oas3, fix mustache format * update default value to null --- bin/openapi3/dart-petstore.sh | 51 +++++++++++++++++++ .../codegen/languages/DartClientCodegen.java | 13 +++-- .../src/main/resources/dart/api.mustache | 18 ++++--- .../src/main/resources/dart/class.mustache | 37 ++++++++++---- .../src/main/resources/dart/model.mustache | 7 ++- .../swagger/.openapi-generator/VERSION | 2 +- .../dart/flutter_petstore/swagger/README.md | 2 +- .../flutter_petstore/swagger/docs/Order.md | 2 +- .../flutter_petstore/swagger/docs/PetApi.md | 8 +-- .../flutter_petstore/swagger/docs/StoreApi.md | 2 +- .../flutter_petstore/swagger/docs/UserApi.md | 8 +-- .../dart/flutter_petstore/swagger/git_push.sh | 2 +- .../swagger/lib/api/pet_api.dart | 38 +++++++------- .../swagger/lib/api/store_api.dart | 20 ++++---- .../swagger/lib/api/user_api.dart | 46 ++++++++--------- .../swagger/lib/model/api_response.dart | 22 +++----- .../swagger/lib/model/category.dart | 18 ++----- .../swagger/lib/model/order.dart | 36 ++++--------- .../swagger/lib/model/pet.dart | 41 ++++----------- .../swagger/lib/model/tag.dart | 18 ++----- .../swagger/lib/model/user.dart | 44 +++++----------- 21 files changed, 214 insertions(+), 221 deletions(-) create mode 100755 bin/openapi3/dart-petstore.sh diff --git a/bin/openapi3/dart-petstore.sh b/bin/openapi3/dart-petstore.sh new file mode 100755 index 00000000000..c7d7fce7692 --- /dev/null +++ b/bin/openapi3/dart-petstore.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +SCRIPT="$0" +echo "# START SCRIPT: $SCRIPT" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" + +# Generate non-browserClient +ags="$@ generate -t modules/openapi-generator/src/main/resources/dart -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger -DhideGenerationTimestamp=true -DbrowserClient=false" + +# then options to generate the library for vm would be: +#ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger_vm -DbrowserClient=false -DpubName=swagger_vm" +#java $JAVA_OPTS -jar $executable $ags + +# Generate browserClient +ags="$@ generate -t modules/openapi-generator/src/main/resources/dart -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger-browser-client -DhideGenerationTimestamp=true -DbrowserClient=true" +#java $JAVA_OPTS -jar $executable $ags + +# Generate non-browserClient and put it to the flutter sample app +ags="$@ generate -t modules/openapi-generator/src/main/resources/dart -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l dart -o samples/client/petstore/dart/flutter_petstore/swagger -DhideGenerationTimestamp=true -DbrowserClient=false" +java $JAVA_OPTS -jar $executable $ags + +# There is a proposal to allow importing different libraries depending on the environment: +# https://github.com/munificent/dep-interface-libraries +# When this is implemented there will only be one library. + +# The current petstore test will then work for both: the browser library and the vm library. + diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java index 6ed1736659a..cc64a74e212 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java @@ -283,13 +283,18 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { } @Override - public String toDefaultValue(Schema p) { - if (ModelUtils.isMapSchema(p)) { + public String toDefaultValue(Schema schema) { + if (ModelUtils.isMapSchema(schema)) { return "{}"; - } else if (ModelUtils.isArraySchema(p)) { + } else if (ModelUtils.isArraySchema(schema)) { return "[]"; } - return super.toDefaultValue(p); + + if (schema.getDefault() != null) { + return schema.getDefault().toString(); + } else { + return "null"; + } } @Override diff --git a/modules/openapi-generator/src/main/resources/dart/api.mustache b/modules/openapi-generator/src/main/resources/dart/api.mustache index c70d88013ba..6ed091fc7ee 100644 --- a/modules/openapi-generator/src/main/resources/dart/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart/api.mustache @@ -40,7 +40,8 @@ class {{classname}} { } {{/required}} {{/queryParams}} - {{#headerParams}}headerParams["{{baseName}}"] = {{paramName}}; + {{#headerParams}} + headerParams["{{baseName}}"] = {{paramName}}; {{/headerParams}} List contentTypes = [{{#consumes}}"{{{mediaType}}}"{{#hasMore}},{{/hasMore}}{{/consumes}}]; @@ -90,20 +91,25 @@ class {{classname}} { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return {{#isListContainer}} - {{#returnType}}(apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList();{{/returnType}} + {{#returnType}} + return (apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList(); + {{/returnType}} {{/isListContainer}} {{^isListContainer}} {{#isMapContainer}} - {{#returnType}}new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')) {{/returnType}}; + {{#returnType}} + return new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')); + {{/returnType}}; {{/isMapContainer}} {{^isMapContainer}} - {{#returnType}}apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}} {{/returnType}}; + {{#returnType}} + return apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}}; + {{/returnType}} {{/isMapContainer}} {{/isListContainer}} } else { - return {{#returnType}}null{{/returnType}}; + return{{#returnType}} null{{/returnType}}; } } {{/operation}} diff --git a/modules/openapi-generator/src/main/resources/dart/class.mustache b/modules/openapi-generator/src/main/resources/dart/class.mustache index 66366a78705..a4115d25c49 100644 --- a/modules/openapi-generator/src/main/resources/dart/class.mustache +++ b/modules/openapi-generator/src/main/resources/dart/class.mustache @@ -1,7 +1,10 @@ class {{classname}} { - {{#vars}}{{#description}}/* {{{description}}} */{{/description}} + {{#vars}} + {{#description}}/* {{{description}}} */{{/description}} {{{datatype}}} {{name}} = {{{defaultValue}}}; - {{#allowableValues}}{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{{/allowableValues}} + {{#allowableValues}} + {{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{ + {{/allowableValues}} {{/vars}} {{classname}}(); @@ -17,20 +20,27 @@ class {{classname}} { {{name}} = json['{{name}}'] == null ? null : DateTime.parse(json['{{name}}']); {{/isDateTime}} {{^isDateTime}} - {{name}} = {{#complexType}} - {{#isListContainer}}{{complexType}}.listFromJson(json['{{name}}']){{/isListContainer}}{{^isListContainer}} - {{#isMapContainer}}{{complexType}}.mapFromJson(json['{{name}}']){{/isMapContainer}} - {{^isMapContainer}}new {{complexType}}.fromJson(json['{{name}}']){{/isMapContainer}}{{/isListContainer}} + {{#isListContainer}} + {{name}} = {{complexType}}.listFromJson(json['{{name}}']); + {{/isListContainer}} + {{^isListContainer}} + {{#isMapContainer}} + {{name}} = {{complexType}}.mapFromJson(json['{{name}}']); + {{/isMapContainer}} + {{^isMapContainer}} + {{name}} = new {{complexType}}.fromJson(json['{{name}}']); + {{/isMapContainer}} + {{/isListContainer}} {{/complexType}} {{^complexType}} {{#isListContainer}} - (json['{{name}}'] as List).map((item) => item as {{items.datatype}}).toList() + {{name}} = (json['{{name}}'] as List).map((item) => item as {{items.datatype}}).toList(); {{/isListContainer}} {{^isListContainer}} - json['{{name}}'] + {{name}} = json['{{name}}']; {{/isListContainer}} - {{/complexType}}; + {{/complexType}} {{/isDateTime}} {{/vars}} } @@ -38,9 +48,14 @@ class {{classname}} { Map toJson() { return { {{#vars}} - {{#isDateTime}}'{{name}}': {{name}} == null ? '' : {{name}}.toUtc().toIso8601String(){{^-last}},{{/-last}}{{/isDateTime}}{{^isDateTime}}'{{name}}': {{name}}{{^-last}},{{/-last}}{{/isDateTime}} + {{#isDateTime}} + '{{name}}': {{name}} == null ? '' : {{name}}.toUtc().toIso8601String(){{^-last}},{{/-last}} + {{/isDateTime}} + {{^isDateTime}} + '{{name}}': {{name}}{{^-last}},{{/-last}} + {{/isDateTime}} {{/vars}} - }; + }; } static List<{{classname}}> listFromJson(List json) { diff --git a/modules/openapi-generator/src/main/resources/dart/model.mustache b/modules/openapi-generator/src/main/resources/dart/model.mustache index 1fa14e179a7..37b030ab034 100644 --- a/modules/openapi-generator/src/main/resources/dart/model.mustache +++ b/modules/openapi-generator/src/main/resources/dart/model.mustache @@ -2,6 +2,11 @@ part of {{pubName}}.api; {{#models}} {{#model}} -{{#isEnum}}{{>enum}}{{/isEnum}}{{^isEnum}}{{>class}}{{/isEnum}} +{{#isEnum}} +{{>enum}} +{{/isEnum}} +{{^isEnum}} +{{>class}} +{{/isEnum}} {{/model}} {{/models}} diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/.openapi-generator/VERSION b/samples/client/petstore/dart/flutter_petstore/swagger/.openapi-generator/VERSION index 855ff9501eb..096bf47efe3 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/.openapi-generator/VERSION +++ b/samples/client/petstore/dart/flutter_petstore/swagger/.openapi-generator/VERSION @@ -1 +1 @@ -2.4.0-SNAPSHOT \ No newline at end of file +3.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/README.md b/samples/client/petstore/dart/flutter_petstore/swagger/README.md index c7cf01ff3e4..9ec33fa98a8 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/README.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/README.md @@ -1,7 +1,7 @@ # swagger This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. -This Dart package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: +This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: 1.0.0 - Build package: org.openapitools.codegen.languages.DartClientCodegen diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/docs/Order.md b/samples/client/petstore/dart/flutter_petstore/swagger/docs/Order.md index c076322a76e..c2ace4ef798 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/docs/Order.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/docs/Order.md @@ -13,7 +13,7 @@ Name | Type | Description | Notes **quantity** | **int** | | [optional] [default to null] **shipDate** | [**DateTime**](DateTime.md) | | [optional] [default to null] **status** | **String** | Order Status | [optional] [default to null] -**complete** | **bool** | | [optional] [default to null] +**complete** | **bool** | | [optional] [default to false] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md b/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md index 98fa465fcb2..cc7825223f4 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md @@ -312,8 +312,8 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **petId** | **int**| ID of pet that needs to be updated | - **name** | **String**| Updated name of the pet | [optional] - **status** | **String**| Updated status of the pet | [optional] + **name** | **String**| Updated name of the pet | [optional] [default to null] + **status** | **String**| Updated status of the pet | [optional] [default to null] ### Return type @@ -359,8 +359,8 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **petId** | **int**| ID of pet to update | - **additionalMetadata** | **String**| Additional data to pass to server | [optional] - **file** | **MultipartFile**| file to upload | [optional] + **additionalMetadata** | **String**| Additional data to pass to server | [optional] [default to null] + **file** | **MultipartFile**| file to upload | [optional] [default to null] ### Return type diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md b/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md index fff0d414bb9..2810cdd910c 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md @@ -179,7 +179,7 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined + - **Content-Type**: application/json - **Accept**: application/xml, application/json [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/docs/UserApi.md b/samples/client/petstore/dart/flutter_petstore/swagger/docs/UserApi.md index 8f593886e44..c3012ea508c 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/docs/UserApi.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/docs/UserApi.md @@ -56,7 +56,7 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined + - **Content-Type**: application/json - **Accept**: Not defined [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) @@ -96,7 +96,7 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined + - **Content-Type**: application/json - **Accept**: Not defined [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) @@ -136,7 +136,7 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined + - **Content-Type**: application/json - **Accept**: Not defined [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) @@ -342,7 +342,7 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined + - **Content-Type**: application/json - **Accept**: Not defined [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/git_push.sh b/samples/client/petstore/dart/flutter_petstore/swagger/git_push.sh index ae01b182ae9..8442b80bb44 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/git_push.sh +++ b/samples/client/petstore/dart/flutter_petstore/swagger/git_push.sh @@ -1,7 +1,7 @@ #!/bin/sh # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" git_user_id=$1 git_repo_id=$2 diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart index 9dc8167e5e1..288836e86a0 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart @@ -25,7 +25,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = ["application/json","application/xml"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -52,9 +52,8 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Deletes a pet @@ -103,9 +102,8 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Finds Pets by status @@ -126,8 +124,8 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - queryParams.addAll(_convertParametersForCollectionFormat("", "status", status)); - + queryParams.addAll(_convertParametersForCollectionFormat("csv", "status", status)); + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -154,7 +152,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'List') as List ; + return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -177,8 +175,8 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - queryParams.addAll(_convertParametersForCollectionFormat("", "tags", tags)); - + queryParams.addAll(_convertParametersForCollectionFormat("csv", "tags", tags)); + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -205,7 +203,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'List') as List ; + return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -228,7 +226,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -255,7 +253,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') as Pet ; + return apiClient.deserialize(response.body, 'Pet') as Pet; } else { return null; } @@ -278,7 +276,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = ["application/json","application/xml"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -305,9 +303,8 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Updates a pet in the store with form data @@ -328,7 +325,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = ["application/x-www-form-urlencoded"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -367,9 +364,8 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// uploads an image @@ -390,7 +386,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = ["multipart/form-data"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -428,7 +424,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse ; + return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse; } else { return null; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart index 9ea2e32c19d..39026fc9898 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart @@ -25,7 +25,7 @@ class StoreApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -52,9 +52,8 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Returns pet inventories by status @@ -72,7 +71,7 @@ class StoreApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -99,7 +98,8 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Map') as Map ; + return new Map.from(apiClient.deserialize(response.body, 'Map')); + ; } else { return null; } @@ -122,7 +122,7 @@ class StoreApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -149,7 +149,7 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order ; + return apiClient.deserialize(response.body, 'Order') as Order; } else { return null; } @@ -172,8 +172,8 @@ class StoreApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - - List contentTypes = []; + + List contentTypes = ["application/json"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; List authNames = []; @@ -199,7 +199,7 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order ; + return apiClient.deserialize(response.body, 'Order') as Order; } else { return null; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart index 13dc2ecdc10..76798563a95 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart @@ -25,8 +25,8 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - - List contentTypes = []; + + List contentTypes = ["application/json"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; List authNames = []; @@ -52,9 +52,8 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Creates list of users with given input array @@ -75,8 +74,8 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - - List contentTypes = []; + + List contentTypes = ["application/json"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; List authNames = []; @@ -102,9 +101,8 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Creates list of users with given input array @@ -125,8 +123,8 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - - List contentTypes = []; + + List contentTypes = ["application/json"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; List authNames = []; @@ -152,9 +150,8 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Delete user @@ -175,7 +172,7 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -202,9 +199,8 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Get user by user name @@ -225,7 +221,7 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -252,7 +248,7 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') as User ; + return apiClient.deserialize(response.body, 'User') as User; } else { return null; } @@ -280,7 +276,7 @@ class UserApi { Map formParams = {}; queryParams.addAll(_convertParametersForCollectionFormat("", "username", username)); queryParams.addAll(_convertParametersForCollectionFormat("", "password", password)); - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -307,7 +303,7 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') as String ; + return apiClient.deserialize(response.body, 'String') as String; } else { return null; } @@ -327,7 +323,7 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - + List contentTypes = []; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; @@ -354,9 +350,8 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } /// Updated user @@ -380,8 +375,8 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - - List contentTypes = []; + + List contentTypes = ["application/json"]; String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; List authNames = []; @@ -407,9 +402,8 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return ; } else { - return ; + return; } } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart index 68ed711118e..be00a0b15df 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart @@ -4,12 +4,9 @@ class ApiResponse { int code = null; - String type = null; - String message = null; - ApiResponse(); @override @@ -19,12 +16,9 @@ class ApiResponse { ApiResponse.fromJson(Map json) { if (json == null) return; - code = - json['code']; - type = - json['type']; - message = - json['message']; + code = json['code']; + type = json['type']; + message = json['message']; } Map toJson() { @@ -32,15 +26,11 @@ class ApiResponse { 'code': code, 'type': type, 'message': message - }; + }; } - static List listFromJson(List> json) { - var list = new List(); - if (json != null && json.length > 0) { - json.forEach((Map value) => list.add(new ApiResponse.fromJson(value))); - } - return list; + static List listFromJson(List json) { + return json == null ? new List() : json.map((value) => new ApiResponse.fromJson(value)).toList(); } static Map mapFromJson(Map> json) { diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart index 29855232387..7975849f91d 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart @@ -4,9 +4,7 @@ class Category { int id = null; - String name = null; - Category(); @override @@ -16,25 +14,19 @@ class Category { Category.fromJson(Map json) { if (json == null) return; - id = - json['id']; - name = - json['name']; + id = json['id']; + name = json['name']; } Map toJson() { return { 'id': id, 'name': name - }; + }; } - static List listFromJson(List> json) { - var list = new List(); - if (json != null && json.length > 0) { - json.forEach((Map value) => list.add(new Category.fromJson(value))); - } - return list; + static List listFromJson(List json) { + return json == null ? new List() : json.map((value) => new Category.fromJson(value)).toList(); } static Map mapFromJson(Map> json) { diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart index 852e9e62738..2084e2abb4b 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart @@ -4,21 +4,16 @@ class Order { int id = null; - int petId = null; - int quantity = null; - DateTime shipDate = null; - -/* Order Status */ + /* Order Status */ String status = null; - //enum statusEnum { placed, approved, delivered, }; - - bool complete = null; + //enum statusEnum { placed, approved, delivered, };{ + bool complete = false; Order(); @override @@ -28,17 +23,12 @@ class Order { Order.fromJson(Map json) { if (json == null) return; - id = - json['id']; - petId = - json['petId']; - quantity = - json['quantity']; + id = json['id']; + petId = json['petId']; + quantity = json['quantity']; shipDate = json['shipDate'] == null ? null : DateTime.parse(json['shipDate']); - status = - json['status']; - complete = - json['complete']; + status = json['status']; + complete = json['complete']; } Map toJson() { @@ -49,15 +39,11 @@ class Order { 'shipDate': shipDate == null ? '' : shipDate.toUtc().toIso8601String(), 'status': status, 'complete': complete - }; + }; } - static List listFromJson(List> json) { - var list = new List(); - if (json != null && json.length > 0) { - json.forEach((Map value) => list.add(new Order.fromJson(value))); - } - return list; + static List listFromJson(List json) { + return json == null ? new List() : json.map((value) => new Order.fromJson(value)).toList(); } static Map mapFromJson(Map> json) { diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart index 85d231848fd..6bd04ecbf1a 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart @@ -4,21 +4,16 @@ class Pet { int id = null; - Category category = null; - String name = null; - List photoUrls = []; - List tags = []; - -/* pet status in the store */ + /* pet status in the store */ String status = null; - //enum statusEnum { available, pending, sold, }; + //enum statusEnum { available, pending, sold, };{ Pet(); @override @@ -28,22 +23,12 @@ class Pet { Pet.fromJson(Map json) { if (json == null) return; - id = - json['id']; - category = - - - new Category.fromJson(json['category']) - ; - name = - json['name']; - photoUrls = - json['photoUrls']; - tags = - Tag.listFromJson(json['tags']) - ; - status = - json['status']; + id = json['id']; + category = new Category.fromJson(json['category']); + name = json['name']; + photoUrls = (json['photoUrls'] as List).map((item) => item as String).toList(); + tags = Tag.listFromJson(json['tags']); + status = json['status']; } Map toJson() { @@ -54,15 +39,11 @@ class Pet { 'photoUrls': photoUrls, 'tags': tags, 'status': status - }; + }; } - static List listFromJson(List> json) { - var list = new List(); - if (json != null && json.length > 0) { - json.forEach((Map value) => list.add(new Pet.fromJson(value))); - } - return list; + static List listFromJson(List json) { + return json == null ? new List() : json.map((value) => new Pet.fromJson(value)).toList(); } static Map mapFromJson(Map> json) { diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart index ed2828f9069..06a042eec01 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart @@ -4,9 +4,7 @@ class Tag { int id = null; - String name = null; - Tag(); @override @@ -16,25 +14,19 @@ class Tag { Tag.fromJson(Map json) { if (json == null) return; - id = - json['id']; - name = - json['name']; + id = json['id']; + name = json['name']; } Map toJson() { return { 'id': id, 'name': name - }; + }; } - static List listFromJson(List> json) { - var list = new List(); - if (json != null && json.length > 0) { - json.forEach((Map value) => list.add(new Tag.fromJson(value))); - } - return list; + static List listFromJson(List json) { + return json == null ? new List() : json.map((value) => new Tag.fromJson(value)).toList(); } static Map mapFromJson(Map> json) { diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart index a4d049b97e7..47c7453f698 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart @@ -4,27 +4,19 @@ class User { int id = null; - String username = null; - String firstName = null; - String lastName = null; - String email = null; - String password = null; - String phone = null; - -/* User Status */ + /* User Status */ int userStatus = null; - User(); @override @@ -34,22 +26,14 @@ class User { User.fromJson(Map json) { if (json == null) return; - id = - json['id']; - username = - json['username']; - firstName = - json['firstName']; - lastName = - json['lastName']; - email = - json['email']; - password = - json['password']; - phone = - json['phone']; - userStatus = - json['userStatus']; + id = json['id']; + username = json['username']; + firstName = json['firstName']; + lastName = json['lastName']; + email = json['email']; + password = json['password']; + phone = json['phone']; + userStatus = json['userStatus']; } Map toJson() { @@ -62,15 +46,11 @@ class User { 'password': password, 'phone': phone, 'userStatus': userStatus - }; + }; } - static List listFromJson(List> json) { - var list = new List(); - if (json != null && json.length > 0) { - json.forEach((Map value) => list.add(new User.fromJson(value))); - } - return list; + static List listFromJson(List json) { + return json == null ? new List() : json.map((value) => new User.fromJson(value)).toList(); } static Map mapFromJson(Map> json) {