From d40cbf9dbd69651c6aa273e0797fc6e3eadd0fbc Mon Sep 17 00:00:00 2001 From: Jaumard Date: Thu, 6 Dec 2018 11:34:01 +0100 Subject: [PATCH] add default timeout to calls (#1596) add properties to send or not null values update deps --- .../languages/DartJaguarClientCodegen.java | 13 ++ .../main/resources/dart-jaguar/api.mustache | 38 ++++- .../resources/dart-jaguar/apilib.mustache | 9 +- .../main/resources/dart-jaguar/class.mustache | 6 +- .../resources/dart-jaguar/pubspec.mustache | 10 +- .../flutter_petstore/openapi/README.md | 2 +- .../flutter_petstore/openapi/lib/api.dart | 147 +++++++++--------- .../openapi/lib/api/pet_api.dart | 91 ++++++++--- .../openapi/lib/api/store_api.dart | 33 +++- .../openapi/lib/api/user_api.dart | 78 ++++++++-- .../openapi/lib/model/api_response.dart | 24 ++- .../openapi/lib/model/category.dart | 21 ++- .../openapi/lib/model/order.dart | 34 ++-- .../openapi/lib/model/pet.dart | 35 +++-- .../openapi/lib/model/tag.dart | 20 ++- .../openapi/lib/model/user.dart | 44 ++++-- .../flutter_petstore/openapi/pubspec.yaml | 10 +- .../petstore/dart-jaguar/openapi/README.md | 2 +- .../petstore/dart-jaguar/openapi/lib/api.dart | 147 +++++++++--------- .../dart-jaguar/openapi/lib/api/pet_api.dart | 91 ++++++++--- .../openapi/lib/api/store_api.dart | 33 +++- .../dart-jaguar/openapi/lib/api/user_api.dart | 78 ++++++++-- .../openapi/lib/model/api_response.dart | 24 ++- .../openapi/lib/model/category.dart | 21 ++- .../dart-jaguar/openapi/lib/model/order.dart | 34 ++-- .../dart-jaguar/openapi/lib/model/pet.dart | 35 +++-- .../dart-jaguar/openapi/lib/model/tag.dart | 20 ++- .../dart-jaguar/openapi/lib/model/user.dart | 44 ++++-- .../petstore/dart-jaguar/openapi/pubspec.yaml | 10 +- 29 files changed, 785 insertions(+), 369 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java index 0a2d3444771..4e82fc4a9b4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java @@ -16,6 +16,7 @@ package org.openapitools.codegen.languages; +import org.openapitools.codegen.CliOption; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; @@ -36,6 +37,7 @@ import java.util.Set; import static org.openapitools.codegen.utils.StringUtils.underscore; public class DartJaguarClientCodegen extends DartClientCodegen { + private static final String NULLABLE_FIELDS = "nullableFields"; private static Set modelToIgnore = new HashSet<>(); static { @@ -45,11 +47,15 @@ public class DartJaguarClientCodegen extends DartClientCodegen { modelToIgnore.add("file"); } + private boolean nullableFields = true; + public DartJaguarClientCodegen() { super(); browserClient = false; outputFolder = "generated-code/dart-jaguar"; embeddedTemplateDir = templateDir = "dart-jaguar"; + + cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload")); } @Override @@ -74,6 +80,13 @@ public class DartJaguarClientCodegen extends DartClientCodegen { @Override public void processOpts() { + if (additionalProperties.containsKey(NULLABLE_FIELDS)) { + nullableFields = convertPropertyToBooleanAndWriteBack(NULLABLE_FIELDS); + } else { + //not set, use to be passed to template + additionalProperties.put(NULLABLE_FIELDS, nullableFields); + } + if (additionalProperties.containsKey(PUB_NAME)) { this.setPubName((String) additionalProperties.get(PUB_NAME)); } else { diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/api.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/api.mustache index 762cb6a0fb1..34c6f4cb8c6 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/api.mustache @@ -15,8 +15,9 @@ part '{{classFilename}}.jretro.dart'; class {{classname}} extends _${{classname}}Client implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - {{classname}}({this.base, this.serializers}); + {{classname}}({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); {{#operation}} /// {{summary}} @@ -29,23 +30,46 @@ class {{classname}} extends _${{classname}}Client implements ApiClient { {{/pathParams}} {{#headerParams}} {{#-first}}{{#hasPathParams}},{{/hasPathParams}}{{/-first}} - @Header("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} + @Header("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} {{/headerParams}} {{#queryParams}} {{#-first}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/-first}} - @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} + @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} {{/queryParams}} {{#vendorExtensions}} + {{#formParams}} + {{#-first}}{{#hasQueryParams}},{{/hasQueryParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/-first}} + {{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsFormField() {{/isForm}}{{#isMultipart}}@AsMultipartField() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} + {{/formParams}} + {{#bodyParam}} + {{#hasFormParams}},{{/hasFormParams}}{{^hasFormParams}}{{#hasQueryParams}},{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}} + {{^isJson}}{{^isForm}}{{^isMultipart}}@AsBody(){{/isMultipart}}{{/isForm}}{{/isJson}} {{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsForm() {{/isForm}}{{#isMultipart}}@AsMultipart() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} + {{/bodyParam}} + {{/vendorExtensions}} + ) { + return super.{{nickname}}( + {{#pathParams}} + {{paramName}}{{#hasMore}}, {{/hasMore}} + {{/pathParams}} + {{#headerParams}} + {{#-first}}{{#hasPathParams}},{{/hasPathParams}}{{/-first}} + {{paramName}}{{#hasMore}}, {{/hasMore}} + {{/headerParams}} + {{#queryParams}} + {{#-first}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/-first}} + {{paramName}}{{#hasMore}}, {{/hasMore}} + {{/queryParams}} + {{#formParams}} {{#-first}}{{#hasQueryParams}},{{/hasQueryParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/-first}} - {{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsFormField() {{/isForm}}{{#isMultipart}}@AsMultipartField() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} + {{paramName}}{{#hasMore}}, {{/hasMore}} {{/formParams}} {{#bodyParam}} {{#hasFormParams}},{{/hasFormParams}}{{^hasFormParams}}{{#hasQueryParams}},{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}} - {{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsForm() {{/isForm}}{{#isMultipart}}@AsMultipart() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}} + {{paramName}}{{#hasMore}}, {{/hasMore}} {{/bodyParam}} - {{/vendorExtensions}} - ); + ).timeout(timeout); + } {{/operation}} diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache index 71cfe8618a2..d4f32de82d9 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache @@ -1,6 +1,6 @@ library {{pubName}}.api; -import 'package:http/http.dart'; +import 'package:http/io_client.dart'; import 'package:jaguar_serializer/jaguar_serializer.dart'; import 'package:jaguar_retrofit/jaguar_retrofit.dart'; import 'package:{{pubName}}/auth/api_key_auth.dart'; @@ -22,11 +22,12 @@ class JaguarApiGen { List interceptors; String basePath = "{{basePath}}"; Route _baseRoute; + final Duration timeout; /** * Add custom global interceptors, put overrideInterceptors to true to set your interceptors only (auth interceptors will not be added) */ - JaguarApiGen({List interceptors, bool overrideInterceptors = false, String baseUrl}) { + JaguarApiGen({List interceptors, bool overrideInterceptors = false, String baseUrl, this.timeout = const Duration(minutes: 2)}) { _baseRoute = Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient()); if(interceptors == null) { this.interceptors = _defaultInterceptors; @@ -68,8 +69,8 @@ class JaguarApiGen { if(serializers == null) { serializers = jsonJaguarRepo; } - return {{classname}}(base: base, serializers: serializers); + return {{classname}}(base: base, serializers: serializers, timeout: timeout); } {{/apis}}{{/apiInfo}} -} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache index f4a1731a5f3..dfb5cbd88ba 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache @@ -2,12 +2,12 @@ part '{{classFilename}}.jser.dart'; class {{classname}} { {{#vars}}{{#description}} /* {{{description}}} */{{/description}} - @Alias('{{{baseName}}}') + @Alias('{{baseName}}') final {{{datatype}}} {{name}}; {{#allowableValues}}{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{{/allowableValues}}{{/vars}} {{classname}}( - {{#vars}}{{^defaultValue}}{{#required}} this.{{name}}, {{/required}}{{/defaultValue}}{{/vars}} + {{#vars}}{{^defaultValue}}{{#required}} this.{{name}}, {{/required}}{{/defaultValue}}{{/vars}} {{#vendorExtensions}}{{#hasVars}}{ {{#vars}}{{^required}} this.{{name}}{{#defaultValue}} = {{{defaultValue}}}{{#hasMore}}, {{/hasMore}} {{/defaultValue}}{{/required}} @@ -21,7 +21,7 @@ class {{classname}} { } } -@GenSerializer() +@GenSerializer(nullableFields: {{nullableFields}}) class {{classname}}Serializer extends Serializer<{{classname}}> with _${{classname}}Serializer { } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/dart-jaguar/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart-jaguar/pubspec.mustache index 30bdbdc28e5..d619bc2d570 100644 --- a/modules/openapi-generator/src/main/resources/dart-jaguar/pubspec.mustache +++ b/modules/openapi-generator/src/main/resources/dart-jaguar/pubspec.mustache @@ -4,9 +4,9 @@ description: {{pubDescription}} environment: sdk: ">=2.0.0 <3.0.0" dependencies: - jaguar_retrofit: '^2.5.4' - jaguar_serializer: '^2.2.2' + jaguar_retrofit: '^2.5.12' + jaguar_serializer: '^2.2.4' dev_dependencies: - jaguar_retrofit_gen: '^2.5.2' - jaguar_serializer_cli: '^2.2.1' - build_runner: '^0.10.0' \ No newline at end of file + jaguar_retrofit_gen: '^2.5.10' + jaguar_serializer_cli: '^2.2.4' + build_runner: '^1.1.1' \ No newline at end of file diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/README.md b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/README.md index 4e85ae7a928..39cc83147de 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/README.md +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/README.md @@ -4,7 +4,7 @@ This is a sample server Petstore server. For this sample, you can use the api ke This Dart package is automatically generated by the [Open API Codegen](https://github.com/OpenAPITools/openapi-generator) project: - API version: 1.0.0 -- Build date: 2018-10-08T15:27:22.304+08:00[Asia/Hong_Kong] +- Build date: 2018-12-02T16:16:44.701611+01:00[Europe/Paris] - Build package: org.openapitools.codegen.languages.DartJaguarClientCodegen ## Requirements diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api.dart index e1aa03d6840..8add80e7ec1 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api.dart @@ -1,6 +1,6 @@ library openapi.api; -import 'package:http/http.dart'; +import 'package:http/io_client.dart'; import 'package:jaguar_serializer/jaguar_serializer.dart'; import 'package:jaguar_retrofit/jaguar_retrofit.dart'; import 'package:openapi/auth/api_key_auth.dart'; @@ -18,100 +18,101 @@ import 'package:openapi/model/pet.dart'; import 'package:openapi/model/tag.dart'; import 'package:openapi/model/user.dart'; -final jsonJaguarRepo = JsonRepo() - ..add(ApiResponseSerializer()) - ..add(CategorySerializer()) - ..add(OrderSerializer()) - ..add(PetSerializer()) - ..add(TagSerializer()) - ..add(UserSerializer()); -final _defaultInterceptors = [ - OAuthInterceptor(), - BasicAuthInterceptor(), - ApiKeyAuthInterceptor() -]; +final jsonJaguarRepo = JsonRepo() +..add(ApiResponseSerializer()) +..add(CategorySerializer()) +..add(OrderSerializer()) +..add(PetSerializer()) +..add(TagSerializer()) +..add(UserSerializer()) +; + +final _defaultInterceptors = [OAuthInterceptor(), BasicAuthInterceptor(), ApiKeyAuthInterceptor()]; class JaguarApiGen { - List interceptors; - String basePath = "http://petstore.swagger.io/v2"; - Route _baseRoute; + List interceptors; + String basePath = "http://petstore.swagger.io/v2"; + Route _baseRoute; + final Duration timeout; - /** + /** * Add custom global interceptors, put overrideInterceptors to true to set your interceptors only (auth interceptors will not be added) */ - JaguarApiGen( - {List interceptors, - bool overrideInterceptors = false, - String baseUrl}) { - _baseRoute = - Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient()); - if (interceptors == null) { - this.interceptors = _defaultInterceptors; - } else if (overrideInterceptors) { - this.interceptors = interceptors; - } else { - this.interceptors = List.from(_defaultInterceptors)..addAll(interceptors); + JaguarApiGen({List interceptors, bool overrideInterceptors = false, String baseUrl, this.timeout = const Duration(minutes: 2)}) { + _baseRoute = Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient()); + if(interceptors == null) { + this.interceptors = _defaultInterceptors; + } + else if(overrideInterceptors){ + this.interceptors = interceptors; + } + else { + this.interceptors = List.from(_defaultInterceptors)..addAll(interceptors); + } + + this.interceptors.forEach((interceptor) { + _baseRoute.before(interceptor.before); + _baseRoute.after(interceptor.after); + }); } - this.interceptors.forEach((interceptor) { - _baseRoute.before(interceptor.before); - _baseRoute.after(interceptor.after); - }); - } + void setOAuthToken(String name, String token) { + (_defaultInterceptors[0] as OAuthInterceptor).tokens[name] = token; + } - void setOAuthToken(String name, String token) { - (_defaultInterceptors[0] as OAuthInterceptor).tokens[name] = token; - } + void setBasicAuth(String name, String username, String password) { + (_defaultInterceptors[1] as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password); + } - void setBasicAuth(String name, String username, String password) { - (_defaultInterceptors[1] as BasicAuthInterceptor).authInfo[name] = - BasicAuthInfo(username, password); - } + void setApiKey(String name, String apiKey) { + (_defaultInterceptors[2] as ApiKeyAuthInterceptor).apiKeys[name] = apiKey; + } - void setApiKey(String name, String apiKey) { - (_defaultInterceptors[2] as ApiKeyAuthInterceptor).apiKeys[name] = apiKey; - } - - /** + + /** * Get PetApi instance, base route and serializer can be overridden by a given but be careful, * by doing that all interceptors will not be executed */ - PetApi getPetApi({Route base, SerializerRepo serializers}) { - if (base == null) { - base = _baseRoute; + PetApi getPetApi({Route base, SerializerRepo serializers}) { + if(base == null) { + base = _baseRoute; + } + if(serializers == null) { + serializers = jsonJaguarRepo; + } + return PetApi(base: base, serializers: serializers, timeout: timeout); } - if (serializers == null) { - serializers = jsonJaguarRepo; - } - return PetApi(base: base, serializers: serializers); - } - /** + + /** * Get StoreApi instance, base route and serializer can be overridden by a given but be careful, * by doing that all interceptors will not be executed */ - StoreApi getStoreApi({Route base, SerializerRepo serializers}) { - if (base == null) { - base = _baseRoute; + StoreApi getStoreApi({Route base, SerializerRepo serializers}) { + if(base == null) { + base = _baseRoute; + } + if(serializers == null) { + serializers = jsonJaguarRepo; + } + return StoreApi(base: base, serializers: serializers, timeout: timeout); } - if (serializers == null) { - serializers = jsonJaguarRepo; - } - return StoreApi(base: base, serializers: serializers); - } - /** + + /** * Get UserApi instance, base route and serializer can be overridden by a given but be careful, * by doing that all interceptors will not be executed */ - UserApi getUserApi({Route base, SerializerRepo serializers}) { - if (base == null) { - base = _baseRoute; + UserApi getUserApi({Route base, SerializerRepo serializers}) { + if(base == null) { + base = _baseRoute; + } + if(serializers == null) { + serializers = jsonJaguarRepo; + } + return UserApi(base: base, serializers: serializers, timeout: timeout); } - if (serializers == null) { - serializers = jsonJaguarRepo; - } - return UserApi(base: base, serializers: serializers); - } -} + + +} \ No newline at end of file diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/pet_api.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/pet_api.dart index ae5f7e9c158..0c7270125dc 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/pet_api.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/pet_api.dart @@ -14,17 +14,24 @@ part 'pet_api.jretro.dart'; class PetApi extends _$PetApiClient implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - PetApi({this.base, this.serializers}); + PetApi({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); /// Add a new pet to the store /// /// @PostReq(path: "/pet", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future addPet( + + @AsJson() Pet pet + ) { + return super.addPet( + - @AsJson() Pet pet - ); + pet + ).timeout(timeout); + } /// Deletes a pet /// @@ -33,8 +40,15 @@ class PetApi extends _$PetApiClient implements ApiClient { Future deletePet( @PathParam("petId") int petId , - @Header("api_key") String apiKey - ); + @Header("api_key") String apiKey + ) { + return super.deletePet( + petId + , + apiKey + + ).timeout(timeout); + } /// Finds Pets by status /// @@ -42,8 +56,14 @@ class PetApi extends _$PetApiClient implements ApiClient { @GetReq(path: "/pet/findByStatus", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future> findPetsByStatus( - @QueryParam("status") List status - ); + @QueryParam("status") List status + ) { + return super.findPetsByStatus( + + status + + ).timeout(timeout); + } /// Finds Pets by tags /// @@ -51,8 +71,14 @@ class PetApi extends _$PetApiClient implements ApiClient { @GetReq(path: "/pet/findByTags", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future> findPetsByTags( - @QueryParam("tags") List tags - ); + @QueryParam("tags") List tags + ) { + return super.findPetsByTags( + + tags + + ).timeout(timeout); + } /// Find pet by ID /// @@ -60,16 +86,27 @@ class PetApi extends _$PetApiClient implements ApiClient { @GetReq(path: "/pet/:petId", metadata: {"auth": [ {"type": "apiKey", "name": "api_key", "keyName": "api_key", "where": "header" }]}) Future getPetById( @PathParam("petId") int petId - ); + ) { + return super.getPetById( + petId + + ).timeout(timeout); + } /// Update an existing pet /// /// @PutReq(path: "/pet", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future updatePet( + + @AsJson() Pet pet + ) { + return super.updatePet( + - @AsJson() Pet pet - ); + pet + ).timeout(timeout); + } /// Updates a pet in the store with form data /// @@ -77,11 +114,20 @@ class PetApi extends _$PetApiClient implements ApiClient { @PostReq(path: "/pet/:petId", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future updatePetWithForm( @PathParam("petId") int petId + , + @AsFormField() String name, + + @AsFormField() String status + ) { + return super.updatePetWithForm( + petId + , - @AsFormField() String name, + name, - @AsFormField() String status - ); + status + ).timeout(timeout); + } /// uploads an image /// @@ -89,11 +135,20 @@ class PetApi extends _$PetApiClient implements ApiClient { @PostReq(path: "/pet/:petId/uploadImage", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future uploadFile( @PathParam("petId") int petId + , + @AsMultipartField() String additionalMetadata, + + @AsMultipartField() MultipartFile file + ) { + return super.uploadFile( + petId + , - @AsMultipartField() String additionalMetadata, + additionalMetadata, - @AsMultipartField() MultipartFile file - ); + file + ).timeout(timeout); + } } diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/store_api.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/store_api.dart index b0e40104275..816a3f91425 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/store_api.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/store_api.dart @@ -13,8 +13,9 @@ part 'store_api.jretro.dart'; class StoreApi extends _$StoreApiClient implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - StoreApi({this.base, this.serializers}); + StoreApi({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); /// Delete purchase order by ID /// @@ -22,14 +23,23 @@ class StoreApi extends _$StoreApiClient implements ApiClient { @DeleteReq(path: "/store/order/:orderId") Future deleteOrder( @PathParam("orderId") String orderId - ); + ) { + return super.deleteOrder( + orderId + + ).timeout(timeout); + } /// Returns pet inventories by status /// /// Returns a map of status codes to quantities @GetReq(path: "/store/inventory", metadata: {"auth": [ {"type": "apiKey", "name": "api_key", "keyName": "api_key", "where": "header" }]}) Future> getInventory( - ); + ) { + return super.getInventory( + + ).timeout(timeout); + } /// Find purchase order by ID /// @@ -37,16 +47,27 @@ class StoreApi extends _$StoreApiClient implements ApiClient { @GetReq(path: "/store/order/:orderId") Future getOrderById( @PathParam("orderId") int orderId - ); + ) { + return super.getOrderById( + orderId + + ).timeout(timeout); + } /// Place an order for a pet /// /// @PostReq(path: "/store/order") Future placeOrder( + + @AsJson() Order order + ) { + return super.placeOrder( + - @AsJson() Order order - ); + order + ).timeout(timeout); + } } diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/user_api.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/user_api.dart index 337375075c2..f6469066799 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/user_api.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/user_api.dart @@ -13,35 +13,54 @@ part 'user_api.jretro.dart'; class UserApi extends _$UserApiClient implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - UserApi({this.base, this.serializers}); + UserApi({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); /// Create user /// /// This can only be done by the logged in user. @PostReq(path: "/user") Future createUser( + + @AsJson() User user + ) { + return super.createUser( + - @AsJson() User user - ); + user + ).timeout(timeout); + } /// Creates list of users with given input array /// /// @PostReq(path: "/user/createWithArray") Future createUsersWithArrayInput( + + @AsJson() List user + ) { + return super.createUsersWithArrayInput( + - @AsJson() List user - ); + user + ).timeout(timeout); + } /// Creates list of users with given input array /// /// @PostReq(path: "/user/createWithList") Future createUsersWithListInput( + + @AsJson() List user + ) { + return super.createUsersWithListInput( + - @AsJson() List user - ); + user + ).timeout(timeout); + } /// Delete user /// @@ -49,7 +68,12 @@ class UserApi extends _$UserApiClient implements ApiClient { @DeleteReq(path: "/user/:username") Future deleteUser( @PathParam("username") String username - ); + ) { + return super.deleteUser( + username + + ).timeout(timeout); + } /// Get user by user name /// @@ -57,7 +81,12 @@ class UserApi extends _$UserApiClient implements ApiClient { @GetReq(path: "/user/:username") Future getUserByName( @PathParam("username") String username - ); + ) { + return super.getUserByName( + username + + ).timeout(timeout); + } /// Logs user into the system /// @@ -65,17 +94,29 @@ class UserApi extends _$UserApiClient implements ApiClient { @GetReq(path: "/user/login") Future loginUser( - @QueryParam("username") String username, + @QueryParam("username") String username, - @QueryParam("password") String password - ); + @QueryParam("password") String password + ) { + return super.loginUser( + + username, + + password + + ).timeout(timeout); + } /// Logs out current logged in user session /// /// @GetReq(path: "/user/logout") Future logoutUser( - ); + ) { + return super.logoutUser( + + ).timeout(timeout); + } /// Updated user /// @@ -83,9 +124,16 @@ class UserApi extends _$UserApiClient implements ApiClient { @PutReq(path: "/user/:username") Future updateUser( @PathParam("username") String username + , + @AsJson() User user + ) { + return super.updateUser( + username + , - @AsJson() User user - ); + user + ).timeout(timeout); + } } diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart index d0709e397a3..dbbc7582062 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart @@ -3,16 +3,27 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'api_response.jser.dart'; class ApiResponse { + @Alias('code') final int code; - + @Alias('type') final String type; - + @Alias('message') final String message; + - ApiResponse({this.code = null, this.type = null, this.message = null}); + ApiResponse( + + +{ + this.code = null, + this.type = null, + this.message = null + + } + ); @override String toString() { @@ -20,6 +31,7 @@ class ApiResponse { } } -@GenSerializer() -class ApiResponseSerializer extends Serializer - with _$ApiResponseSerializer {} +@GenSerializer(nullableFields: true) +class ApiResponseSerializer extends Serializer with _$ApiResponseSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart index 0462782e68c..2a02961072f 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart @@ -3,13 +3,23 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'category.jser.dart'; class Category { + @Alias('id') final int id; - + @Alias('name') final String name; + - Category({this.id = null, this.name = null}); + Category( + + +{ + this.id = null, + this.name = null + + } + ); @override String toString() { @@ -17,6 +27,7 @@ class Category { } } -@GenSerializer() -class CategorySerializer extends Serializer - with _$CategorySerializer {} +@GenSerializer(nullableFields: true) +class CategorySerializer extends Serializer with _$CategorySerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart index ccf82bb5d8d..3086347338a 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart @@ -3,31 +3,39 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'order.jser.dart'; class Order { + @Alias('id') final int id; - + @Alias('petId') final int petId; - + @Alias('quantity') final int quantity; - + @Alias('shipDate') final DateTime shipDate; - /* Order Status */ + /* Order Status */ @Alias('status') final String status; //enum statusEnum { placed, approved, delivered, }; @Alias('complete') final bool complete; + Order( - {this.id = null, - this.petId = null, - this.quantity = null, - this.shipDate = null, - this.status = null, - this.complete = false}); + + +{ + this.id = null, + this.petId = null, + this.quantity = null, + this.shipDate = null, + this.status = null, + this.complete = false + + } + ); @override String toString() { @@ -35,5 +43,7 @@ class Order { } } -@GenSerializer() -class OrderSerializer extends Serializer with _$OrderSerializer {} +@GenSerializer(nullableFields: true) +class OrderSerializer extends Serializer with _$OrderSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart index eaf4dac08d6..b487e6ba032 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart @@ -5,32 +5,39 @@ import 'package:openapi/model/category.dart'; part 'pet.jser.dart'; class Pet { + @Alias('id') final int id; - + @Alias('category') final Category category; - + @Alias('name') final String name; - + @Alias('photoUrls') final List photoUrls; - + @Alias('tags') final List tags; - /* pet status in the store */ + /* pet status in the store */ @Alias('status') final String status; //enum statusEnum { available, pending, sold, }; Pet( - {this.id = null, - this.category = null, - this.name = null, - this.photoUrls = const [], - this.tags = const [], - this.status = null}); + + +{ + this.id = null, + this.category = null, + + this.name = null, + this.photoUrls = const [], this.tags = const [], + this.status = null + + } + ); @override String toString() { @@ -38,5 +45,7 @@ class Pet { } } -@GenSerializer() -class PetSerializer extends Serializer with _$PetSerializer {} +@GenSerializer(nullableFields: true) +class PetSerializer extends Serializer with _$PetSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart index 6182f362972..75a61e3fdba 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart @@ -3,13 +3,23 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'tag.jser.dart'; class Tag { + @Alias('id') final int id; - + @Alias('name') final String name; + - Tag({this.id = null, this.name = null}); + Tag( + + +{ + this.id = null, + this.name = null + + } + ); @override String toString() { @@ -17,5 +27,7 @@ class Tag { } } -@GenSerializer() -class TagSerializer extends Serializer with _$TagSerializer {} +@GenSerializer(nullableFields: true) +class TagSerializer extends Serializer with _$TagSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart index 9ad7df784c8..c37ea65b144 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart @@ -3,39 +3,47 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'user.jser.dart'; class User { + @Alias('id') final int id; - + @Alias('username') final String username; - + @Alias('firstName') final String firstName; - + @Alias('lastName') final String lastName; - + @Alias('email') final String email; - + @Alias('password') final String password; - + @Alias('phone') final String phone; - /* User Status */ + /* User Status */ @Alias('userStatus') final int userStatus; + User( - {this.id = null, - this.username = null, - this.firstName = null, - this.lastName = null, - this.email = null, - this.password = null, - this.phone = null, - this.userStatus = null}); + + +{ + this.id = null, + this.username = null, + this.firstName = null, + this.lastName = null, + this.email = null, + this.password = null, + this.phone = null, + this.userStatus = null + + } + ); @override String toString() { @@ -43,5 +51,7 @@ class User { } } -@GenSerializer() -class UserSerializer extends Serializer with _$UserSerializer {} +@GenSerializer(nullableFields: true) +class UserSerializer extends Serializer with _$UserSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/pubspec.yaml b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/pubspec.yaml index 001a842f966..2b10ea61aef 100644 --- a/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/pubspec.yaml +++ b/samples/client/petstore/dart-jaguar/flutter_petstore/openapi/pubspec.yaml @@ -4,9 +4,9 @@ description: OpenAPI API client environment: sdk: ">=2.0.0 <3.0.0" dependencies: - jaguar_retrofit: '^2.5.4' - jaguar_serializer: '^2.2.2' + jaguar_retrofit: '^2.5.12' + jaguar_serializer: '^2.2.4' dev_dependencies: - jaguar_retrofit_gen: '^2.5.2' - jaguar_serializer_cli: '^2.2.1' - build_runner: '^0.10.0' \ No newline at end of file + jaguar_retrofit_gen: '^2.5.10' + jaguar_serializer_cli: '^2.2.4' + build_runner: '^1.1.1' \ No newline at end of file diff --git a/samples/client/petstore/dart-jaguar/openapi/README.md b/samples/client/petstore/dart-jaguar/openapi/README.md index 7b71cf72e98..33dfbd21131 100644 --- a/samples/client/petstore/dart-jaguar/openapi/README.md +++ b/samples/client/petstore/dart-jaguar/openapi/README.md @@ -4,7 +4,7 @@ This is a sample server Petstore server. For this sample, you can use the api ke This Dart package is automatically generated by the [Open API Codegen](https://github.com/OpenAPITools/openapi-generator) project: - API version: 1.0.0 -- Build date: 2018-10-08T15:27:15.700+08:00[Asia/Hong_Kong] +- Build date: 2018-12-02T16:16:43.185605+01:00[Europe/Paris] - Build package: org.openapitools.codegen.languages.DartJaguarClientCodegen ## Requirements diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/api.dart b/samples/client/petstore/dart-jaguar/openapi/lib/api.dart index e1aa03d6840..8add80e7ec1 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/api.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/api.dart @@ -1,6 +1,6 @@ library openapi.api; -import 'package:http/http.dart'; +import 'package:http/io_client.dart'; import 'package:jaguar_serializer/jaguar_serializer.dart'; import 'package:jaguar_retrofit/jaguar_retrofit.dart'; import 'package:openapi/auth/api_key_auth.dart'; @@ -18,100 +18,101 @@ import 'package:openapi/model/pet.dart'; import 'package:openapi/model/tag.dart'; import 'package:openapi/model/user.dart'; -final jsonJaguarRepo = JsonRepo() - ..add(ApiResponseSerializer()) - ..add(CategorySerializer()) - ..add(OrderSerializer()) - ..add(PetSerializer()) - ..add(TagSerializer()) - ..add(UserSerializer()); -final _defaultInterceptors = [ - OAuthInterceptor(), - BasicAuthInterceptor(), - ApiKeyAuthInterceptor() -]; +final jsonJaguarRepo = JsonRepo() +..add(ApiResponseSerializer()) +..add(CategorySerializer()) +..add(OrderSerializer()) +..add(PetSerializer()) +..add(TagSerializer()) +..add(UserSerializer()) +; + +final _defaultInterceptors = [OAuthInterceptor(), BasicAuthInterceptor(), ApiKeyAuthInterceptor()]; class JaguarApiGen { - List interceptors; - String basePath = "http://petstore.swagger.io/v2"; - Route _baseRoute; + List interceptors; + String basePath = "http://petstore.swagger.io/v2"; + Route _baseRoute; + final Duration timeout; - /** + /** * Add custom global interceptors, put overrideInterceptors to true to set your interceptors only (auth interceptors will not be added) */ - JaguarApiGen( - {List interceptors, - bool overrideInterceptors = false, - String baseUrl}) { - _baseRoute = - Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient()); - if (interceptors == null) { - this.interceptors = _defaultInterceptors; - } else if (overrideInterceptors) { - this.interceptors = interceptors; - } else { - this.interceptors = List.from(_defaultInterceptors)..addAll(interceptors); + JaguarApiGen({List interceptors, bool overrideInterceptors = false, String baseUrl, this.timeout = const Duration(minutes: 2)}) { + _baseRoute = Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient()); + if(interceptors == null) { + this.interceptors = _defaultInterceptors; + } + else if(overrideInterceptors){ + this.interceptors = interceptors; + } + else { + this.interceptors = List.from(_defaultInterceptors)..addAll(interceptors); + } + + this.interceptors.forEach((interceptor) { + _baseRoute.before(interceptor.before); + _baseRoute.after(interceptor.after); + }); } - this.interceptors.forEach((interceptor) { - _baseRoute.before(interceptor.before); - _baseRoute.after(interceptor.after); - }); - } + void setOAuthToken(String name, String token) { + (_defaultInterceptors[0] as OAuthInterceptor).tokens[name] = token; + } - void setOAuthToken(String name, String token) { - (_defaultInterceptors[0] as OAuthInterceptor).tokens[name] = token; - } + void setBasicAuth(String name, String username, String password) { + (_defaultInterceptors[1] as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password); + } - void setBasicAuth(String name, String username, String password) { - (_defaultInterceptors[1] as BasicAuthInterceptor).authInfo[name] = - BasicAuthInfo(username, password); - } + void setApiKey(String name, String apiKey) { + (_defaultInterceptors[2] as ApiKeyAuthInterceptor).apiKeys[name] = apiKey; + } - void setApiKey(String name, String apiKey) { - (_defaultInterceptors[2] as ApiKeyAuthInterceptor).apiKeys[name] = apiKey; - } - - /** + + /** * Get PetApi instance, base route and serializer can be overridden by a given but be careful, * by doing that all interceptors will not be executed */ - PetApi getPetApi({Route base, SerializerRepo serializers}) { - if (base == null) { - base = _baseRoute; + PetApi getPetApi({Route base, SerializerRepo serializers}) { + if(base == null) { + base = _baseRoute; + } + if(serializers == null) { + serializers = jsonJaguarRepo; + } + return PetApi(base: base, serializers: serializers, timeout: timeout); } - if (serializers == null) { - serializers = jsonJaguarRepo; - } - return PetApi(base: base, serializers: serializers); - } - /** + + /** * Get StoreApi instance, base route and serializer can be overridden by a given but be careful, * by doing that all interceptors will not be executed */ - StoreApi getStoreApi({Route base, SerializerRepo serializers}) { - if (base == null) { - base = _baseRoute; + StoreApi getStoreApi({Route base, SerializerRepo serializers}) { + if(base == null) { + base = _baseRoute; + } + if(serializers == null) { + serializers = jsonJaguarRepo; + } + return StoreApi(base: base, serializers: serializers, timeout: timeout); } - if (serializers == null) { - serializers = jsonJaguarRepo; - } - return StoreApi(base: base, serializers: serializers); - } - /** + + /** * Get UserApi instance, base route and serializer can be overridden by a given but be careful, * by doing that all interceptors will not be executed */ - UserApi getUserApi({Route base, SerializerRepo serializers}) { - if (base == null) { - base = _baseRoute; + UserApi getUserApi({Route base, SerializerRepo serializers}) { + if(base == null) { + base = _baseRoute; + } + if(serializers == null) { + serializers = jsonJaguarRepo; + } + return UserApi(base: base, serializers: serializers, timeout: timeout); } - if (serializers == null) { - serializers = jsonJaguarRepo; - } - return UserApi(base: base, serializers: serializers); - } -} + + +} \ No newline at end of file diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/api/pet_api.dart b/samples/client/petstore/dart-jaguar/openapi/lib/api/pet_api.dart index ae5f7e9c158..0c7270125dc 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/api/pet_api.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/api/pet_api.dart @@ -14,17 +14,24 @@ part 'pet_api.jretro.dart'; class PetApi extends _$PetApiClient implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - PetApi({this.base, this.serializers}); + PetApi({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); /// Add a new pet to the store /// /// @PostReq(path: "/pet", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future addPet( + + @AsJson() Pet pet + ) { + return super.addPet( + - @AsJson() Pet pet - ); + pet + ).timeout(timeout); + } /// Deletes a pet /// @@ -33,8 +40,15 @@ class PetApi extends _$PetApiClient implements ApiClient { Future deletePet( @PathParam("petId") int petId , - @Header("api_key") String apiKey - ); + @Header("api_key") String apiKey + ) { + return super.deletePet( + petId + , + apiKey + + ).timeout(timeout); + } /// Finds Pets by status /// @@ -42,8 +56,14 @@ class PetApi extends _$PetApiClient implements ApiClient { @GetReq(path: "/pet/findByStatus", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future> findPetsByStatus( - @QueryParam("status") List status - ); + @QueryParam("status") List status + ) { + return super.findPetsByStatus( + + status + + ).timeout(timeout); + } /// Finds Pets by tags /// @@ -51,8 +71,14 @@ class PetApi extends _$PetApiClient implements ApiClient { @GetReq(path: "/pet/findByTags", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future> findPetsByTags( - @QueryParam("tags") List tags - ); + @QueryParam("tags") List tags + ) { + return super.findPetsByTags( + + tags + + ).timeout(timeout); + } /// Find pet by ID /// @@ -60,16 +86,27 @@ class PetApi extends _$PetApiClient implements ApiClient { @GetReq(path: "/pet/:petId", metadata: {"auth": [ {"type": "apiKey", "name": "api_key", "keyName": "api_key", "where": "header" }]}) Future getPetById( @PathParam("petId") int petId - ); + ) { + return super.getPetById( + petId + + ).timeout(timeout); + } /// Update an existing pet /// /// @PutReq(path: "/pet", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future updatePet( + + @AsJson() Pet pet + ) { + return super.updatePet( + - @AsJson() Pet pet - ); + pet + ).timeout(timeout); + } /// Updates a pet in the store with form data /// @@ -77,11 +114,20 @@ class PetApi extends _$PetApiClient implements ApiClient { @PostReq(path: "/pet/:petId", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future updatePetWithForm( @PathParam("petId") int petId + , + @AsFormField() String name, + + @AsFormField() String status + ) { + return super.updatePetWithForm( + petId + , - @AsFormField() String name, + name, - @AsFormField() String status - ); + status + ).timeout(timeout); + } /// uploads an image /// @@ -89,11 +135,20 @@ class PetApi extends _$PetApiClient implements ApiClient { @PostReq(path: "/pet/:petId/uploadImage", metadata: {"auth": [ {"type": "oauth2", "name": "petstore_auth" }]}) Future uploadFile( @PathParam("petId") int petId + , + @AsMultipartField() String additionalMetadata, + + @AsMultipartField() MultipartFile file + ) { + return super.uploadFile( + petId + , - @AsMultipartField() String additionalMetadata, + additionalMetadata, - @AsMultipartField() MultipartFile file - ); + file + ).timeout(timeout); + } } diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/api/store_api.dart b/samples/client/petstore/dart-jaguar/openapi/lib/api/store_api.dart index b0e40104275..816a3f91425 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/api/store_api.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/api/store_api.dart @@ -13,8 +13,9 @@ part 'store_api.jretro.dart'; class StoreApi extends _$StoreApiClient implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - StoreApi({this.base, this.serializers}); + StoreApi({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); /// Delete purchase order by ID /// @@ -22,14 +23,23 @@ class StoreApi extends _$StoreApiClient implements ApiClient { @DeleteReq(path: "/store/order/:orderId") Future deleteOrder( @PathParam("orderId") String orderId - ); + ) { + return super.deleteOrder( + orderId + + ).timeout(timeout); + } /// Returns pet inventories by status /// /// Returns a map of status codes to quantities @GetReq(path: "/store/inventory", metadata: {"auth": [ {"type": "apiKey", "name": "api_key", "keyName": "api_key", "where": "header" }]}) Future> getInventory( - ); + ) { + return super.getInventory( + + ).timeout(timeout); + } /// Find purchase order by ID /// @@ -37,16 +47,27 @@ class StoreApi extends _$StoreApiClient implements ApiClient { @GetReq(path: "/store/order/:orderId") Future getOrderById( @PathParam("orderId") int orderId - ); + ) { + return super.getOrderById( + orderId + + ).timeout(timeout); + } /// Place an order for a pet /// /// @PostReq(path: "/store/order") Future placeOrder( + + @AsJson() Order order + ) { + return super.placeOrder( + - @AsJson() Order order - ); + order + ).timeout(timeout); + } } diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/api/user_api.dart b/samples/client/petstore/dart-jaguar/openapi/lib/api/user_api.dart index 337375075c2..f6469066799 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/api/user_api.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/api/user_api.dart @@ -13,35 +13,54 @@ part 'user_api.jretro.dart'; class UserApi extends _$UserApiClient implements ApiClient { final Route base; final SerializerRepo serializers; + final Duration timeout; - UserApi({this.base, this.serializers}); + UserApi({this.base, this.serializers, this.timeout = const Duration(minutes: 2)}); /// Create user /// /// This can only be done by the logged in user. @PostReq(path: "/user") Future createUser( + + @AsJson() User user + ) { + return super.createUser( + - @AsJson() User user - ); + user + ).timeout(timeout); + } /// Creates list of users with given input array /// /// @PostReq(path: "/user/createWithArray") Future createUsersWithArrayInput( + + @AsJson() List user + ) { + return super.createUsersWithArrayInput( + - @AsJson() List user - ); + user + ).timeout(timeout); + } /// Creates list of users with given input array /// /// @PostReq(path: "/user/createWithList") Future createUsersWithListInput( + + @AsJson() List user + ) { + return super.createUsersWithListInput( + - @AsJson() List user - ); + user + ).timeout(timeout); + } /// Delete user /// @@ -49,7 +68,12 @@ class UserApi extends _$UserApiClient implements ApiClient { @DeleteReq(path: "/user/:username") Future deleteUser( @PathParam("username") String username - ); + ) { + return super.deleteUser( + username + + ).timeout(timeout); + } /// Get user by user name /// @@ -57,7 +81,12 @@ class UserApi extends _$UserApiClient implements ApiClient { @GetReq(path: "/user/:username") Future getUserByName( @PathParam("username") String username - ); + ) { + return super.getUserByName( + username + + ).timeout(timeout); + } /// Logs user into the system /// @@ -65,17 +94,29 @@ class UserApi extends _$UserApiClient implements ApiClient { @GetReq(path: "/user/login") Future loginUser( - @QueryParam("username") String username, + @QueryParam("username") String username, - @QueryParam("password") String password - ); + @QueryParam("password") String password + ) { + return super.loginUser( + + username, + + password + + ).timeout(timeout); + } /// Logs out current logged in user session /// /// @GetReq(path: "/user/logout") Future logoutUser( - ); + ) { + return super.logoutUser( + + ).timeout(timeout); + } /// Updated user /// @@ -83,9 +124,16 @@ class UserApi extends _$UserApiClient implements ApiClient { @PutReq(path: "/user/:username") Future updateUser( @PathParam("username") String username + , + @AsJson() User user + ) { + return super.updateUser( + username + , - @AsJson() User user - ); + user + ).timeout(timeout); + } } diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart index d0709e397a3..dbbc7582062 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart @@ -3,16 +3,27 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'api_response.jser.dart'; class ApiResponse { + @Alias('code') final int code; - + @Alias('type') final String type; - + @Alias('message') final String message; + - ApiResponse({this.code = null, this.type = null, this.message = null}); + ApiResponse( + + +{ + this.code = null, + this.type = null, + this.message = null + + } + ); @override String toString() { @@ -20,6 +31,7 @@ class ApiResponse { } } -@GenSerializer() -class ApiResponseSerializer extends Serializer - with _$ApiResponseSerializer {} +@GenSerializer(nullableFields: true) +class ApiResponseSerializer extends Serializer with _$ApiResponseSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart index 0462782e68c..2a02961072f 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart @@ -3,13 +3,23 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'category.jser.dart'; class Category { + @Alias('id') final int id; - + @Alias('name') final String name; + - Category({this.id = null, this.name = null}); + Category( + + +{ + this.id = null, + this.name = null + + } + ); @override String toString() { @@ -17,6 +27,7 @@ class Category { } } -@GenSerializer() -class CategorySerializer extends Serializer - with _$CategorySerializer {} +@GenSerializer(nullableFields: true) +class CategorySerializer extends Serializer with _$CategorySerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart index ccf82bb5d8d..3086347338a 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart @@ -3,31 +3,39 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'order.jser.dart'; class Order { + @Alias('id') final int id; - + @Alias('petId') final int petId; - + @Alias('quantity') final int quantity; - + @Alias('shipDate') final DateTime shipDate; - /* Order Status */ + /* Order Status */ @Alias('status') final String status; //enum statusEnum { placed, approved, delivered, }; @Alias('complete') final bool complete; + Order( - {this.id = null, - this.petId = null, - this.quantity = null, - this.shipDate = null, - this.status = null, - this.complete = false}); + + +{ + this.id = null, + this.petId = null, + this.quantity = null, + this.shipDate = null, + this.status = null, + this.complete = false + + } + ); @override String toString() { @@ -35,5 +43,7 @@ class Order { } } -@GenSerializer() -class OrderSerializer extends Serializer with _$OrderSerializer {} +@GenSerializer(nullableFields: true) +class OrderSerializer extends Serializer with _$OrderSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart index eaf4dac08d6..b487e6ba032 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart @@ -5,32 +5,39 @@ import 'package:openapi/model/category.dart'; part 'pet.jser.dart'; class Pet { + @Alias('id') final int id; - + @Alias('category') final Category category; - + @Alias('name') final String name; - + @Alias('photoUrls') final List photoUrls; - + @Alias('tags') final List tags; - /* pet status in the store */ + /* pet status in the store */ @Alias('status') final String status; //enum statusEnum { available, pending, sold, }; Pet( - {this.id = null, - this.category = null, - this.name = null, - this.photoUrls = const [], - this.tags = const [], - this.status = null}); + + +{ + this.id = null, + this.category = null, + + this.name = null, + this.photoUrls = const [], this.tags = const [], + this.status = null + + } + ); @override String toString() { @@ -38,5 +45,7 @@ class Pet { } } -@GenSerializer() -class PetSerializer extends Serializer with _$PetSerializer {} +@GenSerializer(nullableFields: true) +class PetSerializer extends Serializer with _$PetSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart index 6182f362972..75a61e3fdba 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart @@ -3,13 +3,23 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'tag.jser.dart'; class Tag { + @Alias('id') final int id; - + @Alias('name') final String name; + - Tag({this.id = null, this.name = null}); + Tag( + + +{ + this.id = null, + this.name = null + + } + ); @override String toString() { @@ -17,5 +27,7 @@ class Tag { } } -@GenSerializer() -class TagSerializer extends Serializer with _$TagSerializer {} +@GenSerializer(nullableFields: true) +class TagSerializer extends Serializer with _$TagSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart b/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart index 9ad7df784c8..c37ea65b144 100644 --- a/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart +++ b/samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart @@ -3,39 +3,47 @@ import 'package:jaguar_serializer/jaguar_serializer.dart'; part 'user.jser.dart'; class User { + @Alias('id') final int id; - + @Alias('username') final String username; - + @Alias('firstName') final String firstName; - + @Alias('lastName') final String lastName; - + @Alias('email') final String email; - + @Alias('password') final String password; - + @Alias('phone') final String phone; - /* User Status */ + /* User Status */ @Alias('userStatus') final int userStatus; + User( - {this.id = null, - this.username = null, - this.firstName = null, - this.lastName = null, - this.email = null, - this.password = null, - this.phone = null, - this.userStatus = null}); + + +{ + this.id = null, + this.username = null, + this.firstName = null, + this.lastName = null, + this.email = null, + this.password = null, + this.phone = null, + this.userStatus = null + + } + ); @override String toString() { @@ -43,5 +51,7 @@ class User { } } -@GenSerializer() -class UserSerializer extends Serializer with _$UserSerializer {} +@GenSerializer(nullableFields: true) +class UserSerializer extends Serializer with _$UserSerializer { + +} diff --git a/samples/client/petstore/dart-jaguar/openapi/pubspec.yaml b/samples/client/petstore/dart-jaguar/openapi/pubspec.yaml index 001a842f966..2b10ea61aef 100644 --- a/samples/client/petstore/dart-jaguar/openapi/pubspec.yaml +++ b/samples/client/petstore/dart-jaguar/openapi/pubspec.yaml @@ -4,9 +4,9 @@ description: OpenAPI API client environment: sdk: ">=2.0.0 <3.0.0" dependencies: - jaguar_retrofit: '^2.5.4' - jaguar_serializer: '^2.2.2' + jaguar_retrofit: '^2.5.12' + jaguar_serializer: '^2.2.4' dev_dependencies: - jaguar_retrofit_gen: '^2.5.2' - jaguar_serializer_cli: '^2.2.1' - build_runner: '^0.10.0' \ No newline at end of file + jaguar_retrofit_gen: '^2.5.10' + jaguar_serializer_cli: '^2.2.4' + build_runner: '^1.1.1' \ No newline at end of file