question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggest to remove singleton OpenAPI object and make Clients instanced.

See original GitHub issue

Currently 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:closed
  • Created 2 years ago
  • Reactions:18
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
cmcnicholascommented, May 25, 2021

We’ve ended up forking (great project as a base btw) as we wanted some additional’s like:

  • interfaces for services
  • instance based services (not static)
  • exposing of the request options as functions
  • remove global singleton OpenApi
  • add discriminator to unioned namespace
  • ability to override catchErrrors
  • inject an ErrorFactory
  • ability to override parsing of the body

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.

1reaction
mb21commented, Sep 22, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found