Skip to content

Conversation

@soartec-lab
Copy link
Member

@soartec-lab soartec-lab commented Nov 18, 2025

Summary

fix #2561

This is a bug due to incomplete compliance with Open API 3.1.

In OpenAPI 3.0, when using $ref, other parallel items were ignored. However, from OpenAPI 3.1 onwards, parallel items of the parent element are given priority.

Therefore, to support OpenAPI 3.1, it is necessary to reference and prioritize the original definition of nullable.

test

The behavior of the test code I added has been modified as follows:

# Before

// schema
export interface PetWithTag {
  tag: string;
  /** @nullable */
  pet: Pet;
}

// zod
export const showPetWithOwnerResponse = zod.object({
  "tag": zod.string(),
  "pet": zod.union([zod.union([zod.object({
  "cuteness": zod.number(),
  "breed": zod.enum(['Labradoodle'])
}),zod.object({
  "length": zod.number(),
  "breed": zod.enum(['Dachshund'])
})]),zod.object({
  "petsRequested": zod.number().optional(),
  "type": zod.enum(['cat'])
})])
})

After

// schema
/**
 * @nullable
 */
export type PetWithTagPet = Pet | null;

export interface PetWithTag {
  tag: string;
  /** @nullable */
  pet: PetWithTagPet;
}

// zod
export const showPetWithOwnerResponse = zod.object({
  "tag": zod.string(),
  "pet": zod.union([zod.union([zod.object({
  "cuteness": zod.number(),
  "breed": zod.enum(['Labradoodle'])
}),zod.object({
  "length": zod.number(),
  "breed": zod.enum(['Dachshund'])
})]),zod.object({
  "petsRequested": zod.number().optional(),
  "type": zod.enum(['cat'])
})]).nullable()
})

@soartec-lab soartec-lab added bug Something isn't working openapi_31 OpenAPI 3.1 related issue labels Nov 18, 2025
@melloware melloware merged commit bb714b1 into orval-labs:master Nov 18, 2025
2 checks passed
@soartec-lab soartec-lab changed the title fix(core): nullable ignored when combined with $ref in schema property fix(core/zod): nullable ignored when combined with $ref in schema property Nov 30, 2025
@soartec-lab soartec-lab added the zod Zod related issue label Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working openapi_31 OpenAPI 3.1 related issue zod Zod related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nullable ignored when combined with $ref in schema property

2 participants