Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 48 additions & 34 deletions modules/openapi-generator/src/main/resources/dart-dio/api.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
Expand All @@ -17,29 +16,37 @@ class {{classname}} {
{{classname}}(this._dio, this._serializers);

{{#operation}}
/// {{summary}}
///
/// {{notes}}
Future<Response{{#returnType}}<{{{returnType}}}>{{/returnType}}>{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}},{{/required}}{{/allParams}}CancelToken cancelToken, Map<String, String> headers, ProgressCallback onSendProgress, ProgressCallback onReceiveProgress,}) async {
/// {{{summary}}}
///
/// {{{notes}}}
Future<Response{{#returnType}}<{{{returnType}}}>{{/returnType}}>{{nickname}}({{^hasRequiredParams}}{ {{/hasRequiredParams}}{{#requiredParams}}
{{{dataType}}} {{paramName}},{{#-last}} { {{/-last}}{{/requiredParams}}{{#optionalParams}}
{{{dataType}}} {{paramName}},{{/optionalParams}}
CancelToken cancelToken,
Map<String, String> headers,
ProgressCallback onSendProgress,
ProgressCallback onReceiveProgress,
}) async {
final String _path = '{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{baseName}}' '}', {{{paramName}}}.toString()){{/pathParams}};

String _path = "{{{path}}}"{{#pathParams}}.replaceAll("{" r'{{baseName}}' "}", {{{paramName}}}.toString()){{/pathParams}};

Map<String, dynamic> queryParams = {};
Map<String, String> headerParams = Map.from(headers ?? {});
final Map<String, dynamic> queryParams = {};
final Map<String, String> headerParams = Map.from(headers ?? {});
dynamic bodyData;

{{#headerParams}}
headerParams[r'{{baseName}}'] = {{paramName}};
headerParams[r'{{baseName}}'] = {{paramName}};
{{/headerParams}}
{{#queryParams}}
queryParams[r'{{baseName}}'] = {{paramName}};
queryParams[r'{{baseName}}'] = {{paramName}};
{{/queryParams}}
queryParams.removeWhere((key, value) => value == null);
headerParams.removeWhere((key, value) => value == null);

List<String> contentTypes = [{{#consumes}}"{{{mediaType}}}"{{^-last}},{{/-last}}{{/consumes}}];

final List<String> contentTypes = [{{^hasConsumes}}];{{/hasConsumes}}{{#hasConsumes}}{{#consumes}}
'{{{mediaType}}}',{{/consumes}}
];{{/hasConsumes}}
{{#hasFormParams}}

final Map<String, dynamic> formData = {};
{{#isMultipart}}
{{#formParams}}
Expand All @@ -63,39 +70,45 @@ class {{classname}} {
bodyData = formData;
{{/isMultipart}}
{{/hasFormParams}}

{{#bodyParam}}

{{#isArray}}
const type = FullType(BuiltList, [FullType({{baseType}})]);
final serializedBody = _serializers.serialize({{paramName}}, specifiedType: type);
const type = FullType(BuiltList, [FullType({{baseType}})]);
final serializedBody = _serializers.serialize({{paramName}}, specifiedType: type);
{{/isArray}}
{{^isArray}}
final serializedBody = _serializers.serialize({{paramName}});
final serializedBody = _serializers.serialize({{paramName}});
{{/isArray}}
final json{{paramName}} = json.encode(serializedBody);
bodyData = json{{paramName}};
final json{{paramName}} = json.encode(serializedBody);
bodyData = json{{paramName}};
{{/bodyParam}}

return _dio.request(
return _dio.request(
_path,
queryParameters: queryParams,
data: bodyData,
options: Options(
method: '{{httpMethod}}'.toUpperCase(),
{{#isResponseFile}}
responseType: ResponseType.bytes,
{{/isResponseFile}}
headers: headerParams,
extra: {
'secure': [{{#authMethods}} {"type": "{{type}}", "name": "{{name}}"{{#isApiKey}}, "keyName": "{{keyParamName}}", "where": "{{#isKeyInQuery}}query{{/isKeyInQuery}}{{#isKeyInHeader}}header{{/isKeyInHeader}}"{{/isApiKey}} }{{^-last}}, {{/-last}}{{/authMethods}}],
},
contentType: contentTypes.isNotEmpty ? contentTypes[0] : "application/json",
method: '{{httpMethod}}'.toUpperCase(),
{{#isResponseFile}}
responseType: ResponseType.bytes,
{{/isResponseFile}}
headers: headerParams,
extra: {
'secure': [{{^hasAuthMethods}}],{{/hasAuthMethods}}{{#hasAuthMethods}}
{{#authMethods}}{
'type': '{{type}}',
'name': '{{name}}',{{#isApiKey}}
'keyName': '{{keyParamName}}',
'where': '{{#isKeyInQuery}}query{{/isKeyInQuery}}{{#isKeyInHeader}}header{{/isKeyInHeader}}',{{/isApiKey}}
},{{/authMethods}}
],{{/hasAuthMethods}}
},
contentType: contentTypes.isNotEmpty ? contentTypes[0] : 'application/json',
),
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
){{#returnType}}.then((response) {

){{#returnType}}.then((response) {
{{#isResponseFile}}
final data = response.data;
{{/isResponseFile}}
Expand Down Expand Up @@ -125,8 +138,9 @@ class {{classname}} {
statusMessage: response.statusMessage,
extra: response.extra,
);
}){{/returnType}};
}
}){{/returnType}};
}

{{/operation}}
}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import 'package:{{pubName}}/api.dart';

var api_instance = new {{classname}}();
{{#allParams}}
var {{paramName}} = {{#isArray}}[{{/isArray}}{{#isBodyParam}}new {{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isArray}}]{{/isArray}}; // {{{dataType}}} | {{{description}}}
var {{paramName}} = {{#isArray}}[{{/isArray}}{{#isBodyParam}}new {{{dataType}}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isArray}}]{{/isArray}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}

try {
Expand All @@ -56,15 +56,15 @@ try {
print(result);
{{/returnType}}
} catch (e) {
print("Exception when calling {{classname}}->{{operationId}}: $e\n");
print('Exception when calling {{classname}}->{{operationId}}: $e\n');
}
```

### Parameters
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{baseType}}.md){{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{{dataType}}}**]({{baseType}}.md){{/isPrimitiveType}}| {{{description}}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{{defaultValue}}}]{{/defaultValue}}
{{/allParams}}

### Return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class {{clientName}} {

Dio dio;
Serializers serializers;
String basePath = "{{{basePath}}}";
String basePath = '{{{basePath}}}';

{{clientName}}({this.dio, Serializers serializers, String basePathOverride, List<Interceptor> interceptors}) {
if (dio == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ part '{{classFilename}}.g.dart';
abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builder> {

{{#vars}}
{{#description}}/* {{{description}}} */{{/description}}
{{#description}}
/// {{{description}}}
{{/description}}
{{#isNullable}}
@nullable
{{/isNullable}}
@BuiltValueField(wireName: r'{{baseName}}')
{{{datatypeWithEnum}}} get {{name}};
{{#allowableValues}}
{{#min}}// range from {{min}} to {{max}}{{/min}}//{{^min}} enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}
// {{#min}}range from {{{min}}} to {{{max}}}{{/min}}{{^min}}enum {{name}}Enum { {{#values}} {{{.}}}, {{/values}} };{{/min}}
{{/allowableValues}}
{{/vars}}

{{/vars}}
// Boilerplate code needed to wire-up generated code
{{classname}}._();

Expand All @@ -42,4 +44,4 @@ abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builde
{{/mostInnerItems}}
{{/isContainer}}
{{/isEnum}}
{{/vars}}
{{/vars}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OffsetDateSerializer implements PrimitiveSerializer<OffsetDate> {
Iterable<Type> get types => BuiltList<Type>([OffsetDate]);

@override
String get wireName => "OffsetDate";
String get wireName => 'OffsetDate';

@override
OffsetDate deserialize(Serializers serializers, Object serialized,
Expand All @@ -28,7 +28,7 @@ class OffsetDateTimeSerializer implements PrimitiveSerializer<OffsetDateTime> {
Iterable<Type> get types => BuiltList<Type>([OffsetDateTime]);

@override
String get wireName => "OffsetDateTime";
String get wireName => 'OffsetDateTime';

@override
OffsetDateTime deserialize(Serializers serializers, Object serialized,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:{{pubName}}/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{{dataType}}}**]({{complexType}}.md){{/isPrimitiveType}} | {{{description}}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{/vars}}

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class {{{classname}}} {
});

{{#vars}}
{{#description}}/// {{{description}}}{{/description}}
{{#description}}
/// {{{description}}}
{{/description}}
{{^isEnum}}
{{#minimum}}
// minimum: {{{minimum}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Name | Type | Description | Notes
**id** | **int** | | [optional] [default to null]
**category** | [**Category**](Category.md) | | [optional] [default to null]
**name** | **String** | | [default to null]
**photoUrls** | **BuiltList&lt;String&gt;** | | [default to const []]
**tags** | [**BuiltList&lt;Tag&gt;**](Tag.md) | | [optional] [default to const []]
**photoUrls** | **BuiltList<String>** | | [default to const []]
**tags** | [**BuiltList<Tag>**](Tag.md) | | [optional] [default to const []]
**status** | **String** | pet status in the store | [optional] [default to null]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
20 changes: 10 additions & 10 deletions samples/client/petstore/dart-dio/petstore_client_lib/doc/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
api_instance.addPet(body);
} catch (e) {
print("Exception when calling PetApi->addPet: $e\n");
print('Exception when calling PetApi->addPet: $e\n');
}
```

Expand Down Expand Up @@ -79,7 +79,7 @@ var apiKey = apiKey_example; // String |
try {
api_instance.deletePet(petId, apiKey);
} catch (e) {
print("Exception when calling PetApi->deletePet: $e\n");
print('Exception when calling PetApi->deletePet: $e\n');
}
```

Expand Down Expand Up @@ -125,15 +125,15 @@ try {
var result = api_instance.findPetsByStatus(status);
print(result);
} catch (e) {
print("Exception when calling PetApi->findPetsByStatus: $e\n");
print('Exception when calling PetApi->findPetsByStatus: $e\n');
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**status** | [**BuiltList&lt;String&gt;**](String.md)| Status values that need to be considered for filter | [default to const []]
**status** | [**BuiltList<String>**](String.md)| Status values that need to be considered for filter | [default to const []]

### Return type

Expand Down Expand Up @@ -170,15 +170,15 @@ try {
var result = api_instance.findPetsByTags(tags);
print(result);
} catch (e) {
print("Exception when calling PetApi->findPetsByTags: $e\n");
print('Exception when calling PetApi->findPetsByTags: $e\n');
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**tags** | [**BuiltList&lt;String&gt;**](String.md)| Tags to filter by | [default to const []]
**tags** | [**BuiltList<String>**](String.md)| Tags to filter by | [default to const []]

### Return type

Expand Down Expand Up @@ -217,7 +217,7 @@ try {
var result = api_instance.getPetById(petId);
print(result);
} catch (e) {
print("Exception when calling PetApi->getPetById: $e\n");
print('Exception when calling PetApi->getPetById: $e\n');
}
```

Expand Down Expand Up @@ -259,7 +259,7 @@ var body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
api_instance.updatePet(body);
} catch (e) {
print("Exception when calling PetApi->updatePet: $e\n");
print('Exception when calling PetApi->updatePet: $e\n');
}
```

Expand Down Expand Up @@ -303,7 +303,7 @@ var status = status_example; // String | Updated status of the pet
try {
api_instance.updatePetWithForm(petId, name, status);
} catch (e) {
print("Exception when calling PetApi->updatePetWithForm: $e\n");
print('Exception when calling PetApi->updatePetWithForm: $e\n');
}
```

Expand Down Expand Up @@ -350,7 +350,7 @@ try {
var result = api_instance.uploadFile(petId, additionalMetadata, file);
print(result);
} catch (e) {
print("Exception when calling PetApi->uploadFile: $e\n");
print('Exception when calling PetApi->uploadFile: $e\n');
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var orderId = orderId_example; // String | ID of the order that needs to be dele
try {
api_instance.deleteOrder(orderId);
} catch (e) {
print("Exception when calling StoreApi->deleteOrder: $e\n");
print('Exception when calling StoreApi->deleteOrder: $e\n');
}
```

Expand Down Expand Up @@ -78,7 +78,7 @@ try {
var result = api_instance.getInventory();
print(result);
} catch (e) {
print("Exception when calling StoreApi->getInventory: $e\n");
print('Exception when calling StoreApi->getInventory: $e\n');
}
```

Expand Down Expand Up @@ -118,7 +118,7 @@ try {
var result = api_instance.getOrderById(orderId);
print(result);
} catch (e) {
print("Exception when calling StoreApi->getOrderById: $e\n");
print('Exception when calling StoreApi->getOrderById: $e\n');
}
```

Expand Down Expand Up @@ -159,7 +159,7 @@ try {
var result = api_instance.placeOrder(body);
print(result);
} catch (e) {
print("Exception when calling StoreApi->placeOrder: $e\n");
print('Exception when calling StoreApi->placeOrder: $e\n');
}
```

Expand Down
Loading