asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
788 stars 52 forks source link

make examples use both input and output types of zod #206

Closed tionkje closed 4 months ago

tionkje commented 5 months ago

As mentionend in #189 I ran the tests and they all ran fine. Let me know if there are any issues with this

AGalabov commented 4 months ago

@tionkje you have some lint errors. Please fix them. As for the PR - I see no reason not to use only z.input. An example should be an example of what comes into the object/validation and not its output.

This is similar to how we handle transform:

it('does support transformed schemas', () => {
    expectSchema(
      [
        z
          .number()
          .transform(num => num.toString())
          .openapi('Transformed'),
      ],
      {
        Transformed: {
          type: 'number',
        },
      }
    );
  });

I.e in the documentation we enter the input type.

And one more thing - we tend to add tests for pretty much everything new that is testable (even if a typescript change only). In this case I think you simply add the default case in the tests, please