Skip to content

Enum components are being generated as nullable when the property holding it is nullable #258

@renke0

Description

@renke0

Description

I have the following scenario:

const Brand = z.enum(['Ford', 'Toyota', 'Tesla']).openapi('Brand');

const Car = z
    .object({
        brand: Brand.nullable(),
        model: z.string(),
    })
    .openapi('Car');

Expected result

I expected the property Car.brand to be a nullable Brand

components:
  schemas:
    Brand:
      type: string
      enum:
        - Ford
        - Toyota
        - Tesla
    Car:
      type: object
      properties:
        brand:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/Brand'
        model:
          type: string

Actual result

The spec generated declares Brand as nullable, instead of making the property Car.brand nullable

components:
  schemas:
    Brand:
      type:
        - string
        - 'null'
      enum:
        - Ford
        - Toyota
        - Tesla
    Car:
      type: object
      properties:
        brand:
          $ref: '#/components/schemas/Brand'
        model:
          type: string

More info

I understand the rationale behind the way this was generated. The problem is that Brand could be reusable, and in some places it might not be nullable. Is there a workaround this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions