openapi-backend
openapi-backend copied to clipboard
Type Error when using required `PathParameters` in Context for a handler
I have generated my types with openapi-client-axios-typegen.
namespace GetMachineBySerialNumber {
namespace Parameters {
export type Serialnumber = /**
* example:
* 205655
*/
Components.Schemas.MachineSerialnumber /* int32 */;
}
export interface PathParameters {
serialnumber: Parameters.Serialnumber;
}
namespace Responses {
export type $200 = Components.Schemas.Machine;
export type $400 = Components.Schemas.Error;
export type $401 = Components.Schemas.Error;
export type $403 = Components.Schemas.Error;
export type $404 = Components.Schemas.Error;
export type $429 = Components.Schemas.Error;
}
}
The path parameter is added to the Context of the following endpoint:
export async function getMachineBySerialNumber(
c: Context<UnknownParams, Paths.GetMachineBySerialNumber.PathParameters>,
_req: Request,
_res: Response
): Promise<Result<Paths.GetMachineBySerialNumber.Responses.$200>> {
console.log(c.request.params.serialnumber);
}
This causes the register function error:
The required parameter is obviously not in the type
UnknownParams.
Is there a way to register a handler with a required type like this?
Or a workaround?
I noticed that the first parameter to Context should be unknown, not UnknownParams. However, this does not solve the problem.