Skip to content

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

Open
@mdelvecchio-wasabi

Description

@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: [email protected]
  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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions