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

fix: correct parameters schema for Zodios(use of .shape and .schema.shape) #488

Conversation

stijnvanhulle
Copy link
Collaborator

With a small change, it will generate the following(instead of using the full Response object):

./zod/getUserSchema

import { z } from 'zod'

export const getUserPathParamsSchema = z.object({ userId: z.string().describe(`Executes the action in the context of the specified user.`) })

/**
 * @description Successful response
 */
export const getUserQueryResponseSchema = z.object({ message: z.string().optional(), user: z.object({ userId: z.string().optional() }).optional() })

zodios.ts

import { makeApi, Zodios } from '@zodios/core'
import { getUserQueryResponseSchema, getUserPathParamsSchema } from './zod/getUserSchema'

const endpoints = makeApi([
  {
    method: 'get',
    path: '/users/:userId',
    description: `...`,
    requestFormat: 'json',
    parameters: [
      {
        name: 'userId',
        description: `Executes the action in the context of the specified user.`,
        type: 'Path',
        schema: getUserPathParamsSchema.shape['userId'],
      },
    ],
    response: getUserQueryResponseSchema,
    errors: [],
  },
])

export const api = new Zodios(endpoints)

export default api


@stijnvanhulle stijnvanhulle linked an issue Oct 13, 2023 that may be closed by this pull request
@vercel
Copy link

vercel bot commented Oct 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
kubb ✅ Ready (Inspect) Visit Preview Oct 13, 2023 9:14pm

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b162622:

Sandbox Source
advanced-pet-store Configuration
faker-pet-store Configuration
msw-pet-store Configuration
react-query-pet-store Configuration
typescript-pet-store Configuration
simple-single-pet-store Configuration
solid-query-pet-store Configuration
svelte-query-pet-store Configuration
swr-pet-store Configuration
vue-query-pet-store Configuration
zod-pet-store Configuration
zodios-pet-store Configuration
client-pet-store Configuration

@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Merging #488 (b162622) into main (1cda7ef) will increase coverage by 0.00%.
The diff coverage is 90.90%.

@@           Coverage Diff           @@
##             main     #488   +/-   ##
=======================================
  Coverage   86.64%   86.64%           
=======================================
  Files         106      106           
  Lines        5915     5924    +9     
  Branches      757      762    +5     
=======================================
+ Hits         5125     5133    +8     
- Misses        789      790    +1     
  Partials        1        1           
Files Coverage Δ
packages/swagger/src/types.ts 100.00% <100.00%> (ø)
...kages/swagger/src/generators/OperationGenerator.ts 89.90% <88.88%> (-0.07%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link

@meister03 meister03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, you also added the description field. I will give it a test...

@meister03
Copy link

Okay works on my test repo, thanks for the changes.

@stijnvanhulle stijnvanhulle merged commit 131b838 into main Oct 14, 2023
@stijnvanhulle stijnvanhulle deleted the 487-zodios-client-generates-path-parameter-object-instead-of-string branch October 14, 2023 08:02
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

Successfully merging this pull request may close these issues.

Zodios Client generates path parameter object instead of string
2 participants