openapi-ts
openapi-ts copied to clipboard
JSON Schema with if/then keywords is generated into unknown type
Description
My use case is to use allOf in combination with if and then keyword. I'm expecting to have the sub schema defined under then merged but they are generated as unknown instead.
Reproducible example or configuration
https://github.com/giovanism/issue-demo-hey-api-openapi-ts-if-then
OpenAPI specification (optional)
No response
System information (optional)
No response
@giovanism What's the expected output in your example?
if, then should create a union type based on the conditions with the conditional attribute(or schema) as a required property.
This is also the preferred way to define a discriminator in 3.1.x+, rather than using the discriminator keyword.
type CreateUserRequest =
| {
accountType: 'premium';
billingAddress: Address;
creditLimit: number & { min: 1000; max: 10000 };
// Other optional properties
}
| {
accountType: 'enterprise';
companyInfo: CompanyInfo;
billingAddress: Address;
creditLimit: number & { min: 10000 };
// Other optional properties
}
| {
accountType: 'basic';
preferences?: UserPreferences;
// Other optional properties
};