swagger-api / swagger-api/swagger-codegen
[Swift4] DefaultValue variable used in mustache template appears to not exist?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Order.swift model and the Swift4 Mustache template containing the defaultValue reference. Reproduce generation with the documented swagger-codegen command and inspect the debugModels output for the complete property. Done means the generated Swift model applies the schema's false default value, with generation output matching the intended template behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100