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][Go] Inline enums not generated #2360

Open
fantavlik opened this issue Mar 11, 2019 · 4 comments
Open

[BUG][Go] Inline enums not generated #2360

fantavlik opened this issue Mar 11, 2019 · 4 comments
Labels
Client: Go Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf Issue: Bug

Comments

@fantavlik
Copy link
Contributor

fantavlik commented Mar 11, 2019

Bug Report Checklist

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

Enums that are declared inline are simply being declared as strings, while the same enum defined as a separate schema is properly captured with all legal values.

openapi-generator version

4.0.0-SNAPSHOT built from this commit: b128d14

OpenAPI declaration file content or url

sample.yaml:

openapi: "3.0.0"
info:
  version: v1
  title: Fake Service
servers:
- url: https://fake.net
paths:
  /status/details:
    get:
      summary: Get status details
      operationId: getStatus
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/StatusDetails"

components:
  schemas:
    State:
      type: string
      enum:
      - "IN_PROGRESS"
      - "READY"
      - "FAILED"
    StatusDetails:
      properties:
        id:
          type: string
        stateInline: # enum not captured, just declared as "string"
          type: string
          enum:
          - "IN_PROGRESS"
          - "READY"
          - "FAILED"
        state: # works as expected
          $ref: "#/components/schemas/State"
Command line used for generation

java -jar openapi-generator-cli.jar generate -i sample.yaml -g go -o ./sample-go

Steps to reproduce
  1. git clone https://github.com/OpenAPITools/openapi-generator.git
  2. cd openapi-generator
  3. git checkout b128d1470709c44c6c7b6a906e1993d1c2758b52
  4. mvn clean install
  5. ln -s modules/openapi-generator-cli/target/openapi-generator-cli.jar .
  6. java -jar openapi-generator-cli.jar generate -i sample.yaml -g go -o ./sample-go
Related issues/PRs

#2200
#1702
#1706

Actual vs Expected output

Go:
model_status_details.go (actual):

package openapi

type StatusDetails struct {
	Id string `json:"id,omitempty"`
	StateInline string `json:"stateInline,omitempty"`
	State State `json:"state,omitempty"`
}

model_status_details.go (expected):

package openapi

type StatusDetails struct {
	Id string `json:"id,omitempty"`
	StateInline StateInlineEnum `json:"stateInline,omitempty"`
	State State `json:"state,omitempty"`
}

type StateInlineEnum string

// List of StateInlineEnum
const (
	IN_PROGRESS StateInlineEnum = "IN_PROGRESS"
	READY StateInlineEnum = "READY"
	FAILED StateInlineEnum = "FAILED"
)
Suggest a fix

PR has been put up: #2494

@auto-labeler
Copy link

auto-labeler bot commented Mar 11, 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.

@fantavlik fantavlik changed the title [BUG][Go][Python] Inline enums declared as simple strings [BUG][Go][Python] Inline enums not generated Mar 24, 2019
@fantavlik fantavlik changed the title [BUG][Go][Python] Inline enums not generated [BUG][Go] Inline enums not generated Mar 24, 2019
@spacether spacether added the Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf label May 2, 2022
@longquanzheng
Copy link

Hi, is there any updates on this issue?

@igorroncevic
Copy link

igorroncevic commented May 16, 2023

The issue is still relevant btw.

Only fix I've been able to find is to reference enum type:

  • from the components section: $ref: "#/components/schemas/YourEnumType"
  • from a separate schema file: $ref: "./schemas/YourEnumType.yml"

Inline definitions, such as:

# YourModel.yml
type: object
properties:
   your_enum:
      type: string
      enum: 
        - value_1
        - value_2

unfortunately won't work.

@ctreatma
Copy link
Contributor

#16582 includes an example for generating inline enums using custom templates, which may be useful for teams using <= v6.6.0 of the generator, but isn't a long-term solution.

For users of v7.0.0+, this issue can be better addressed by setting RESOLVE_INLINE_ENUMS=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client: Go Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf Issue: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants