-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[client-fetch] Wrong type prop generation #1684
Comments
How does this affect your experience @blouflashdb? I remember there was a reason I made it like this, and it might've been due to compiler or certain cases like if the empty object is the only element in type, it actually allows everything |
The current version is absolutely more correct. Your schema implies that there are no additional properties allowed, which is what the outputted type is saying. Empty objects should never be used as a type, and although this doesn't specifically apply when it's combined inline, the current behavior (using Imagine if you had that last object as a ref: {
"ModelBase": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"$ref": "#/components/schemas/VehicleType"
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "type",
"mapping": {
"Car": "#/components/schemas/CarModel",
"Bike": "#/components/schemas/BikeModel",
"Truck": "#/components/schemas/TruckModel"
}
}
},
"NoAdditionalProperties": {
"type": "object",
"additionalProperties": false
},
"BikeModel": {
"allOf": [
{
"$ref": "#/components/schemas/ModelBase"
},
{
"$ref": "#/components/schemas/NoAdditionalProperties"
}
]
}
} Right now the lib outputs export type NoAdditionalProperties = {
[key: string]: never;
}; With your suggested change, it would output as export type NoAdditionalProperties = {}; Which would result in this being valid code: type EmptyObject = {}
type NoKeysObject = {
[key: string]: never;
}
// These are all valid as far as ts is concerned
const ThisIsTechnicallyAnObjectBecauseJavascript: EmptyObject = "abc";
const SoIsThis: EmptyObject = "";
const AndThis: EmptyObject = 0;
// these will throw errors
const TsSavesUsHere: NoKeysObject = "abc";
const TsSavesUsHereToo: NoKeysObject = 0; That's not what we want. Here's a ts playground with the difference. |
Wow you went the extra mile @danieltott, that's correct 🙏 |
Yeah I saw this when looking for another issue and really didn't want it to get accepted 😅 |
Description
Wrong generation of type that has allOf but no additionalProps.
Generates:
But I would expect:
Reproducible example or configuration
Config:
OpenAPI specification (optional)
System information (optional)
No response
The text was updated successfully, but these errors were encountered: