Skip to content

Combining enum parameters does not export type for parameter #2065

@sanjsharma

Description

@sanjsharma

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"

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions