Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dovonun opened this issue Sep 8, 2023 · 1 comment
Open

Comments

@Dovonun
Copy link

Dovonun commented Sep 8, 2023

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
Copy link
Author

Dovonun commented Sep 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant