Suggest to remove singleton OpenAPI object and make Clients instanced.
See original GitHub issueCurrently the Client
templates reference a single OpenAPI
reference which is used to set the token or headers.
An example where this approach fails is trying to contact two API’s with the same generated codegen, we frequently do this e.g. from staging to live environment stagingapi.product.com -> api.product.com and there isn’t really a workaround other than set the token before every request.
This does lead on to the question as to why the client functions are templated as statics, I believe having to instance the clients and provide the configuration would work better with DI and testing frameworks.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:18
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Defining constant value in response · Issue #1313 - GitHub
In order to specify that the response for an API call is always a certain given value, I would like to create this...
Read more >Design Anti-patterns - GitLab Docs
Under the hood, clients of a singleton class all share a single specific instance of an object, which means this pattern inherits all...
Read more >Writing JSON REST Services - Quarkus
In this guide, we see how you can get your REST services to consume and produce JSON payloads. there is another guide if...
Read more >Should RestClient be singleton or new for every request
Recommended way to use RestSharp is to create a new instance per request. It differs from Singleton approach recommended for HttpClient .
Read more >OpenAPI Specification - Version 3.0.3 - Swagger
The openapi field SHOULD be used by tooling specifications and clients to interpret ... get, Operation Object, A definition of a GET operation...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’ve ended up forking (great project as a base btw) as we wanted some additional’s like:
I think that’s it https://github.com/yottaltd/openapi-typescript-codegen/tree/feature/yotta-codegen
keep in mind this is only on the fetch templates currently, we have no need for xhr but will be updating the node templates accordingly.
For us, the
--name
option was not flexible enough, so we let the user pass in a whole template for the services: https://github.com/ferdikoomen/openapi-typescript-codegen/pull/1268