OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

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

Open davinchia opened 4 years ago

davinchia commented 4 years ago

Bug Report Checklist

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.

lisamburns commented 2 years ago

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