handlebars.dart.api.mustache Maven / Gradle / Ivy
part of {{pubName}}.api;
{{#operations}}
class {{classname}} {
final ApiClient apiClient;
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
{{#operation}}
{{#contents}}
{{#@first}}
/// {{summary}}
///
/// {{notes}}
{{#isDeprecated}}
@deprecated
{{/isDeprecated}}
{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}({{#parameters}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/parameters}}{{#hasOptionalParams}}{ {{#parameters}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/parameters}} }{{/hasOptionalParams}}) async {
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
// verify required params are set
{{#parameters}}
{{#required}}
if({{paramName}} == null) {
throw new ApiException(400, "Missing required param: {{paramName}}");
}
{{/required}}
{{/parameters}}
// create path and map variables
String path = "{{{path}}}".replaceAll("{format}","json"){{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}};
// query params
List queryParams = [];
Map headerParams = {};
Map formParams = {};
{{#queryParams}}
{{^required}}
if({{paramName}} != null) {
{{/required}}
queryParams.addAll(_convertParametersForCollectionFormat("{{collectionFormat}}", "{{baseName}}", {{paramName}}));
{{^required}}
}
{{/required}}
{{/queryParams}}
{{#headerParams}}headerParams["{{baseName}}"] = {{paramName}};
{{/headerParams}}
List contentTypes = [{{#consumes}}"{{{mediaType}}}"{{#hasMore}},{{/hasMore}}{{/consumes}}];
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
List authNames = [{{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
if(contentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = new MultipartRequest(null, null);
{{#formParams}}{{#notFile}}
if ({{paramName}} != null) {
hasFields = true;
mp.fields['{{baseName}}'] = parameterToString({{paramName}});
}
{{/notFile}}{{#isFile}}
if ({{paramName}} != null) {
hasFields = true;
mp.fields['{{baseName}}'] = {{paramName}}.field;
mp.files.add({{paramName}});
}
{{/isFile}}{{/formParams}}
if(hasFields)
postBody = mp;
}
else {
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
formParams['{{baseName}}'] = parameterToString({{paramName}});{{/notFile}}
{{/formParams}}
}
var response = await apiClient.invokeAPI(path,
'{{httpMethod}}',
queryParams,
postBody,
headerParams,
formParams,
contentType,
authNames);
if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
} else if(response.body != null) {
return
{{#isListContainer}}
{{#returnType}}(apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList();{{/returnType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isMapContainer}}
{{#returnType}}new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')) {{/returnType}};
{{/isMapContainer}}
{{^isMapContainer}}
{{#returnType}}apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}} {{/returnType}};
{{/isMapContainer}}
{{/isListContainer}}
} else {
return {{#returnType}}null{{/returnType}};
}
}
{{/@first}}
{{/contents}}
{{/operation}}
}
{{/operations}}