All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart2.api.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>header}}
{{>part_of}}
{{#operations}}

class {{{classname}}} {
  {{{classname}}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;

  final ApiClient apiClient;
  {{#operation}}

  {{#summary}}
  /// {{{summary}}}
  {{/summary}}
  {{#notes}}
    {{#summary}}
  ///
    {{/summary}}
  /// {{{notes}}}
  ///
  /// Note: This method returns the HTTP [Response].
  {{/notes}}
  {{^notes}}
    {{#summary}}
  ///
  /// Note: This method returns the HTTP [Response].
    {{/summary}}
    {{^summary}}
  /// Performs an HTTP '{{{httpMethod}}} {{{path}}}' operation and returns the [Response].
    {{/summary}}
  {{/notes}}
  {{#hasParams}}
    {{#summary}}
  ///
    {{/summary}}
    {{^summary}}
      {{#notes}}
  ///
      {{/notes}}
    {{/summary}}
  /// Parameters:
  ///
  {{/hasParams}}
  {{#allParams}}
  /// * [{{{dataType}}}] {{{paramName}}}{{#required}} (required){{/required}}{{#optional}} (optional){{/optional}}:
    {{#description}}
  ///   {{{description}}}
    {{/description}}
    {{^-last}}
  ///
    {{/-last}}
  {{/allParams}}
  Future {{{nickname}}}WithHttpInfo({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async {
  {{#hasParams}}
    // Verify required params are set.
    {{#allParams}}
      {{#required}}
    if ({{{paramName}}} == null) {
     throw ApiException(HttpStatus.badRequest, 'Missing required param: {{{paramName}}}');
    }
      {{/required}}
    {{/allParams}}

  {{/hasParams}}
    final path = '{{{path}}}'.replaceAll('{format}', 'json'){{#pathParams}}
      .replaceAll('{' + '{{{baseName}}}' + '}', {{{paramName}}}.toString()){{/pathParams}};

    Object postBody{{#bodyParam}} = {{{paramName}}}{{/bodyParam}};

    final queryParams = [];
    final headerParams = {};
    final formParams = {};
    {{#hasQueryParams}}

      {{#queryParams}}
        {{^required}}
    if ({{{paramName}}} != null) {
          {{/required}}
      queryParams.addAll(_convertParametersForCollectionFormat('{{{collectionFormat}}}', '{{{baseName}}}', {{{paramName}}}));
          {{^required}}
    }
        {{/required}}
      {{/queryParams}}
    {{/hasQueryParams}}
    {{#hasHeaderParams}}

      {{#headerParams}}
        {{#required}}
    headerParams[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
        {{/required}}
        {{^required}}
    if ({{{paramName}}} != null) {
      headerParams[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
    }
        {{/required}}
      {{/headerParams}}
    {{/hasHeaderParams}}

    final contentTypes = [{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}];
    final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
    final authNames = [{{#authMethods}}'{{{name}}}'{{^-last}}, {{/-last}}{{/authMethods}}];

    if (
      nullableContentType != null &&
      nullableContentType.toLowerCase().startsWith('multipart/form-data')
    ) {
      bool hasFields = false;
      final mp = MultipartRequest(null, null);
      {{#formParams}}
      {{^isFile}}
      if ({{{paramName}}} != null) {
        hasFields = true;
        mp.fields[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
      }
      {{/isFile}}
      {{#isFile}}
      if ({{{paramName}}} != null) {
        hasFields = true;
        mp.fields[r'{{{baseName}}}'] = {{{paramName}}}.field;
        mp.files.add({{{paramName}}});
      }
      {{/isFile}}
      {{/formParams}}
      if (hasFields) {
        postBody = mp;
      }
    } else {
      {{#formParams}}
      {{^isFile}}
      if ({{{paramName}}} != null) {
        formParams[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
      }
      {{/isFile}}
      {{/formParams}}
    }

    return await apiClient.invokeAPI(
      path,
      '{{{httpMethod}}}',
      queryParams,
      postBody,
      headerParams,
      formParams,
      nullableContentType,
      authNames,
    );
  }

  {{#summary}}
  /// {{{summary}}}
  {{/summary}}
  {{#notes}}
  {{#summary}}
  ///
  {{/summary}}
  /// {{{notes}}}
  {{/notes}}
  {{#hasParams}}
    {{#summary}}
  ///
    {{/summary}}
    {{^summary}}
      {{#notes}}
  ///
      {{/notes}}
    {{/summary}}
  /// Parameters:
  ///
  {{/hasParams}}
  {{#allParams}}
  /// * [{{{dataType}}}] {{{paramName}}}{{#required}} (required){{/required}}{{#optional}} (optional){{/optional}}:
    {{#description}}
  ///   {{{description}}}
    {{/description}}
    {{^-last}}
  ///
    {{/-last}}
  {{/allParams}}
  Future<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{{nickname}}}({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async {
    final response = await {{{nickname}}}WithHttpInfo({{#allParams}}{{#required}}{{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}} {{#allParams}}{{^required}}{{{paramName}}}: {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}} {{/hasOptionalParams}});
    if (response.statusCode >= HttpStatus.badRequest) {
      throw ApiException(response.statusCode, _decodeBodyBytes(response));
    }
    {{#returnType}}
    // When a remote server returns no body with a status of 204, we shall not decode it.
    // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
    // FormatException when trying to decode an empty string.
    if (response.body != null && response.statusCode != HttpStatus.noContent) {
      {{#isArray}}
      return (apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as List)
        .cast<{{{returnBaseType}}}>()
        .{{#uniqueItems}}toSet(){{/uniqueItems}}{{^uniqueItems}}toList(growable: false){{/uniqueItems}};
      {{/isArray}}
      {{^isArray}}
        {{#isMap}}
      return {{{returnType}}}.from(apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}'));
        {{/isMap}}
        {{^isMap}}
      return apiClient.deserialize(_decodeBodyBytes(response), '{{{returnType}}}') as {{{returnType}}};
        {{/isMap}}
      {{/isArray}}
    }
    return null;
    {{/returnType}}
  }
  {{/operation}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy