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

Support documentation for custom parsers #644

Closed
cyrilchapon opened this issue Apr 24, 2023 · 1 comment
Closed

Support documentation for custom parsers #644

cyrilchapon opened this issue Apr 24, 2023 · 1 comment

Comments

@cyrilchapon
Copy link

cyrilchapon commented Apr 24, 2023

Hi,

According to akheron/typera#688, I'm leaving a comment here, of a non-working generated OpenAPI with a custom parser (typera-zod).

const updateUserRoute: Route<
  | Response.Ok<UserPayloadDTO>
  // | ... Error types
> = adminRoute
  .put('/user/:id(uuidv4)')
  .use(ZodParser.body<UserUpdatePayloadDTO>(userUpdatePayloadSchema))
  .handler(async (request) => {
    // This is typed correctly
    const userUpdatePayload = request.body

    // ...
  })

Generated OpenAPI :
Capture d’écran 2023-04-24 à 17 21 34

    '/user/{id}': {
      put: {
        operationId: 'updateUserRoute',
        parameters: [
          {
            name: 'id',
            in: 'path',
            required: true,
            schema: { type: 'string' },
          },
        ],
        responses: {
          '200': {
            description:
// ...

The thing is I don't really understand why; since apparently, the strategy is to lookup the type from the request.body variable; and it's correctly typed in my example above.

I can give a shot a fixing, but I'd need help to know where to start. Any idea ? :)

@cyrilchapon
Copy link
Author

cyrilchapon commented Apr 26, 2023

The trouble were apparently in the building strategy of typera-zod which was somehow broken (or at least breaking something). I was transpiling to an "hybrid" package (CJS + ESM), and apparently typera-openapi was not liking it.

In my last refactor, I turned it to a pure CJS build; which resolves everything and it works like a charm 🎉

Closing this, however it might need investigation to confirm typera-openapi can work with an ESM parser.

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