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

swift4.api.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{#operations}}//
// {{classname}}.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation{{#usePromiseKit}}
import PromiseKit{{/usePromiseKit}}{{#useRxSwift}}
import RxSwift{{/useRxSwift}}

{{#swiftUseApiNamespace}}
extension {{projectName}}API {
{{/swiftUseApiNamespace}}

{{#description}}
/** {{.}} */{{/description}}
{{#objcCompatible}}@objc {{/objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class {{classname}}{{#objcCompatible}} : NSObject{{/objcCompatible}} {
{{#operation}}
    {{#allParams}}
    {{#isEnum}}
    /**
     * enum for parameter {{paramName}}
     */
    {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}_{{operationId}}: {{^isContainer}}{{{dataType}}}{{/isContainer}}{{#isContainer}}String{{/isContainer}} {
        {{#allowableValues}}
        {{#enumVars}}
        case {{name}} = {{{value}}}
        {{/enumVars}}
        {{/allowableValues}}
    }

    {{/isEnum}}
    {{/allParams}}
{{^usePromiseKit}}
{{^useRxSwift}}
    /**
     {{#summary}}
     {{{.}}}
     {{/summary}}{{#allParams}}
     - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/allParams}}
     - parameter completion: completion handler to receive the data and the error objects
     */
    {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}completion: @escaping ((_ data: {{{returnType}}}{{^returnType}}Void{{/returnType}}?,_ error: Error?) -> Void)) {
        {{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}).execute { (response, error) -> Void in
        {{#returnType}}
            completion(response?.body, error)
        {{/returnType}}
        {{^returnType}}
            if error == nil {
                completion((), error)
            } else {
                completion(nil, error)
            }
        {{/returnType}}
        }
    }
{{/useRxSwift}}
{{/usePromiseKit}}
{{#usePromiseKit}}
    /**
     {{#summary}}
     {{{.}}}
     {{/summary}}{{#allParams}}
     - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/allParams}}
     - returns: Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}>
     */
    {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}({{#allParams}} {{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {
        let deferred = Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}>.pending()
        {{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}).execute { (response, error) -> Void in
            if let error = error {
                deferred.resolver.reject(error)
{{#returnType}}
            } else if let response = response {
                deferred.resolver.fulfill(response.body!)
            } else {
                fatalError()
{{/returnType}}
{{^returnType}}
            } else {
                deferred.resolver.fulfill(())
{{/returnType}}
            }
        }
        return deferred.promise
    }
{{/usePromiseKit}}
{{#useRxSwift}}
    /**
     {{#summary}}
     {{{.}}}
     {{/summary}}{{#allParams}}
     - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/allParams}}
     - returns: Observable<{{{returnType}}}{{^returnType}}Void{{/returnType}}>
     */
    {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Observable<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {
        return Observable.create { observer -> Disposable in
            {{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}).execute { (response, error) -> Void in
                if let error = error {
                    observer.onError(error)
{{#returnType}}
                } else if let response = response {
                    observer.onNext(response.body!)
                } else {
                    fatalError()
{{/returnType}}
{{^returnType}}
                } else {
                    observer.onNext(())
{{/returnType}}
                }
                observer.onCompleted()
            }
            return Disposables.create()
        }
    }
{{/useRxSwift}}
{{#useResult}}
    /**
     {{#summary}}
     {{{.}}}
     {{/summary}}{{#allParams}}
     - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/allParams}}
     - parameter completion: completion handler to receive the result
     */
    open class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}completion: @escaping ((_ result: Result<{{{returnType}}}{{^returnType}}Void{{/returnType}}, Error>) -> Void)) {
        {{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}).execute { (response, error) -> Void in
            if let error = error {
                completion(.failure(error))
        {{#returnType}}
            } else if let response = response {
                completion(.success(response.body!))
            } else {
                fatalError()
            }
        {{/returnType}}
        {{^returnType}}
            } else {
                completion(.success(()))
            }
        {{/returnType}}
        }
    }
{{/useResult}}

    /**
     {{#summary}}
     {{{.}}}
     {{/summary}}
     - {{httpMethod}} {{{path}}}{{#notes}}
     - {{{.}}}{{/notes}}{{#subresourceOperation}}
     - subresourceOperation: {{.}}{{/subresourceOperation}}{{#defaultResponse}}
     - defaultResponse: {{.}}{{/defaultResponse}}
     {{#authMethods}}
     - {{#isBasic}}BASIC{{/isBasic}}{{#isOAuth}}OAuth{{/isOAuth}}{{#isApiKey}}API Key{{/isApiKey}}:
       - type: {{type}}{{#keyParamName}} {{keyParamName}} {{#isKeyInQuery}}(QUERY){{/isKeyInQuery}}{{#isKeyInHeaer}}(HEADER){{/isKeyInHeaer}}{{/keyParamName}}
       - name: {{name}}
       {{/authMethods}}
     {{#hasResponseHeaders}}
     - responseHeaders: [{{#responseHeaders}}{{{baseName}}}({{{dataType}}}){{^-last}}, {{/-last}}{{/responseHeaders}}]
     {{/hasResponseHeaders}}
     {{#externalDocs}}
     - externalDocs: {{.}}
     {{/externalDocs}}
     {{#allParams}}
     - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
     {{/allParams}}
     - returns: RequestBuilder<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {{description}}
     */
    {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> RequestBuilder<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {
        {{^pathParams}}let{{/pathParams}}{{#pathParams}}{{#-first}}var{{/-first}}{{/pathParams}} path = "{{{path}}}"{{#pathParams}}
        let {{paramName}}PreEscape = "\({{#isEnum}}{{paramName}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}.rawValue{{/isContainer}}{{/isEnum}}{{^isEnum}}APIHelper.mapValueToPathItem({{paramName}}){{/isEnum}})"
        let {{paramName}}PostEscape = {{paramName}}PreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
        path = path.replacingOccurrences(of: "{{=<% %>=}}{<%baseName%>}<%={{ }}=%>", with: {{paramName}}PostEscape, options: .literal, range: nil){{/pathParams}}
        let URLString = {{projectName}}API.basePath + path
        {{#bodyParam}}
        let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: {{paramName}})
        {{/bodyParam}}
        {{^bodyParam}}
            {{#hasFormParams}}
        let formParams: [String:Any?] = [
                {{#formParams}}
            {{> _param}}{{^-last}},{{/-last}}
                {{/formParams}}
        ]

        let nonNullParameters = APIHelper.rejectNil(formParams)
        let parameters = APIHelper.convertBoolToString(nonNullParameters)
            {{/hasFormParams}}
            {{^hasFormParams}}
        let parameters: [String:Any]? = nil
            {{/hasFormParams}}
        {{/bodyParam}}{{#hasQueryParams}}
        var url = URLComponents(string: URLString)
        url?.queryItems = APIHelper.mapValuesToQueryItems([{{^queryParams}}:{{/queryParams}}
            {{#queryParams}}
            {{> _param}}{{^-last}}, {{/-last}}
            {{/queryParams}}
        ]){{/hasQueryParams}}{{^hasQueryParams}}
        let url = URLComponents(string: URLString){{/hasQueryParams}}{{#headerParams}}{{#-first}}
        let nillableHeaders: [String: Any?] = [{{/-first}}
            {{> _param}}{{^-last}},{{/-last}}{{#-last}}
        ]
        let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders){{/-last}}{{/headerParams}}

        let requestBuilder: RequestBuilder<{{{returnType}}}{{^returnType}}Void{{/returnType}}>.Type = {{projectName}}API.requestBuilderFactory.{{#returnType}}getBuilder(){{/returnType}}{{^returnType}}getNonDecodableBuilder(){{/returnType}}

        return requestBuilder.init(method: "{{httpMethod}}", URLString: (url?.string ?? URLString), parameters: parameters, isBody: {{hasBodyParam}}{{#headerParams}}{{#-first}}, headers: headerParameters{{/-first}}{{/headerParams}})
    }

{{/operation}}
}
{{#swiftUseApiNamespace}}
}
{{/swiftUseApiNamespace}}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy