astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Declaration of some types that depend on other types in the same file got swapped when using groupStrategy: tag-file

imballinst opened this issue · comments

Reference PR: #184

- 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 probably can help fix this. Let me know if I could help in making the issue clearer. Thanks!

the issue is quite clear, thanks for the draft PR, please ping me whenever you feel it's ready !

This should be fixed already with #184.