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

Generate enum as export type #313

Closed
ThomasDevGif opened this issue Jan 4, 2024 · 1 comment
Closed

Generate enum as export type #313

ThomasDevGif opened this issue Jan 4, 2024 · 1 comment

Comments

@ThomasDevGif
Copy link

Hello,

I have a Java api and I use swagger-maven-plugin to generate an api-file.yaml.
Then I use ng-openapi-gen and the api-file.yaml to generate the api in my angular application.

The problem is that I cannot reuse my Java enum as type in my angular application.

Here is the api-file.yaml content :

openapi: 3.0.1

paths:
  /users:
    get:
      operationId: getUser
      responses:
        default:
          description: default response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/UserDto'
  /users/{userId}/etiquettes:
    get:
      operationId: getEtiquettes
      parameters:
      - name: userId
        in: path
        required: true
        schema:
          type: integer
          format: int64
      responses:
        default:
          description: default response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/EtiquetteDto'
components:
  schemas:
    UserDto:
      type: object
      properties:
        userId:
          type: string
        etiquettes:
          type: array
          items:
            type: string
            enum:
              - WHITE
              - GREY
              - BLACK
              - RED
              - GREEN
              - BLUE
              - YELLOW
              - ORANGE
    EtiquetteDto:
      type: object
      properties:
        color:
          type: string
          enum:
          - WHITE
          - GREY
          - BLACK
          - RED
          - GREEN
          - BLUE
          - YELLOW
          - ORANGE
        name:
          type: string

And the generated models using ng-openapi-gen :

export interface EtiquetteDto {
  color?: 'WHITE' | 'GREY' | 'BLACK' | 'RED' | 'GREEN' | 'BLUE' | 'YELLOW' | 'ORANGE';
  name?: string;
}

export interface UserDto {
  etiquettes?: Array<'WHITE' | 'GREY' | 'BLACK' | 'RED' | 'GREEN' | 'BLUE' | 'YELLOW' | 'ORANGE'>;
  userId?: string;
}

Is there any way to also generate an export type Color so I can use it in the angular application ?

Thanks in advance,

@ThomasDevGif
Copy link
Author

The problem was before the yaml generation.
I had to add the swagger annotations @Schema(enumAsRef = true) in each enum file.

luisfpg pushed a commit that referenced this issue Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant