The suggested solution might not be the most idiomatic to the current implementation. Maybe this could be computed along others metrics and not afterwards ? Anw do not hesitate
A solution suggestion
Previously when a zod expression was match it would early return dependency injection.
But zod expression might involve schemas such as with:
z.array(z.union([FooBar.and(Bar).and(Foo), z.union([FooBar, Bar, Foo])]))
I agree that using a ref or a json response would "fix" this here, as it would be abstracted behind a "on head" schema.
But it's avoidable when dealing with use case such as response body unions and so on.
In this way we will iterate and try match in the zod expression each of the endpoints's zodSchemaByName
Result on an example output:
// controller_bar.ts
import { makeApi, Zodios, type ZodiosOptions } from "@zodios/core";
import { z } from "zod";
+ import { FooBar } from "./common";
const endpoints = makeApi([
{
method: "put",
path: "/bar",
description: \`Bar\`,
requestFormat: "json",
response: z.array(FooBar),
},
]);
export const Controller_barApi = new Zodios(endpoints);
export function createApiClient(baseUrl: string, options?: ZodiosOptions) {
return new Zodios(baseUrl, endpoints, options);
}
Conclusion
As always any suggestion are welcomed ! Please let know
Have a great day !
ps: I might not have covered every existing use case in tests so feel free to add any
Introduction
It seems like there's an issue while importing common models, shared between at least 2 controllers, when tag grouping apis.
For more information regarding the bug itself please refer to https://github.com/astahmer/openapi-zod-client/issues/310
The suggested solution might not be the most idiomatic to the current implementation. Maybe this could be computed along others metrics and not afterwards ? Anw do not hesitate
A solution suggestion
Previously when a
zod
expression was match it would early return dependency injection. Butzod
expression might involve schemas such as with:I agree that using a
ref
or ajson
response would "fix" this here, as it would be abstracted behind a "on head" schema. But it's avoidable when dealing with use case such as response body unions and so on. In this way we will iterate and try match in thezod
expression each of the endpoints'szodSchemaByName
Result on an example output:
Conclusion
As always any suggestion are welcomed ! Please let know Have a great day !
ps: I might not have covered every existing use case in tests so feel free to add any