Skip to content

Commit d509ba1

Browse files
jaumardwing328
authored andcommitted
add default timeout to calls (OpenAPITools#1596)
add properties to send or not null values update deps
1 parent 492bcea commit d509ba1

File tree

29 files changed

+785
-369
lines changed

29 files changed

+785
-369
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.openapitools.codegen.languages;
1818

19+
import org.openapitools.codegen.CliOption;
1920
import org.openapitools.codegen.CodegenConstants;
2021
import org.openapitools.codegen.CodegenModel;
2122
import org.openapitools.codegen.CodegenOperation;
@@ -36,6 +37,7 @@
3637
import static org.openapitools.codegen.utils.StringUtils.underscore;
3738

3839
public class DartJaguarClientCodegen extends DartClientCodegen {
40+
private static final String NULLABLE_FIELDS = "nullableFields";
3941
private static Set<String> modelToIgnore = new HashSet<>();
4042

4143
static {
@@ -45,11 +47,15 @@ public class DartJaguarClientCodegen extends DartClientCodegen {
4547
modelToIgnore.add("file");
4648
}
4749

50+
private boolean nullableFields = true;
51+
4852
public DartJaguarClientCodegen() {
4953
super();
5054
browserClient = false;
5155
outputFolder = "generated-code/dart-jaguar";
5256
embeddedTemplateDir = templateDir = "dart-jaguar";
57+
58+
cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
5359
}
5460

5561
@Override
@@ -74,6 +80,13 @@ public String toDefaultValue(Schema p) {
7480

7581
@Override
7682
public void processOpts() {
83+
if (additionalProperties.containsKey(NULLABLE_FIELDS)) {
84+
nullableFields = convertPropertyToBooleanAndWriteBack(NULLABLE_FIELDS);
85+
} else {
86+
//not set, use to be passed to template
87+
additionalProperties.put(NULLABLE_FIELDS, nullableFields);
88+
}
89+
7790
if (additionalProperties.containsKey(PUB_NAME)) {
7891
this.setPubName((String) additionalProperties.get(PUB_NAME));
7992
} else {

modules/openapi-generator/src/main/resources/dart-jaguar/api.mustache

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ part '{{classFilename}}.jretro.dart';
1515
class {{classname}} extends _${{classname}}Client implements ApiClient {
1616
final Route base;
1717
final SerializerRepo serializers;
18+
final Duration timeout;
1819
19-
{{classname}}({this.base, this.serializers});
20+
{{classname}}({this.base, this.serializers, this.timeout = const Duration(minutes: 2)});
2021

2122
{{#operation}}
2223
/// {{summary}}
@@ -29,23 +30,46 @@ class {{classname}} extends _${{classname}}Client implements ApiClient {
2930
{{/pathParams}}
3031
{{#headerParams}}
3132
{{#-first}}{{#hasPathParams}},{{/hasPathParams}}{{/-first}}
32-
@Header("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
33+
@Header("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
3334
{{/headerParams}}
3435
{{#queryParams}}
3536
{{#-first}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/-first}}
36-
@QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
37+
@QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
3738
{{/queryParams}}
3839
{{#vendorExtensions}}
40+
{{#formParams}}
41+
{{#-first}}{{#hasQueryParams}},{{/hasQueryParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/-first}}
42+
{{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsFormField() {{/isForm}}{{#isMultipart}}@AsMultipartField() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
43+
{{/formParams}}
44+
{{#bodyParam}}
45+
{{#hasFormParams}},{{/hasFormParams}}{{^hasFormParams}}{{#hasQueryParams}},{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}}
46+
{{^isJson}}{{^isForm}}{{^isMultipart}}@AsBody(){{/isMultipart}}{{/isForm}}{{/isJson}} {{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsForm() {{/isForm}}{{#isMultipart}}@AsMultipart() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
47+
{{/bodyParam}}
48+
{{/vendorExtensions}}
49+
) {
50+
return super.{{nickname}}(
51+
{{#pathParams}}
52+
{{paramName}}{{#hasMore}}, {{/hasMore}}
53+
{{/pathParams}}
54+
{{#headerParams}}
55+
{{#-first}}{{#hasPathParams}},{{/hasPathParams}}{{/-first}}
56+
{{paramName}}{{#hasMore}}, {{/hasMore}}
57+
{{/headerParams}}
58+
{{#queryParams}}
59+
{{#-first}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/-first}}
60+
{{paramName}}{{#hasMore}}, {{/hasMore}}
61+
{{/queryParams}}
62+
3963
{{#formParams}}
4064
{{#-first}}{{#hasQueryParams}},{{/hasQueryParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/-first}}
41-
{{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsFormField() {{/isForm}}{{#isMultipart}}@AsMultipartField() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
65+
{{paramName}}{{#hasMore}}, {{/hasMore}}
4266
{{/formParams}}
4367
{{#bodyParam}}
4468
{{#hasFormParams}},{{/hasFormParams}}{{^hasFormParams}}{{#hasQueryParams}},{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{#hasHeaderParams}},{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}}{{^hasFormParams}}{{^hasQueryParams}}{{^hasHeaderParams}}{{#hasPathParams}},{{/hasPathParams}}{{/hasHeaderParams}}{{/hasQueryParams}}{{/hasFormParams}}
45-
{{#isJson}}@AsJson() {{/isJson}}{{#isForm}}@AsForm() {{/isForm}}{{#isMultipart}}@AsMultipart() {{/isMultipart}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}
69+
{{paramName}}{{#hasMore}}, {{/hasMore}}
4670
{{/bodyParam}}
47-
{{/vendorExtensions}}
48-
);
71+
).timeout(timeout);
72+
}
4973

5074
{{/operation}}
5175

modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library {{pubName}}.api;
22

3-
import 'package:http/http.dart';
3+
import 'package:http/io_client.dart';
44
import 'package:jaguar_serializer/jaguar_serializer.dart';
55
import 'package:jaguar_retrofit/jaguar_retrofit.dart';
66
import 'package:{{pubName}}/auth/api_key_auth.dart';
@@ -22,11 +22,12 @@ class JaguarApiGen {
2222
List<Interceptor> interceptors;
2323
String basePath = "{{basePath}}";
2424
Route _baseRoute;
25+
final Duration timeout;
2526
2627
/**
2728
* Add custom global interceptors, put overrideInterceptors to true to set your interceptors only (auth interceptors will not be added)
2829
*/
29-
JaguarApiGen({List<Interceptor> interceptors, bool overrideInterceptors = false, String baseUrl}) {
30+
JaguarApiGen({List<Interceptor> interceptors, bool overrideInterceptors = false, String baseUrl, this.timeout = const Duration(minutes: 2)}) {
3031
_baseRoute = Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient());
3132
if(interceptors == null) {
3233
this.interceptors = _defaultInterceptors;
@@ -68,8 +69,8 @@ class JaguarApiGen {
6869
if(serializers == null) {
6970
serializers = jsonJaguarRepo;
7071
}
71-
return {{classname}}(base: base, serializers: serializers);
72+
return {{classname}}(base: base, serializers: serializers, timeout: timeout);
7273
}
7374

7475
{{/apis}}{{/apiInfo}}
75-
}
76+
}

modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ part '{{classFilename}}.jser.dart';
22

33
class {{classname}} {
44
{{#vars}}{{#description}} /* {{{description}}} */{{/description}}
5-
@Alias('{{{baseName}}}')
5+
@Alias('{{baseName}}')
66
final {{{datatype}}} {{name}};
77
{{#allowableValues}}{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{{/allowableValues}}{{/vars}}
88

99
{{classname}}(
10-
{{#vars}}{{^defaultValue}}{{#required}} this.{{name}}, {{/required}}{{/defaultValue}}{{/vars}}
10+
{{#vars}}{{^defaultValue}}{{#required}} this.{{name}}, {{/required}}{{/defaultValue}}{{/vars}}
1111

1212
{{#vendorExtensions}}{{#hasVars}}{
1313
{{#vars}}{{^required}} this.{{name}}{{#defaultValue}} = {{{defaultValue}}}{{#hasMore}}, {{/hasMore}} {{/defaultValue}}{{/required}}
@@ -21,7 +21,7 @@ class {{classname}} {
2121
}
2222
}
2323

24-
@GenSerializer()
24+
@GenSerializer(nullableFields: {{nullableFields}})
2525
class {{classname}}Serializer extends Serializer<{{classname}}> with _${{classname}}Serializer {
2626
2727
}

modules/openapi-generator/src/main/resources/dart-jaguar/pubspec.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ description: {{pubDescription}}
44
environment:
55
sdk: ">=2.0.0 <3.0.0"
66
dependencies:
7-
jaguar_retrofit: '^2.5.4'
8-
jaguar_serializer: '^2.2.2'
7+
jaguar_retrofit: '^2.5.12'
8+
jaguar_serializer: '^2.2.4'
99
dev_dependencies:
10-
jaguar_retrofit_gen: '^2.5.2'
11-
jaguar_serializer_cli: '^2.2.1'
12-
build_runner: '^0.10.0'
10+
jaguar_retrofit_gen: '^2.5.10'
11+
jaguar_serializer_cli: '^2.2.4'
12+
build_runner: '^1.1.1'

samples/client/petstore/dart-jaguar/flutter_petstore/openapi/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a sample server Petstore server. For this sample, you can use the api ke
44
This Dart package is automatically generated by the [Open API Codegen](https://github.com/OpenAPITools/openapi-generator) project:
55

66
- API version: 1.0.0
7-
- Build date: 2018-10-08T15:27:22.304+08:00[Asia/Hong_Kong]
7+
- Build date: 2018-12-02T16:16:44.701611+01:00[Europe/Paris]
88
- Build package: org.openapitools.codegen.languages.DartJaguarClientCodegen
99

1010
## Requirements
Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library openapi.api;
22

3-
import 'package:http/http.dart';
3+
import 'package:http/io_client.dart';
44
import 'package:jaguar_serializer/jaguar_serializer.dart';
55
import 'package:jaguar_retrofit/jaguar_retrofit.dart';
66
import 'package:openapi/auth/api_key_auth.dart';
@@ -18,100 +18,101 @@ import 'package:openapi/model/pet.dart';
1818
import 'package:openapi/model/tag.dart';
1919
import 'package:openapi/model/user.dart';
2020

21+
2122
final jsonJaguarRepo = JsonRepo()
22-
..add(ApiResponseSerializer())
23-
..add(CategorySerializer())
24-
..add(OrderSerializer())
25-
..add(PetSerializer())
26-
..add(TagSerializer())
27-
..add(UserSerializer());
28-
29-
final _defaultInterceptors = [
30-
OAuthInterceptor(),
31-
BasicAuthInterceptor(),
32-
ApiKeyAuthInterceptor()
33-
];
23+
..add(ApiResponseSerializer())
24+
..add(CategorySerializer())
25+
..add(OrderSerializer())
26+
..add(PetSerializer())
27+
..add(TagSerializer())
28+
..add(UserSerializer())
29+
;
30+
31+
final _defaultInterceptors = [OAuthInterceptor(), BasicAuthInterceptor(), ApiKeyAuthInterceptor()];
3432

3533
class JaguarApiGen {
36-
List<Interceptor> interceptors;
37-
String basePath = "http://petstore.swagger.io/v2";
38-
Route _baseRoute;
34+
List<Interceptor> interceptors;
35+
String basePath = "http://petstore.swagger.io/v2";
36+
Route _baseRoute;
37+
final Duration timeout;
3938

40-
/**
39+
/**
4140
* Add custom global interceptors, put overrideInterceptors to true to set your interceptors only (auth interceptors will not be added)
4241
*/
43-
JaguarApiGen(
44-
{List<Interceptor> interceptors,
45-
bool overrideInterceptors = false,
46-
String baseUrl}) {
47-
_baseRoute =
48-
Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient());
49-
if (interceptors == null) {
50-
this.interceptors = _defaultInterceptors;
51-
} else if (overrideInterceptors) {
52-
this.interceptors = interceptors;
53-
} else {
54-
this.interceptors = List.from(_defaultInterceptors)..addAll(interceptors);
55-
}
42+
JaguarApiGen({List<Interceptor> interceptors, bool overrideInterceptors = false, String baseUrl, this.timeout = const Duration(minutes: 2)}) {
43+
_baseRoute = Route(baseUrl ?? basePath).withClient(globalClient ?? IOClient());
44+
if(interceptors == null) {
45+
this.interceptors = _defaultInterceptors;
46+
}
47+
else if(overrideInterceptors){
48+
this.interceptors = interceptors;
49+
}
50+
else {
51+
this.interceptors = List.from(_defaultInterceptors)..addAll(interceptors);
52+
}
5653

57-
this.interceptors.forEach((interceptor) {
58-
_baseRoute.before(interceptor.before);
59-
_baseRoute.after(interceptor.after);
60-
});
61-
}
54+
this.interceptors.forEach((interceptor) {
55+
_baseRoute.before(interceptor.before);
56+
_baseRoute.after(interceptor.after);
57+
});
58+
}
6259

63-
void setOAuthToken(String name, String token) {
64-
(_defaultInterceptors[0] as OAuthInterceptor).tokens[name] = token;
65-
}
60+
void setOAuthToken(String name, String token) {
61+
(_defaultInterceptors[0] as OAuthInterceptor).tokens[name] = token;
62+
}
6663

67-
void setBasicAuth(String name, String username, String password) {
68-
(_defaultInterceptors[1] as BasicAuthInterceptor).authInfo[name] =
69-
BasicAuthInfo(username, password);
70-
}
64+
void setBasicAuth(String name, String username, String password) {
65+
(_defaultInterceptors[1] as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password);
66+
}
7167

72-
void setApiKey(String name, String apiKey) {
73-
(_defaultInterceptors[2] as ApiKeyAuthInterceptor).apiKeys[name] = apiKey;
74-
}
68+
void setApiKey(String name, String apiKey) {
69+
(_defaultInterceptors[2] as ApiKeyAuthInterceptor).apiKeys[name] = apiKey;
70+
}
7571

76-
/**
72+
73+
/**
7774
* Get PetApi instance, base route and serializer can be overridden by a given but be careful,
7875
* by doing that all interceptors will not be executed
7976
*/
80-
PetApi getPetApi({Route base, SerializerRepo serializers}) {
81-
if (base == null) {
82-
base = _baseRoute;
83-
}
84-
if (serializers == null) {
85-
serializers = jsonJaguarRepo;
77+
PetApi getPetApi({Route base, SerializerRepo serializers}) {
78+
if(base == null) {
79+
base = _baseRoute;
80+
}
81+
if(serializers == null) {
82+
serializers = jsonJaguarRepo;
83+
}
84+
return PetApi(base: base, serializers: serializers, timeout: timeout);
8685
}
87-
return PetApi(base: base, serializers: serializers);
88-
}
8986

90-
/**
87+
88+
/**
9189
* Get StoreApi instance, base route and serializer can be overridden by a given but be careful,
9290
* by doing that all interceptors will not be executed
9391
*/
94-
StoreApi getStoreApi({Route base, SerializerRepo serializers}) {
95-
if (base == null) {
96-
base = _baseRoute;
97-
}
98-
if (serializers == null) {
99-
serializers = jsonJaguarRepo;
92+
StoreApi getStoreApi({Route base, SerializerRepo serializers}) {
93+
if(base == null) {
94+
base = _baseRoute;
95+
}
96+
if(serializers == null) {
97+
serializers = jsonJaguarRepo;
98+
}
99+
return StoreApi(base: base, serializers: serializers, timeout: timeout);
100100
}
101-
return StoreApi(base: base, serializers: serializers);
102-
}
103101

104-
/**
102+
103+
/**
105104
* Get UserApi instance, base route and serializer can be overridden by a given but be careful,
106105
* by doing that all interceptors will not be executed
107106
*/
108-
UserApi getUserApi({Route base, SerializerRepo serializers}) {
109-
if (base == null) {
110-
base = _baseRoute;
107+
UserApi getUserApi({Route base, SerializerRepo serializers}) {
108+
if(base == null) {
109+
base = _baseRoute;
110+
}
111+
if(serializers == null) {
112+
serializers = jsonJaguarRepo;
113+
}
114+
return UserApi(base: base, serializers: serializers, timeout: timeout);
111115
}
112-
if (serializers == null) {
113-
serializers = jsonJaguarRepo;
114-
}
115-
return UserApi(base: base, serializers: serializers);
116-
}
117-
}
116+
117+
118+
}

0 commit comments

Comments
 (0)