swagger-codegen
swagger-codegen copied to clipboard
[Swift4] DefaultValue variable used in mustache template appears to not exist?
Description
It doesn't appear that the defaultValue variable is being generated when generating models with the language swift4.
Swagger-codegen version
2.4.0
Swagger declaration file content or url
definitions: {
Order: {
type: "object",
properties: {
id: {
type: "integer",
format: "int64"
},
petId: {
type: "integer",
format: "int64"
},
quantity: {
type: "integer",
format: "int32"
},
shipDate: {
type: "string",
format: "date-time"
},
status: {
type: "string",
description: "Order Status",
enum: [
"placed",
"approved",
"delivered"
]
},
complete: {
type: "boolean",
default: false
}
},
xml: {
name: "Order"
}
},
...
Command line used for generation
java -jar swagger-codegen-cli.jar generate \
-i https://petstore.swagger.io/v2/swagger.json \
-l swift4 -o /Users/.../.../.../.../.../SwaggerDemo -Dmodels
Steps to reproduce
- Run the above command to produce swift models based off of the https://petstore.swagger.io/v2/swagger.json Open Api Specification.
- Inspect the Order.swift model
- The Order.swift model contains a class definition that looks like this:
public struct Order: Codable {
public enum Status: String, Codable {
case placed = "placed"
case approved = "approved"
case delivered = "delivered"
}
public var _id: Int64?
public var petId: Int64?
public var quantity: Int?
public var shipDate: Date?
/** Order Status */
public var status: Status?
public var complete: Bool?
The complete Boolean property is defined with a default value, but the default value is not set:
complete: {
type: "boolean",
default: false
}
Related issues/PRs
Suggest a fix/enhancement
When I debug with -DdebugModels
java -DdebugModels -jar swagger-codegen-cli.jar generate \
-i petstorecomplete.json \
-l swift4
I see this output for the OrderClass:
{
"baseName" : "complete",
"getter" : "getComplete",
"setter" : "setComplete",
"datatype" : "Bool",
"datatypeWithEnum" : "Bool",
"name" : "complete",
"defaultValueWithParam" : " = data.complete;",
"baseType" : "Bool",
"jsonSchema" : "{\n \"type\" : \"boolean\",\n \"default\" : false\n}",
"exclusiveMinimum" : false,
"exclusiveMaximum" : false,
"hasMore" : false,
"required" : false,
"secondaryParam" : false,
"hasMoreNonReadOnly" : false,
"isPrimitiveType" : true,
"isContainer" : false,
"isNotContainer" : true,
"isString" : false,
"isNumeric" : false,
"isInteger" : false,
"isLong" : false,
"isNumber" : false,
"isFloat" : false,
"isDouble" : false,
"isByteArray" : false,
"isBinary" : false,
"isFile" : false,
"isBoolean" : true,
"isDate" : false,
"isDateTime" : false,
"isUuid" : false,
"isListContainer" : false,
"isMapContainer" : false,
"isEnum" : false,
"isReadOnly" : false,
"vendorExtensions" : {
"x-swift-optional-scalar" : true
},
"hasValidation" : false,
"isInherited" : false,
"nameInCamelCase" : "Complete",
"isXmlAttribute" : false,
"isXmlWrapped" : false
} ],
But the defaultValue parameter used in the mustache file doesn't seem to exist at all:
{{/description}}public var {{name}}: {{{datatype}}}{{^required}}?{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#objcCompatible}}{{#vendorExtensions.x-swift-optional-scalar}}
My only guess is that the defaultValue variable is no longer used or it's not being generated for some reason?
Thank you for any insight!
Im having the same issue