Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag grouping common schema import issue #309

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

prastoin
Copy link

@prastoin prastoin commented Oct 14, 2024

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:

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

Copy link

vercel bot commented Oct 14, 2024

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

Name Status Preview Comments Updated (UTC)
openapi-zod-client-rim4 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 1:48pm

@prastoin prastoin changed the title Tag groupping import issue [WIP] Tag groupping import issue Oct 14, 2024
@prastoin prastoin changed the title [WIP] Tag groupping import issue Tag groupping import issue Oct 14, 2024
@prastoin prastoin marked this pull request as ready for review October 14, 2024 14:40
@prastoin prastoin changed the title Tag groupping import issue Tag grouping common schema import issue Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant