Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4579
Closed
Open
Issue created Nov 22, 2019 by Administrator@rootContributor6 of 6 checklist items completed6/6 checklist items

[BUG] Default values, min, max, etc. are missing from generated Go models for object properties

Created by: mdelvecchio-wasabi

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? -> 4.2.1
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I defined an API with an object property that has default values, minimum, maximum, etc. The generated Go code lacks this information completely.

openapi-generator version

4.2.1

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  title: Configuration API
  contact:
    name: Corporation
    url: https://corporation.com
    email: nobody@corporation.com
  description: Manage configuration
  version: v2
servers:
  - url: http://config/


paths:

  /system/whatever:

    get:
      summary: Get whatever configuration
      description: Get whatever configuration
      operationId: getConfigWhatever
      tags:
      - system
      responses:
        200:
          description: The current whatever configuration
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WhateverConfig'
        default:
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIError'

    put:
      summary: Set whatever configuration
      description: Set whatever configuration
      operationId: setConfigWhatever
      tags:
      - system
      requestBody:
        description: Whatever configuration to set
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WhateverConfig'

      responses:
        200:
          description: The whatever configuration was set
        400:
          description: Invalid swhatever configuration was specified
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/APIError'
        500:
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIError'

    delete:
      summary: Delete the whatever configuration
      description: Delete the whatever configuration and revert to defaults
      operationId: deleteConfigWhatever
      tags:
      - system
      responses:
        200:
          description: The whatever configuration was deleted
        default:
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/APIError'


components:

  schemas:

    APIError:
      description: An error has occurred
      type: object
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

    WhateverConfig:
      title: Whatever Configuration
      description: Whatever configuration
      type: object

      properties:

        OutputDirectory:
          type: string
          title: Output directory
          description: Output directory
          default: "/var/log/whatever"

        BooleanFalse:
          type: boolean
          title: A boolean property with default false
          description: A boolean property with default false
          default: false

        BooleanTrue:
          type: boolean
          title: A boolean property with default true
          description: A boolean property with default true
          default: true

        Integer13:
          type: integer
          title: An integer property with default 13, min 1, max 1000
          description: An integer property with default 13, min 1, max 1000
          default: 13
          minimum: 1
          maximum: 1000
Command line used for generation

java -jar openapi-generator-cli.jar generate -i example.yaml -o example-gen -g go

Steps to reproduce

Execute the above command. Search the generated code for default values, minimum, maximum, etc. In example-gen/model_whatever_config.go, find:

// WhateverConfig Whatever configuration
type WhateverConfig struct {
	// Output directory
	OutputDirectory string `json:"OutputDirectory,omitempty"`
	// A boolean property with default false
	BooleanFalse bool `json:"BooleanFalse,omitempty"`
	// A boolean property with default true
	BooleanTrue bool `json:"BooleanTrue,omitempty"`
	// An integer property with default 13, min 1, max 1000
	Integer13 int32 `json:"Integer13,omitempty"`
}

But no mention of the default values, minimum, maximum, etc. for any property.

Related issues/PRs
Suggest a fix

Not sure if this is a fix or a feature request. I don't understand why this information is missing from the generated Go code.

Assignee
Assign to
Time tracking