Skip to content

Commit 96da8a3

Browse files
committed
added dart templates
1 parent bc7d0bd commit 96da8a3

19 files changed

+843
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# {{pubName}}
2+
{{#appDescription}}
3+
{{{appDescription}}}
4+
{{/appDescription}}
5+
6+
This Dart package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
7+
8+
- API version: {{appVersion}}
9+
{{#artifactVersion}}
10+
- Package version: {{artifactVersion}}
11+
{{/artifactVersion}}
12+
{{^hideGenerationTimestamp}}
13+
- Build date: {{generatedDate}}
14+
{{/hideGenerationTimestamp}}
15+
- Build package: {{generatorClass}}
16+
{{#infoUrl}}
17+
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
18+
{{/infoUrl}}
19+
20+
## Requirements
21+
22+
Dart 1.20.0 or later OR Flutter 0.0.20 or later
23+
24+
## Installation & Usage
25+
26+
### Github
27+
If this Dart package is published to Github, please include the following in pubspec.yaml
28+
```
29+
name: {{pubName}}
30+
version: {{pubVersion}}
31+
description: {{pubDescription}}
32+
dependencies:
33+
{{pubName}}:
34+
git: https://github.com/{{gitUserId}}/{{gitRepoId}}.git
35+
version: 'any'
36+
```
37+
38+
### Local
39+
To use the package in your local drive, please include the following in pubspec.yaml
40+
```
41+
dependencies:
42+
{{pubName}}:
43+
path: /path/to/{{pubName}}
44+
```
45+
46+
## Tests
47+
48+
TODO
49+
50+
## Getting Started
51+
52+
Please follow the [installation procedure](#installation--usage) and then run the following:
53+
54+
```dart
55+
import 'package:{{pubName}}/api.dart';
56+
{{#apiInfo}}{{#apis}}{{#@first}}{{#operations}}{{#operation}}{{#@first}}
57+
{{#hasAuthMethods}}
58+
{{#authMethods}}
59+
{{#isBasic}}
60+
// TODO Configure HTTP basic authorization: {{{name}}}
61+
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
62+
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
63+
{{/isBasic}}
64+
{{#isApiKey}}
65+
// TODO Configure API key authorization: {{{name}}}
66+
//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
67+
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
68+
//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer";
69+
{{/isApiKey}}
70+
{{#isOAuth}}
71+
// TODO Configure OAuth2 access token for authorization: {{{name}}}
72+
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
73+
{{/isOAuth}}
74+
{{/authMethods}}
75+
{{/hasAuthMethods}}
76+
77+
var api_instance = new {{classname}}();
78+
{{#allParams}}
79+
var {{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}new {{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; // {{{dataType}}} | {{{description}}}
80+
{{/allParams}}
81+
82+
try {
83+
{{#returnType}}var result = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
84+
{{#returnType}}
85+
print(result);
86+
{{/returnType}}
87+
} catch (e) {
88+
print("Exception when calling {{classname}}->{{operationId}}: $e\n");
89+
}
90+
{{/@first}}{{/operation}}{{/operations}}{{/@first}}{{/apis}}{{/apiInfo}}
91+
```
92+
93+
## Documentation for API Endpoints
94+
95+
All URIs are relative to *{{basePath}}*
96+
97+
Class | Method | HTTP request | Description
98+
------------ | ------------- | ------------- | -------------
99+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}/{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
100+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
101+
102+
## Documentation For Models
103+
104+
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}/{{{classname}}}.md)
105+
{{/model}}{{/models}}
106+
107+
## Documentation For Authorization
108+
109+
{{^authMethods}} All endpoints do not require authorization.
110+
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
111+
{{#authMethods}}## {{{name}}}
112+
113+
{{#isApiKey}}- **Type**: API key
114+
- **API key parameter name**: {{{keyParamName}}}
115+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
116+
{{/isApiKey}}
117+
{{#isBasic}}- **Type**: HTTP basic authentication
118+
{{/isBasic}}
119+
{{#isOAuth}}- **Type**: OAuth
120+
- **Flow**: {{{flow}}}
121+
- **Authorization URL**: {{{authorizationUrl}}}
122+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
123+
{{#scopes}} - **{{{scope}}}**: {{{description}}}
124+
{{/scopes}}
125+
{{/isOAuth}}
126+
127+
{{/authMethods}}
128+
129+
## Author
130+
131+
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
132+
{{/hasMore}}{{/apis}}{{/apiInfo}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
analyzer:
2+
strong-mode: true
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
part of {{pubName}}.api;
2+
3+
{{#operations}}
4+
5+
6+
class {{classname}} {
7+
final ApiClient apiClient;
8+
9+
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
10+
11+
{{#operation}}
12+
/// {{summary}}
13+
///
14+
/// {{notes}}
15+
{{#isDeprecated}}
16+
@deprecated
17+
{{/isDeprecated}}
18+
{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async {
19+
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
20+
21+
// verify required params are set
22+
{{#allParams}}
23+
{{#required}}
24+
if({{paramName}} == null) {
25+
throw new ApiException(400, "Missing required param: {{paramName}}");
26+
}
27+
{{/required}}
28+
{{/allParams}}
29+
30+
// create path and map variables
31+
String path = "{{{path}}}".replaceAll("{format}","json"){{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}};
32+
33+
// query params
34+
List<QueryParam> queryParams = [];
35+
Map<String, String> headerParams = {};
36+
Map<String, String> formParams = {};
37+
{{#queryParams}}
38+
{{^required}}
39+
if({{paramName}} != null) {
40+
{{/required}}
41+
queryParams.addAll(_convertParametersForCollectionFormat("{{collectionFormat}}", "{{baseName}}", {{paramName}}));
42+
{{^required}}
43+
}
44+
{{/required}}
45+
{{/queryParams}}
46+
{{#headerParams}}headerParams["{{baseName}}"] = {{paramName}};
47+
{{/headerParams}}
48+
49+
List<String> contentTypes = [{{#consumes}}"{{{mediaType}}}"{{#hasMore}},{{/hasMore}}{{/consumes}}];
50+
51+
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
52+
List<String> authNames = [{{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
53+
54+
if(contentType.startsWith("multipart/form-data")) {
55+
bool hasFields = false;
56+
MultipartRequest mp = new MultipartRequest(null, null);
57+
{{#formParams}}{{#notFile}}
58+
if ({{paramName}} != null) {
59+
hasFields = true;
60+
mp.fields['{{baseName}}'] = parameterToString({{paramName}});
61+
}
62+
{{/notFile}}{{#isFile}}
63+
if ({{paramName}} != null) {
64+
hasFields = true;
65+
mp.fields['{{baseName}}'] = {{paramName}}.field;
66+
mp.files.add({{paramName}});
67+
}
68+
{{/isFile}}{{/formParams}}
69+
if(hasFields)
70+
postBody = mp;
71+
}
72+
else {
73+
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
74+
formParams['{{baseName}}'] = parameterToString({{paramName}});{{/notFile}}
75+
{{/formParams}}
76+
}
77+
78+
var response = await apiClient.invokeAPI(path,
79+
'{{httpMethod}}',
80+
queryParams,
81+
postBody,
82+
headerParams,
83+
formParams,
84+
contentType,
85+
authNames);
86+
87+
if(response.statusCode >= 400) {
88+
throw new ApiException(response.statusCode, response.body);
89+
} else if(response.body != null) {
90+
return
91+
{{#isListContainer}}
92+
{{#returnType}}(apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList();{{/returnType}}
93+
{{/isListContainer}}
94+
{{^isListContainer}}
95+
{{#isMapContainer}}
96+
{{#returnType}}new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')) {{/returnType}};
97+
{{/isMapContainer}}
98+
{{^isMapContainer}}
99+
{{#returnType}}apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}} {{/returnType}};
100+
{{/isMapContainer}}
101+
{{/isListContainer}}
102+
} else {
103+
return {{#returnType}}null{{/returnType}};
104+
}
105+
}
106+
{{/operation}}
107+
}
108+
{{/operations}}

0 commit comments

Comments
 (0)