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
  • #2360
Closed
Open
Issue created Mar 11, 2019 by Administrator@rootContributor

[BUG][Go] Inline enums not generated

Created by: fantavlik

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: https://github.com/OpenAPITools/openapi-generator/commit/b128d1470709c44c6c7b6a906e1993d1c2758b52

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

https://github.com/OpenAPITools/openapi-generator/issues/2200 https://github.com/OpenAPITools/openapi-generator/issues/1702 https://github.com/OpenAPITools/openapi-generator/issues/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: https://github.com/OpenAPITools/openapi-generator/pull/2494

Assignee
Assign to
Time tracking