openapi-backend icon indicating copy to clipboard operation
openapi-backend copied to clipboard

Type Error when using required `PathParameters` in Context for a handler

Open Dovonun opened this issue 2 years ago • 1 comments

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: image 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?

Dovonun avatar Sep 08 '23 16:09 Dovonun

I noticed that the first parameter to Context should be unknown, not UnknownParams. However, this does not solve the problem.

Dovonun avatar Sep 11 '23 09:09 Dovonun