Skip to content
Open
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
2 changes: 1 addition & 1 deletion bin/generate-v3
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ docker run \
--input-spec ${SWAGGER_FILE} \
--generator-name dart \
--output /local/dart-v3 \
--template-dir /local/dart-templates
--template-dir /local/dart-v3-templates

sleep 3

Expand Down
145 changes: 145 additions & 0 deletions dart-v3-templates/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# {{{pubName}}}
{{#appDescriptionWithNewLines}}
{{{appDescriptionWithNewLines}}}
{{/appDescriptionWithNewLines}}

This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: {{{appVersion}}}
{{#artifactVersion}}
- Package version: {{{artifactVersion}}}
{{/artifactVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{{generatedDate}}}
{{/hideGenerationTimestamp}}
- Build package: {{{generatorClass}}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Requirements

Dart 2.0 or later

## Installation & Usage

### Github
If this Dart package is published to Github, add the following dependency to your pubspec.yaml
```
dependencies:
{{{pubName}}}:
git: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}.git
```

### Local
To use the package in your local drive, add the following dependency to your pubspec.yaml
```
dependencies:
{{{pubName}}}:
path: /path/to/{{{pubName}}}
```

## Tests

TODO

## Getting Started

Please follow the [installation procedure](#installation--usage) and then run the following:

```dart
import 'package:{{{pubName}}}/api.dart';
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
// TODO Configure HTTP basic authorization: {{{name}}}
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
{{/isBasicBasic}}
{{#isBasicBearer}}
// TODO Configure HTTP Bearer authorization: {{{name}}}
// Case 1. Use String Token
//defaultApiClient.getAuthentication<HttpBearerAuth>('{{{name}}}').setAccessToken('YOUR_ACCESS_TOKEN');
// Case 2. Use Function which generate token.
// String yourTokenGeneratorFunction() { ... }
//defaultApiClient.getAuthentication<HttpBearerAuth>('{{{name}}}').setAccessToken(yourTokenGeneratorFunction);
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
// TODO Configure API key authorization: {{{name}}}
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKeyPrefix = 'Bearer';
{{/isApiKey}}
{{#isOAuth}}
// TODO Configure OAuth2 access token for authorization: {{{name}}}
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}

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

try {
{{#returnType}}final result = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
{{#returnType}}
print(result);
{{/returnType}}
} catch (e) {
print('Exception when calling {{{classname}}}->{{{operationId}}}: $e\n');
}
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```

## Documentation for API Endpoints

All URIs are relative to *{{{basePath}}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{{classname}}}* | [**{{{operationId}}}**]({{{apiDocPath}}}/{{{classname}}}.md#{{{operationIdLowerCase}}}) | **{{{httpMethod}}}** {{{path}}} | {{#summary}}{{{summary}}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Documentation For Models

{{#models}}{{#model}} - [{{{classname}}}]({{{modelDocPath}}}/{{{classname}}}.md)
{{/model}}{{/models}}

## Documentation For Authorization

{{^authMethods}} All endpoints do not require authorization.
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
{{#authMethods}}## {{{name}}}

{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP Basic authentication
{{/isBasicBasic}}
{{#isBasicBearer}}
- **Type**: HTTP Bearer authentication
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}

## Author

{{#apiInfo}}{{#apis}}{{#-last}}{{{infoEmail}}}
{{/-last}}{{/apis}}{{/apiInfo}}

1 change: 1 addition & 0 deletions dart-v3-templates/analysis_options.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
analyzer:
202 changes: 202 additions & 0 deletions dart-v3-templates/api.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{{>header}}
{{>part_of}}
{{#operations}}

class {{classname}} {
const {{classname}}(this._apiClient);

final {{clientName}} _apiClient;

{{#operation}}
/// {{#summary}}{{.}}{{/summary}}{{^summary}}{{nickname}}{{/summary}}
/// {{notes}}
///
/// Parameters:
{{#allParams}}
/// * [{{paramName}}] {{#description}}- {{{.}}}{{/description}}
{{/allParams}}
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
/// * [headers] - Can be used to add additional headers to the request
/// * [extras] - Can be used to add flags to the request
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
///
/// Returns a [Future]{{#returnType}} containing a [Response] with a [{{{returnType}}}] as data{{/returnType}}
/// Throws [DioException] if API call or serialization fails
{{#externalDocs}}
/// {{description}}
/// Also see [{{summary}} Documentation]({{url}})
{{/externalDocs}}
{{#isDeprecated}}
@Deprecated('This operation has been deprecated')
{{/isDeprecated}}
Future<Response<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {{nickname}}({ {{#allParams}}{{#isPathParam}}
required {{{dataType}}} {{paramName}},{{/isPathParam}}{{#isQueryParam}}
{{#required}}required {{/required}}{{{dataType}}}{{^required}}?{{/required}} {{paramName}},{{/isQueryParam}}{{#isHeaderParam}}
{{#required}}required {{/required}}{{{dataType}}}{{^required}}?{{/required}} {{paramName}},{{/isHeaderParam}}{{#isBodyParam}}
{{#required}}required {{/required}}{{{dataType}}}{{^required}}?{{/required}} {{paramName}},{{/isBodyParam}}{{#isFormParam}}
{{#required}}required {{/required}}{{{dataType}}}{{^required}}?{{/required}} {{paramName}},{{/isFormParam}}{{/allParams}}
{{#hasConsumes}}{{#hasBodyParam}}Iterable<String>? bodyParameters,{{/hasBodyParam}}{{/hasConsumes}}
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final String path = r'{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{{baseName}}}' '}', {{{paramName}}}.toString()){{/pathParams}};
final options = Options(
method: r'{{#lambda.uppercase}}{{httpMethod}}{{/lambda.uppercase}}',
{{#isResponseFile}}
responseType: ResponseType.bytes,
{{/isResponseFile}}
headers: <String, dynamic>{
{{#httpUserAgent}}
r'User-Agent': r'{{{.}}}',
{{/httpUserAgent}}
// to string ??
{{#headerParams}}
{{^required}}{{^nullable}}if ({{{paramName}}} != null) {{/nullable}}{{/required}}r'{{baseName}}': {{paramName}},
{{/headerParams}}
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[{{^hasAuthMethods}}],{{/hasAuthMethods}}{{#hasAuthMethods}}
{{#authMethods}}{
'type': '{{type}}',
{{#scheme}}'scheme': '{{scheme}}',{{/scheme}}
'name': '{{name}}',{{#isApiKey}}
'keyName': '{{keyParamName}}',
'where': '{{#isKeyInQuery}}query{{/isKeyInQuery}}{{#isKeyInHeader}}header{{/isKeyInHeader}}',{{/isApiKey}}
},{{/authMethods}}
],{{/hasAuthMethods}}
...?extra,
},
{{#hasConsumes}}contentType: '{{#prioritizedContentTypes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/prioritizedContentTypes}}',{{/hasConsumes}}
validateStatus: validateStatus,
);

{{#hasQueryParams}}
final queryParameters = <String, dynamic>{
{{#queryParams}}
{{^required}}{{^isNullable}}if ({{{paramName}}} != null) {{/isNullable}}{{/required}}r'{{baseName}}':
{{#isContainer}}encodeCollectionQueryParameter{{/isContainer}}{{^isContainer}}encodeQueryParameter{{/isContainer}}(
{{{paramName}}}{{#isContainer}},
format: ListFormat.{{{collectionFormat}}}{{/isContainer}}
),
{{/queryParams}}
};
{{/hasQueryParams}}

{{#hasBodyOrFormParams}}
dynamic bodyData;

try {
{{#hasFormParams}}
{{#isMultipart}}
bodyData = FormData.fromMap(<String, dynamic>{
{{#formParams}}
{{^required}}{{^isNullable}}if ({{{paramName}}} != null) {{/isNullable}}{{/required}}r'{{{baseName}}}': {{#isFile}}{{{paramName}}}{{/isFile}}{{^isFile}}encodeFormParameter({{{paramName}}}){{/isFile}},
{{/formParams}}
});
{{/isMultipart}}
{{^isMultipart}}
bodyData = <String, dynamic>{
{{#formParams}}
{{^required}}
{{^isNullable}}if ({{{paramName}}} != null) {{/isNullable}}
{{/required}}
r'{{{baseName}}}': {{#isContainer}}encodeCollectionQueryParameter{{/isContainer}}{{^isContainer}}encodeQueryParameter{{/isContainer}}(
{{{paramName}}},
{{#isContainer}}
format: ListFormat.{{{collectionFormat}}}
{{/isContainer}}
),
{{/formParams}}
};
{{/isMultipart}}
{{/hasFormParams}}
{{#bodyParam}}
{{#isPrimitiveType}}
bodyData = {{paramName}}{{#isFile}}.finalize(){{/isFile}};
{{/isPrimitiveType}}
{{^isPrimitiveType}}
bodyData = {{paramName}}{{^required}}?{{/required}}.toJson(bodyParameters);
{{/isPrimitiveType}}
{{/bodyParam}}
} catch(error, stackTrace) {
throw DioException(
error: error,
requestOptions: options.compose(
_apiClient.dio.options,
path,
{{#hasQueryParams}}
queryParameters: queryParameters,
{{/hasQueryParams}}
),
stackTrace: stackTrace,
type: DioExceptionType.unknown,
);
}
{{/hasBodyOrFormParams}}

{{#returnType}}final response = await{{/returnType}}{{^returnType}}return{{/returnType}} _apiClient.dio.request<Object>(
path,
{{#hasBodyOrFormParams}}
data: bodyData,
{{/hasBodyOrFormParams}}
options: options,
{{#hasQueryParams}}
queryParameters: queryParameters,
{{/hasQueryParams}}
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);

{{#returnType}}
{{{returnType}}} responseData;

try {
{{#isResponseFile}}
responseData = response.data as {{{returnType}}};
{{/isResponseFile}}
{{^isResponseFile}}
{{#returnSimpleType}}
{{#returnTypeIsPrimitive}}
responseData = response.data as {{{returnType}}};
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
responseData = await _apiClient.deserializeAsync<{{{returnType}}}>(response.data!, '{{{returnType}}}');
{{/returnTypeIsPrimitive}}
{{/returnSimpleType}}
{{^returnSimpleType}}
responseData = await _apiClient.deserializeAsync<{{{returnType}}}>(response.data!, '{{{returnType}}}');
{{/returnSimpleType}}
{{/isResponseFile}}
} catch (error, stackTrace) {
throw DioException(
error: error,
requestOptions: response.requestOptions,
response: response,
stackTrace: stackTrace,
type: DioExceptionType.unknown,
);
}

return Response<{{{returnType}}}>(
data: responseData,
headers: response.headers,
isRedirect: response.isRedirect,
requestOptions: response.requestOptions,
redirects: response.redirects,
statusCode: response.statusCode,
statusMessage: response.statusMessage,
extra: response.extra,
);
{{/returnType}}
}
{{/operation}}
}
{{/operations}}
Loading