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

[REQ][Java] Customize scopes separator in generated API client

Open mrydzy opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

Api Client is generated with scopes that are comma separated and there is no way to change it.

See https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache#L110

Some Oauth services require scopes to be space separated.

Describe the solution you'd like

It would be nice to be able to change default separator for scopes in generated client.

Describe alternatives you've considered

Workaround is to list all the scopes as a single, coma separated scope in yaml file.

Additional context

mrydzy avatar Mar 20 '24 01:03 mrydzy

According to the RFC 6749 section 3.3 : "The value of the scope parameter is expressed as a list of space-delimited, case-sensitive strings"

So from my point of view, generate a comma separated list of scopes is a bug ?

Adrien-dev25 avatar Dec 02 '25 14:12 Adrien-dev25

As work around, I used this piece of code :

// Create custom authentication method with list of scopes delimited by space
OAuth customOAuth = new OauthClientCredentialsGrant(null,
		"https://myApiManager/oauth2/token",	
		"scope1 scope2 scope3");

// Create ApiClient without using declared Oauth method
ApiClient apiClient = new ApiClient();

// register our custom authentication method 
apiClient.addAuthorization("custom-client-credential", customOAuth);

// set credentials 
apiClient.setClientCredentials("__Consumer_Key__","__Consumer_Secret__");

Adrien-dev25 avatar Dec 04 '25 07:12 Adrien-dev25