swagger-api / swagger-api/swagger-codegen

[Java] Auto-generated OAuth example is out of date for many HTTP backends

Open
#7,649 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The code sample from the auto-generated Api Doc:

ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure OAuth2 access token for authorization: Client Credentials
OAuth Client Credentials = (OAuth) defaultClient.getAuthentication("Client Credentials");
Client Credentials.setAccessToken("YOUR ACCESS TOKEN");

no longer matches the ApiCilent implementation for most HTTP backends:

ApiClient defaultClient = new ApiClient("Client Credentials");
defaultClient.setAccessToken("YOUR ACCESS TOKEN");

and also seems to be invalid syntax.

Swagger-codegen version

2.2.1

Suggest a fix/enhancement

Use 2nd provided example for HTTP backends (feign, retrofit, retrofit2) that support TokenRequestBuilder for automatic request and renew of Access Token (and add documentation for that functionality too).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/swagger-codegen/src/main/resources/Java/api_doc.mustache and compare its OAuth example with modules/swagger-codegen/src/main/resources/Java/libraries/feign/ApiClient.mustache. Check the corresponding feign, retrofit, and retrofit2 backends and their TokenRequestBuilder support. Done means the generated examples use valid, matching syntax and document automatic access-token requests and renewal where supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.