Skip to content

Combining enum parameters does not export type for parameter #2065

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

Open
sanjsharma opened this issue Apr 28, 2025 · 1 comment
Open

Combining enum parameters does not export type for parameter #2065

sanjsharma opened this issue Apr 28, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sanjsharma
Copy link

sanjsharma commented Apr 28, 2025

Orval version: "7.8.0"

OAS:

openapi: 3.0.2
paths:
  "/animals":
    get:
      parameters:
        - $ref: '#/components/parameters/AnimalParam'

components:
  parameters:   
    AnimalParam:
      name: animal
      in: query
      schema:
        oneOf:
          - $ref: "#/components/schemas/Foo"
          - type: string
            enum:
              - mouse
      required: false
  schemas:
    Foo:
      type: string
      nullable: true
      enum:
        - cat
        - dog

Generated types:

import { Foo } from './foo'

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const AnimalParamParameter = { ...Foo, mouse: 'mouse' } as const

It does not export type for AnimalParamParameter

Workaround:

components:
  parameters:   
    AnimalParam:
      name: animal
      in: query
      schema:
        oneOf:
          - $ref: "#/components/schemas/Bar"

  schemas:
    Foo:
      nullable: true
      type: string
      enum:
        - cat
        - dog
    Bar:
      nullable: true
      oneOf:
        - $ref: "#/components/schemas/Foo"
        - type: string
          enum:
            - mouse

It exports the type as needed

import { Foo } from './foo'

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const Bar = { ...Foo, mouse: 'mouse' } as const
export type Bar = (typeof Bar)[keyof typeof Bar]
import type { Bar } from './bar'

export type AnimalParamParameter = Bar

Without the oneOf workaround on AnimalParams which it should not need, I do not get the type exported

AnimalParam:
  name: animal
  in: query
  schema:
    $ref: "#/components/schemas/Bar"
@AllieJonsson AllieJonsson self-assigned this Apr 28, 2025
@AllieJonsson AllieJonsson added the bug Something isn't working label Apr 28, 2025
@AllieJonsson
Copy link
Contributor

#2057 will fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants