Tag grouping common schema import issue #309
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #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.But
zod
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 the
zod
expression each of the endpoints'szodSchemaByName
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