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

Zod: only generates 200 response bodies #1380

Closed
Priddles opened this issue May 16, 2024 · 16 comments · Fixed by #1429
Closed

Zod: only generates 200 response bodies #1380

Priddles opened this issue May 16, 2024 · 16 comments · Fixed by #1429
Assignees
Labels
good first issue Good for newcomers zod Zod related issue
Milestone

Comments

@Priddles
Copy link

What are the steps to reproduce this issue?

  1. Use an input target with a path that has multiple responses.
Example
paths:
  /foo:
    get:
      responses:
        "200":
          $ref: "#/components/responses/Success"
        "202":
          $ref: "#/components/responses/SuccessAsync"
        "400":
          $ref: "#/components/responses/Error"
  1. Generate using Zod client.

What happens?

Only one Zod schema for the 200 response body is generated.

What were you expecting to happen?

Zod schemas for all possible responses to be generated.

Any logs, error output, etc?

None.

Any other comments?

Appears to be hard-coded:

const response = spec?.[verb]?.responses?.['200'] as

What versions are you using?

Operating System: MacOS 14.4.1
Package Version: 6.28.2
Browser Version: N/A

@melloware melloware added the zod Zod related issue label May 16, 2024
@melloware melloware changed the title Zod client only generates 200 response bodies Zod: only generates 200 response bodies May 16, 2024
@melloware
Copy link
Collaborator

Similar to this issue: #1280

@melloware
Copy link
Collaborator

Isn't this https://orval.dev/reference/configuration/output#generateeachhttpstatus

The setting to generate for each HTTP status?

@melloware melloware added this to the 6.30.0 milestone May 26, 2024
@Priddles
Copy link
Author

Priddles commented May 26, 2024

@melloware That is a config option for the mocks, and it does not affect zod generation as far as I can tell.

@melloware melloware reopened this May 26, 2024
@melloware melloware removed this from the 6.30.0 milestone May 26, 2024
@melloware
Copy link
Collaborator

Reopened i thought it did it for mocks and zod. I see now its just mocks.

@melloware
Copy link
Collaborator

You are right the code is only doing 200

const response = spec?.[verb]?.responses?.['200'] as
    | ResponseObject
    | ReferenceObject;

@melloware
Copy link
Collaborator

@Priddles is it just a matter of looping over the responses array and generating for each?

@Priddles
Copy link
Author

@Priddles is it just a matter of looping over the responses array and generating for each?

Yes, I'd say so.

Some level of deduplication would be good, but definitiely a nice-to-have.

@melloware melloware added the good first issue Good for newcomers label May 27, 2024
@TommoLeedsy
Copy link
Contributor

@melloware I have a fix for this locally and will put a PR in tomorrow.

@melloware melloware added this to the 6.30.0 milestone May 31, 2024
@melloware
Copy link
Collaborator

Ok assigned the ticket to you.

@Priddles
Copy link
Author

Priddles commented Jun 8, 2024

@melloware @TommoLeedsy Thanks for the quick turnaround!

I saw it got released so I tried it out, but having some issues. Wasn't sure whether to open a new issue or not so putting it here.

I have a minimal reproducible example here.

The issues are:

  1. It seems to be reading the config from the wrong object.
  2. It generates a lot of MSW and Faker related code that has nothing to do with Zod.

@melloware
Copy link
Collaborator

I would open a new ticket.

@TommoLeedsy
Copy link
Contributor

@Priddles Sorry yeah that's my mistake, I didn't realise I needed to add a new config option and just used an existing one instead. I have now added generateEachHttpStatus to the zod options. This should sort it. I can put a PR in today?

@melloware
Copy link
Collaborator

Yes @TommoLeedsy PR would be great.

@Priddles
Copy link
Author

@melloware Do you know when the fix might be released?

@melloware
Copy link
Collaborator

Let me find out

@Priddles
Copy link
Author

Working in latest release. Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers zod Zod related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants