You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I upgraded to 5.11 recently, and I really like the new OperationHandler type templates. However, now that I'm getting better type validation on my handlers, I'm running into an issue with endpoints that have boolean query parameters.
As an example, here is the openapi typegen generated types for an endpoint with a boolean query param:
Given that I've defined c as type OperationContext<'getAllCategories'>, now typescript thinks that this value already IS a boolean, so this type of conversion no longer works. I've found myself having to coerce it as follows:
constisGroupQuery=c.request?.query?.is_groupasunknownasStringif(isGroupQuery&&isGroupQuery.toLowerCase()==='true'){// Handle is_group==true}elseif(isGroupQuery&&isGroupQuery.toLowerCase()==='false'){// Handle is_group==false}else{// Handle is_group not set}
Is it possible to ask openapi-backend to set the values in c.request.query and c.request.params to the defined types?
The text was updated successfully, but these errors were encountered:
Hi, I upgraded to 5.11 recently, and I really like the new OperationHandler type templates. However, now that I'm getting better type validation on my handlers, I'm running into an issue with endpoints that have boolean query parameters.
As an example, here is the
openapi typegen
generated types for an endpoint with a boolean query param:And here is the signature for the handler that I've registered:
The problem I'm running into is that the type of
c.request.query.is_group
is actually a string. Below is some debugger output:c.request.query {is_group: 'true'}
That has always been the case with opeanpi-backend, and historically, I just set a local boolean with something like:
Given that I've defined c as type
OperationContext<'getAllCategories'>
, now typescript thinks that this value already IS a boolean, so this type of conversion no longer works. I've found myself having to coerce it as follows:Is it possible to ask openapi-backend to set the values in c.request.query and c.request.params to the defined types?
The text was updated successfully, but these errors were encountered: