Open
Description
Reproduced with version 13.0.23.
Test case:
{
"openapi": "3.1.0",
"components": {
"schemas": {
"MySchema": {
"properties": {
"working": {
"type": "string",
"enum": [
"email_address"
],
"const": "email_address"
},
"not_working": {
"type": "string",
"enum": [
"phone_number"
],
"const": "phone_number"
}
},
"type": "object"
}
}
}
}
Run it like this:
./node_modules/.bin/swagger-typescript-api -p <test_schema> --no-client
Output file:
export interface MySchema {
working?: "email_address";
not_working?: phone_number;
}
Note that "phone_number" isn't in quotes.
I think the problem is here. When the field value is a constant, getSchemaType()
returns the literal value as a JS expression. In this case, the two keyType
s are "email_address"
and "phone_number"
. The two getSchemaType()
calls on lines 73 and 78 return "number" and "boolean", respectively. Then keyType.includes()
returns true
for "phone_number"
on line 78 so we fail to treat the corresponding value
as a string and we don't wrap it in quotes.