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

v2.swift3.model.mustache Maven / Gradle / Ivy

The newest version!
{{#models}}{{#model}}//
// {{classname}}.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation

{{#description}}

/** {{description}} */{{/description~}}
{{#is this 'array-model'}}
public typealias {{classname}} = [{{arrayModelType}}]
{{/is~}}
{{#isNot this 'array-model'}}{{#is this 'enum'}}
public enum {{classname}}: {{dataType}} {
{{#allowableValues}}{{#enumVars}}    case {{name}} = "{{{value}}}"
{{/enumVars}}{{/allowableValues}}
    func encodeToJSON() -> Any { return self.rawValue }
}
{{/is~}}
{{#isNot this 'enum'}}
open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}JSONEncodable{{/parent}} {
{{#vars}}{{#is this 'enum'}}
    public enum {{enumName}}: {{#isNot this 'container'}}{{datatype}}{{/isNot}}{{#is this 'container'}}String{{/is}} { {{#allowableValues}}{{#enumVars}}
        case {{name}} = {{#is ../../this 'container'}}"{{/is}}{{#is ../../this 'string'}}"{{/is}}{{{value}}}{{#is ../../this 'string'}}"{{/is}}{{#is ../../this 'container'}}"{{/is}}{{/enumVars}}{{/allowableValues}}
    }
{{/is~}}
{{/vars}}
{{#vars}}{{#is this 'enum'}}    {{#description}}/** {{description}} */
    {{/description}}public var {{name}}: {{{datatypeWithEnum}}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
{{/is~}}
{{#isNot this 'enum'}}    {{#description}}/** {{description}} */
    {{/description}}public var {{name}}: {{{datatype}}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#objcCompatible}}{{#vendorExtensions.x-swift-optional-scalar}}
    public var {{name}}Num: NSNumber? {
        get {
            return {{name}}.map({ return NSNumber(value: $0) })
        }
    }{{/vendorExtensions.x-swift-optional-scalar}}{{/objcCompatible}}
{{/isNot~}}
{{/vars~}}

{{#additionalPropertiesType}}
    public var additionalProperties: [AnyHashable:{{{additionalPropertiesType}}}] = [:]

{{/additionalPropertiesType~}}
{{^unwrapRequired}}
    {{^parent}}public init() {}{{/parent}}{{/unwrapRequired}}
{{#unwrapRequired}}
    public init({{#allVars}}{{^@first}}, {{/@first}}{{name}}: {{#is this 'enum'}}{{datatypeWithEnum}}{{/is}}{{#isNot this 'enum'}}{{datatype}}{{/isNot}}{{^required}}?=nil{{/required}}{{/allVars}}) {
        {{#vars}}
        self.{{name}} = {{name}}
        {{/vars}}
    }{{/unwrapRequired~}}
{{#additionalPropertiesType}}
    public subscript(key: AnyHashable) -> {{{additionalPropertiesType}}}? {
        get {
            if let value = additionalProperties[key] {
                return value
            }
            return nil
        }

        set {
            additionalProperties[key] = newValue
        }
    }
{{/additionalPropertiesType}}
    // MARK: JSONEncodable
    {{#parent}}override {{/parent}}open func encodeToJSON() -> Any {
        var nillableDictionary = {{#parent}}super.encodeToJSON() as? [String:Any?] ?? {{/parent}}[String:Any?](){{#vars}}{{#is this 'not-container'}}{{#is this 'primitive-type'}}{{#isNot this 'enum'}}{{#is this 'integer'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/is}}{{#is this 'long'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/is}}{{#isNot this 'long'}}{{#isNot this 'integer'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{/isNot}}{{/isNot}}{{/isNot}}{{/is}}{{#is this 'enum'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.rawValue{{/is}}{{#isNot this 'primitive-type'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isNot}}{{/is}}{{#is this 'container'}}{{#isNot this 'enum'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isNot}}{{#is this 'enum'}}{{#is this 'list-container'}}
        nillableDictionary["{{baseName}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.map({$0.rawValue}).encodeToJSON(){{/is}}{{#is this 'map-container'}}//TODO: handle enum map scenario{{/is}}{{/is}}{{/is}}{{/vars}}

        {{#additionalPropertiesType}}
        for (key, value) in additionalProperties {
            if let key = key as? String {
               nillableDictionary[key] = value
            }
        }

        {{/additionalPropertiesType~}}
        let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
        return dictionary
    }
}
{{/isNot}}{{/isNot}}{{/model}}{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy