Description
openapi-typescript version
7.6.1
Node.js version
20.17.0
OS + version
WSL Ubuntu 22.04.1 LTS
Description
We're trying to generate a type for an update request (UpdatePet) where the attributes need to be determined by a discriminator (sound), with the two possible types being CatProps and DogProps, these have one optional property each: kittens and puppies respectively. We're also trying to generate two additional types Cat and Dog , which reference CatProps and DogProps, with kittens and puppies being required.
When the discriminator is added to the UpdatePet schema the Cat and Dog types incorrectly generate with kittens and puppies becoming optional. If we remove the discriminator, the Cat and Dog schemas generate correctly.
Reproduction
openapi: 3.0.0
info:
title: Bug test
version: 1.0.0
description: Api specification for bug report
components:
schemas:
CatProps:
type: object
properties:
kittens:
type: number
format: integer
Cat:
type: object
required: [kittens]
allOf:
- $ref: "#/components/schemas/CatProps"
DogProps:
type: object
properties:
puppies:
type: number
format: integer
Dog:
type: object
required: [puppies]
allOf:
- $ref: "#/components/schemas/DogProps"
UpdatePet:
oneOf:
- $ref: "#/components/schemas/DogProps"
- $ref: "#/components/schemas/CatProps"
discriminator:
propertyName: sound
mapping:
bark: "#/components/schemas/DogProps"
meow: "#/components/schemas/CatProps"
Generate a ts schema from this yml, Cat type will be: Cat: components["schemas"]["CatProps"]
Then delete the whole discriminator, Cat type will be: Cat: WithRequired<components["schemas"]["CatProps"], "kittens">
Expected result
Cat type should be the following: Cat: WithRequired<components["schemas"]["CatProps"], "kittens">
The type of UpdatePet should have no effect on the seemingly unrelated Cat and Dog types.
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint
)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)