Can you prevent generation of the singleton client object?
#3421
-
|
I'm interested in using Hey API in a server-rendered Next.js app. Currently, my application uses a However, I noticed that by default, the generated SDK will just use a singleton Is there a preferred way to generate a fetch client that doesn't include a singleton like this? Frankly, I think a singleton client is an antipattern for anything other than entirely client-side apps (and even then I'm not sure it's a great idea in most cases). |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
Hi @thomasboyt! I'm Dosu and I’m helping the openapi-ts team. Unfortunately, there's no built-in configuration option to disable the singleton client generation in Hey API. The generated code always includes the default Your workaround options:
Your feedback about the singleton being an antipattern for SSR is valid—you might consider opening a feature request on the Hey API repo for a "no singleton" mode or a way to make the client parameter required. This seems like a reasonable enhancement for server-side use cases. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
@thomasboyt hello, I see you over at openapi-typescript as well 👋 dosu is pretty much right, you can't disable the singleton output today, but you can enforce client to be always passed by setting |
Beta Was this translation helpful? Give feedback.
-
|
@mrlubos Since you asked about this specifically, there are some unique issues with next.js that I think need to be understood better in the hey api nextjs plugin. I´m not sure if a singleton api client is just an antipattern for nextjs, or if it has its use cases. I think the nextjs plugin section could at lease benefit from a discussion about this, especially regarding interceptors. Especially if misuse could be a security risk. |
Beta Was this translation helpful? Give feedback.
@thomasboyt hello, I see you over at openapi-typescript as well 👋 dosu is pretty much right, you can't disable the singleton output today, but you can enforce client to be always passed by setting
client: falsein the SDK plugin