openapistack / openapi-backend

Build, Validate, Route, Authenticate and Mock using OpenAPI
https://openapistack.co
MIT License
605 stars 83 forks source link

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

Open Dovonun opened 12 months ago

Dovonun commented 12 months ago

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 commented 12 months ago

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