redux-toolkit
redux-toolkit copied to clipboard
[open-api gen] Error: path paremeter not defined if schema is vague
Issue
I just tried to convert an openapi schema to RTK query, and stumbled upon the following error:
Error: path parameter id does not seem to be defined?
The schema is a bit weird, but unfortunately, its generation is outside of my control. Look at how the parameter name for delete and get is in a different case:
{
"paths":{
"/playlists/{id}":{
"get":{
"tags":[
"Playlists"
],
"summary":"Get a Playlist",
"operationId":"getPlaylist",
"parameters":[
{
"name":"id",
"in":"path",
"description":"ID of the playlist",
"example":1
}
]
},
"delete":{
"tags":[
"Playlists"
],
"summary":"Delete a playlist",
"operationId":"deletePlaylist",
"parameters":[
{
"in":"path",
"name":"ID",
"required":true,
"description":"ID of playlist to delete",
"schema":{
"type":"integer",
"example":1
}
}
]
}
}
}
}
The solution
The error happens as this comparison fails https://github.com/reduxjs/redux-toolkit/blob/2fbf0b5e8403e31209eee9801af0256bdfc78dfb/packages/rtk-query-codegen-openapi/src/generate.ts#L414
In the example of the spec above it compares 'ID' === 'id', which fails. However, when comparing using name instead of originalName everything works, as name has the parameter in the correct case.
I am not sure whether using name for originalName is legitim though.