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

[FEATURE/BUG] Reusable Enum values / References not supported #3598

Closed
2 of 6 tasks
macjohnny opened this issue Aug 9, 2019 · 2 comments
Closed
2 of 6 tasks

[FEATURE/BUG] Reusable Enum values / References not supported #3598

macjohnny opened this issue Aug 9, 2019 · 2 comments

Comments

@macjohnny
Copy link
Member

macjohnny commented Aug 9, 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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

According to swagger-api/swagger-editor#609 (comment) and OAI/OpenAPI-Specification#300 (comment) yaml files support references, which could serve to reuse e.g. enum values.
However, the following error occurs:

schemas.enum is not of type `array`
openapi-generator version

4.0.3

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  version: 1.0.0
  title: Petstore

paths:
  /pet:
    get:
      parameters:
        - $ref: '#/components/parameters/livingEnvironment'
      responses:
        '200':
          description: 'Pet'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
        name:
          type: string
        tag:
          type: string
        livingEnvironment:
          type: string
          enum: &livingEnvironmentEnum
            - Water
            - Land
            - Air

  parameters:
    livingEnvironment:
      name: livingEnvironment
      required: false
      in: query
      schema:
        type: string
        enum: *livingEnvironmentEnum
Command line used for generation
openapi-generator generate -i api-definition2.yml -g typescript-angular -o frontend-client
Steps to reproduce
Related issues/PRs
Suggest a fix
@OpenAPITools OpenAPITools deleted a comment from auto-labeler bot Aug 9, 2019
@macjohnny macjohnny changed the title [BUG] Reusable Enum values / References not supported [FEATURE/BUG] Reusable Enum values / References not supported Aug 9, 2019
@macjohnny
Copy link
Member Author

closing, as this can be solved with e.g.

openapi: '3.0.0'
info:
  version: 1.0.0
  title: Petstore
paths:
  /pets:
    get:
      parameters:
        - $ref: '#/components/parameters/livingEnvironment'
      responses:
        '200':
          description: 'An array of pets'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pets'
components:
  schemas:
    LivingEnvironment:
      type: string
      enum:
        - Water
        - Land
        - Air

    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
        name:
          type: string
        tag:
          type: string
        livingEnvironment:
          $ref: '#/components/schemas/LivingEnvironment'
    Pets:
      type: array
      items:
        $ref: '#/components/schemas/Pet'

  parameters:
    livingEnvironment:
      name: livingEnvironment
      required: false
      in: query
      schema:
        $ref: '#/components/schemas/LivingEnvironment'

@pablo53
Copy link

pablo53 commented May 6, 2021

I have the same issue. The bug is not resolved, this is only a workaround for the issue of not handling the enum references correctly.

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

No branches or pull requests

2 participants