Skip to content

Conversation

helt
Copy link
Contributor

@helt helt commented Aug 20, 2024

Status

DONE

Description

Support for typed tuples as they are produced by pydantic v2.0+

Fix #1592

  • in generateZodValidationSchemaDefinition, the array switch case has to be altered to adhere prefixItems constraints. If prefixItems exists,
    • a tuple has to be pushed into functions instead of array,
    • each prefixItem has to be parsed and nested into the tuple
    • if items exists, a rest function has to be pushed after the tuple with the schema in items
  • in parseZodValidationSchemaDefinition:
    • logic to add positional parameters to tuple
    • logic for the rest functions has to be added
  • somewhere:
    • prevent .min().max() on tuple.
  • Tests added

@melloware melloware added the zod Zod related issue label Aug 20, 2024
@melloware melloware added this to the 7.0.2 milestone Aug 20, 2024
@melloware
Copy link
Collaborator

Run npm run format to format the code. Also for min() and max() i assume jus tlook at where min and max are being createed in the code and you porbbaly need to ignore that if its a tuple?

@helt
Copy link
Contributor Author

helt commented Aug 22, 2024

More issues that I would like to know if there is a better solution:

  • I have to cast to oas31.SchemaObject and back to oas30.SchemaObject because prefixItems is a oas 3.1.0 thing. Is there a better way? Without casting?

@melloware
Copy link
Collaborator

I have no answer for that I assume casting it is the only way.

@helt
Copy link
Contributor Author

helt commented Aug 23, 2024

I think this is done now. Please review and comment (and merge)

@melloware
Copy link
Collaborator

tests are still failing?

@helt
Copy link
Contributor Author

helt commented Aug 30, 2024

Ok. I see. Fakerjs got triggered because I accidentially re-used a existing test oas file. I reverted the hijacked file and added an explicit one. Hope thats ok this way.

@melloware
Copy link
Collaborator

Running build now

@helt
Copy link
Contributor Author

helt commented Aug 30, 2024

Did huskies job and formatted the code

@melloware melloware merged commit b0f6cf6 into orval-labs:master Aug 30, 2024
2 checks passed
@helt helt deleted the bugs/typed-tuple-on-zod branch August 31, 2024 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zod Zod related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zod: generation of typed tuples produces illegal zod array syntax
2 participants