Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks done
mdelvecchio-wasabi opened this issue Nov 22, 2019 · 3 comments · May be fixed by #18532
Open
6 tasks done

Comments

@mdelvecchio-wasabi
Copy link

mdelvecchio-wasabi commented Nov 22, 2019

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.

@auto-labeler
Copy link

auto-labeler bot commented Nov 22, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@mdelvecchio-wasabi
Copy link
Author

So I take it that this is just not part of the openapi-generator functionality? That openapi-generator just ignores default, min, and max values?

If so, I guess I need to look elsewhere.

Can someone comment please?

Thanks.

@kevinpeter
Copy link

you can extend the mustach-template with your missing values.
This video tutorial helped me: https://www.youtube.com/watch?v=Jp2y15Xgk9g

rledisez added a commit to rledisez/openapi-generator that referenced this issue Apr 26, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
rledisez added a commit to rledisez/openapi-generator that referenced this issue Apr 29, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
rledisez added a commit to rledisez/openapi-generator that referenced this issue Apr 29, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
rledisez added a commit to rledisez/openapi-generator that referenced this issue Apr 29, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
rledisez added a commit to rledisez/openapi-generator that referenced this issue May 13, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
rledisez added a commit to rledisez/openapi-generator that referenced this issue May 13, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
rledisez added a commit to rledisez/openapi-generator that referenced this issue May 28, 2024
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants