OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.9k stars 6.59k forks source link

[BUG][graphql-schema] doesn't support reuseble enum #5815

Open charlesxsh opened 4 years ago

charlesxsh commented 4 years ago

Bug Report Checklist

Description

graphql-schema generator doesn't support reusable enum

openapi-generator version

4.3.0

OpenAPI declaration file content or url
Resource:
      type: object
      properties:
        status:
            $ref: '#/components/schemas/ResourceStatus'
ResourceStatus:
      type: string
      enum:
        - a
        - b
        - c
Command line used for generation

npx openapi-generator generate -g graphql-schema -i example.yaml -o somedir

Steps to reproduce

Just run this command with schemas provided above, you will get an empty graphql file for this enum

# Paths for user service
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
# The version of the OpenAPI document: 1.0.0
# Generated by OpenAPI Generator: https://openapi-generator.tech
#

type ResourceStatus {

}
Related issues/PRs
Suggest a fix
antonio-petricca commented 2 years ago

Bug still present in 5.4.0 too.

antonio-petricca commented 2 years ago

I fixed a solution by the PR https://github.com/OpenAPITools/openapi-generator/pull/12389 .

bastiwerner commented 2 months ago

Bug still present in v7.8.0 Could be fixed using the following model.mustache file:

{{#models}}
{{#model}}
{{>partial_header}}
{{#description}}
"""
{{.}}
"""
{{/description}}
{{#isEnum}}
enum {{classname}} {
  {{#allowableValues}}
  {{#values}}
  {{.}}
  {{/values}}
  {{/allowableValues}}
}
{{/isEnum}}
{{^isEnum}}
type {{classname}} {
{{#vars}}
  {{#description}}
  """
  {{.}}
  """
  {{/description}}
  {{baseName}}: {{datatypeWithEnum}}
{{/vars}}
}
{{/isEnum}}
{{/model}}
{{/models}}