openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open charlesxsh opened this issue 5 years ago • 3 comments

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?
  • [ ] [Optional] Bounty to sponsor the fix (example)
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

charlesxsh avatar Apr 03 '20 11:04 charlesxsh

Bug still present in 5.4.0 too.

antonio-petricca avatar May 16 '22 16:05 antonio-petricca

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

antonio-petricca avatar May 18 '22 06:05 antonio-petricca

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}}

bastiwerner avatar Aug 23 '24 08:08 bastiwerner