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

swift.model.mustache Maven / Gradle / Ivy

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

import Foundation

{{#description}}

/** {{description}} */{{/description}}
public class {{classname}}: JSONEncodable {
{{#vars}}
{{#isEnum}}
    public enum {{datatypeWithEnum}}: String { {{#allowableValues}}{{#values}}
        case {{enum}} = "{{raw}}"{{/values}}{{/allowableValues}}
    }
{{/isEnum}}
{{/vars}}
{{#vars}}
{{#isEnum}}
    {{#description}}/** {{description}} */
    {{/description}}public var {{name}}: {{{datatypeWithEnum}}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
{{/isEnum}}
{{^isEnum}}
    {{#description}}/** {{description}} */
    {{/description}}public var {{name}}: {{{dataType}}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
{{/isEnum}}
{{/vars}}

{{^unwrapRequired}}
    public init() {}
{{/unwrapRequired}}
{{#unwrapRequired}}
    public init({{#allVars}}{{^-first}}, {{/-first}}{{name}}: {{#isEnum}}{{datatypeWithEnum}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{^required}}?=nil{{/required}}{{/allVars}}) {
        {{#allVars}}
        self.{{name}} = {{name}}
        {{/allVars}}
    }
{{/unwrapRequired}}

    // MARK: JSONEncodable
    func encodeToJSON() -> AnyObject {
        var nillableDictionary = [String:AnyObject?](){{#vars}}{{^isContainer}}{{#isPrimitiveType}}{{^isEnum}}{{#isInteger}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isInteger}}{{#isLong}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isLong}}{{^isLong}}{{^isInteger}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{/isInteger}}{{/isLong}}{{/isEnum}}{{/isPrimitiveType}}{{#isEnum}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.rawValue{{/isEnum}}{{^isPrimitiveType}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isPrimitiveType}}{{/isContainer}}{{#isContainer}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isContainer}}{{/vars}}
        let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
        return dictionary
    }
}{{/model}}
{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy