swagger-api / swagger-api/swagger-codegen

swagger-codegen-cli omits integer default values

Open
#6,929 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

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

Swagger-codegen version

2.2.3

Swagger declaration file content or url

Input YAML file:

swagger: '2.0'
info:
  title: Settings API
  contact:
    name: Somebody
    url: https://settings.com
    email: settings@settings.com
  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:

{
  "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" : "settings@settings.com"
    }
  },
  "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.

##### Command line used for generation

java -jar swagger-codegen-cli.jar generate -i input.yaml -l swagger -o .

##### Steps to reproduce

Type the above command

##### Related issues/PRs



##### Suggest a fix/enhancement




Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with swagger-codegen-cli.jar, the supplied YAML, and the generate -i input.yaml -l swagger -o . command. Trace the Swagger output generation for schema property defaults, then verify that the integer default 12345 is preserved alongside the existing string and boolean defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.