In our OpenAPI specification, we have a type Allowance that can be either a EngineeringAllowance or StandardAllowance.
we use the property allowance_type as discriminator.
Allowance:
oneOf:
- $ref: "#/components/schemas/EngineeringAllowance"
- $ref: "#/components/schemas/StandardAllowance"
discriminator:
propertyName: allowance_type
each allowance type correspond to one allowance_type string, as given by the enum
StandardAllowance:
properties:
allowance_type:
type: string
enum: ["standard"]
The types generated by rtk-query/codegen-openapi isn’t correct,
the type Allowance is empty. The discrimated union never match the given patterns allowance_type: 'EngineeringAllowance'; or allowance_type: 'StandardAllowance'; as it’s the wrong strings.
the strings do not match with the value given in the openAPI definition, it simply uses the name of the Schema.
It should use the provided allowance_type strings given in the allowance_type enum for each schema.
export type EngineeringAllowance = {
allowance_type?: 'engineering';
distribution?: 'MARECO' | 'LINEAR';
capacity_speed_limit?: number;
} & RangeAllowance;
export type StandardAllowance = {
allowance_type?: 'standard';
default_value?: AllowanceValue;
ranges?: RangeAllowance[];
distribution?: 'MARECO' | 'LINEAR';
capacity_speed_limit?: number;
};
export type Allowance =
| ({
allowance_type: 'EngineeringAllowance';
} & EngineeringAllowance)
| ({
allowance_type: 'StandardAllowance';
} & StandardAllowance);
Allowance:
oneOf:
- $ref: "#/components/schemas/EngineeringAllowance"
- $ref: "#/components/schemas/StandardAllowance"
discriminator:
propertyName: allowance_type
StandardAllowance:
properties:
allowance_type:
type: string
enum: ["standard"]
default_value:
$ref: "#/components/schemas/AllowanceValue"
ranges:
type: array
items:
$ref: "#/components/schemas/RangeAllowance"
distribution:
type: string
enum: ["MARECO", "LINEAR"]
capacity_speed_limit:
type: number
format: double
EngineeringAllowance:
allOf:
- type: object
properties:
allowance_type:
type: string
enum: ["engineering"]
distribution:
type: string
enum: ["MARECO", "LINEAR"]
capacity_speed_limit:
type: number
format: double
- $ref: "#/components/schemas/RangeAllowance"
In our OpenAPI specification, we have a type
Allowancethat can be either aEngineeringAllowanceorStandardAllowance.we use the property
allowance_typeas discriminator.each allowance type correspond to one
allowance_typestring, as given by the enumThe types generated by
rtk-query/codegen-openapiisn’t correct,the type
Allowanceis empty. The discrimated union never match the given patternsallowance_type: 'EngineeringAllowance';orallowance_type: 'StandardAllowance';as it’s the wrong strings.the strings do not match with the value given in the openAPI definition, it simply uses the name of the Schema.
It should use the provided
allowance_typestrings given in theallowance_typeenum for each schema.