I am using swagger-codegen-cli.jar to generate JSON with "-l swagger" from my input YAML. This tool does not include default values specified for integer properties in object types
2.2.3
Input YAML file:
swagger: '2.0'
info:
title: Settings API
contact:
name: Somebody
url: https://settings.com
email: [email protected]
description: Allows the user to get some settings
version: v1
host: api.settings.com
schemes:
- https
- http
basePath: /api/v1/stuff
produces:
- application/json
paths:
/settings:
get:
summary: Get the settings
responses:
200:
description: The settings
schema:
$ref: '#/definitions/Settings'
definitions:
Settings:
summary: The settings object
type: object
properties:
StringProperty:
type: string
summary: A string property
default: "Stringy"
BooleanProperty:
type: boolean
summary: A boolean property
default: true
IntProperty:
type: integer
summary: An integer property
default: 12345
Command line:
java -jar swagger-codegen-cli.jar generate -i input.yaml -l swagger -o .
Output JSON:
```json
{
"swagger" : "2.0",
"info" : {
"description" : "Allows the user to get some settings",
"version" : "v1",
"title" : "Settings API",
"contact" : {
"name" : "Somebody",
"url" : "https://settings.com",
"email" : "[email protected]"
}
},
"host" : "api.settings.com",
"basePath" : "/api/v1/stuff",
"schemes" : [ "https", "http" ],
"produces" : [ "application/json" ],
"paths" : {
"/settings" : {
"get" : {
"summary" : "Get the settings",
"parameters" : [ ],
"responses" : {
"200" : {
"description" : "The settings",
"schema" : {
"$ref" : "#/definitions/Settings"
}
}
}
}
}
},
"definitions" : {
"Settings" : {
"type" : "object",
"properties" : {
"StringProperty" : {
"type" : "string",
"default" : "Stringy"
},
"BooleanProperty" : {
"type" : "boolean",
"default" : true
},
"IntProperty" : {
"type" : "integer"
}
}
}
}
}
Note that the default values for the string and boolean properties are included, but the default value for the integer property (12345) is missing.
java -jar swagger-codegen-cli.jar generate -i input.yaml -l swagger -o .
Type the above command
Interestingly, when I added "format: int32" to the integer property definition:
IntProperty:
type: integer
format: int32
summary: An integer property
default: 12345
It worked:
"IntProperty" : {
"type" : "integer",
"format" : "int32",
"default" : 12345
The Swagger spec says that "format" is optional:
An optional format keyword serves as a hint for the tools to use a specific numeric type:
So I don't think it should be required here.
Thanks.
Any interest in addressing this issue?
Thanks.
I am seeing the same issue when generating Java models with swagger-codegen-cli and the JavaClientCodegen, the defaults are not generated for Integer types.
@dankling are you able to get defaults generated for other types? I'm not seeing any of the defaults being generated. Could you post your source and output files?
Same issue here. I'm getting model defaults for boolean types but not integer. using -l csharp and -DdebugModels I'm not seeing "defaultValue" in the output.
Same issue here for python as well.
Two years and two jobs later, circling back to this.
Disappointing to see that it has not been addressed.
Most helpful comment
Interestingly, when I added "format: int32" to the integer property definition:
It worked:
The Swagger spec says that "format" is optional:
So I don't think it should be required here.
Thanks.