openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] Ruby Client generates docs that encourage bad client configuration.

Open davinchia opened this issue 5 years ago • 1 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

The ruby client documentation encourages the use of the default client constructor. This is fine in most cases, but does carry the caveat that the default constructor will use the later given access_token across all threads. Passing access_token to constructors avoids this.

This is because the configure method modifies a @@default variable which is passed as the default argument to the initialize method for DefaultApi.

Not a ruby expert - so can't comment on whether the generated code follows the right ruby patterns/conventions. I do think this can be avoided with tweaks in the documentation that accompanies the generated client.

openapi-generator version

Using 4.2.1.

OpenAPI declaration file content or url

NA.

Command line used for generation

NA.

Steps to reproduce

Generate any client and look at the rendered documentation.

Related issues/PRs

Checked. Unclear from my 10 mins search.

Suggest a fix

Not an expert on the ruby generation bit of this codebase. Open to pointers. Filing an issue for myself now. Will likely get to it when I have some time.

davinchia avatar Feb 19 '20 04:02 davinchia

I have this same issue. I don't want the access token to be global and so reading the generated code, it looks like I need to do something like this, nonintuitively. config = MyService::Configuration.new( access_token: "some-token" ) api = MyService::DefaultApi.new(MyService::ApiClient.new(config))

lisamburns avatar Aug 09 '22 16:08 lisamburns