astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
741 stars 82 forks source link

fix: fix order of schemas when using option groupStrategy: tag-file #184

Closed imballinst closed 1 year ago

imballinst commented 1 year ago

This PR is a PoC to proof that when using groupStrategy: "tag-file", the zod type of Category and Tag are generated last instead of first.

- const Category = z
-   .object({ id: z.number().int(), name: z.string() })
-   .partial()
-   .passthrough();
- const Tag = z
-   .object({ id: z.number().int(), name: z.string() })
-   .partial()
-   .passthrough();
  const Pet = z
    .object({
      id: z.number().int().optional(),
      name: z.string(),
--
      tags: z.array(Tag).optional(),
      status: z.enum(["available", "pending", "sold"]).optional(),
    })
    .passthrough();
+ const Category = z
+   .object({ id: z.number().int(), name: z.string() })
+   .partial()
+   .passthrough();
+ const Tag = z
+   .object({ id: z.number().int(), name: z.string() })
+   .partial()
+   .passthrough();
  const ApiResponse = z
    .object({ code: z.number().int(), type: z.string(), message: z.string() })
    .partial()
    .passthrough();

As we see above, since Pet is declared first, then it will cause error since Category and Tag isn't defined yet. I'll create an issue for this, referring to this PR.

vercel[bot] commented 1 year ago

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

Name Status Preview Comments Updated (UTC)
openapi-zod-client ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2023 1:44pm