orval icon indicating copy to clipboard operation
orval copied to clipboard

Bugs/typed tuple on zod

Open helt opened this issue 1 year ago • 5 comments

Status

DONE

Description

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

Reproduction for issue https://github.com/orval-labs/orval/issues/1592

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

helt avatar Aug 20 '24 12:08 helt

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?

melloware avatar Aug 20 '24 17:08 melloware

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?

helt avatar Aug 22 '24 09:08 helt

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

melloware avatar Aug 22 '24 10:08 melloware

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

helt avatar Aug 23 '24 08:08 helt

tests are still failing?

melloware avatar Aug 28 '24 15:08 melloware

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.

helt avatar Aug 30 '24 13:08 helt

Running build now

melloware avatar Aug 30 '24 14:08 melloware

Did huskies job and formatted the code

helt avatar Aug 30 '24 14:08 helt