Reputation: 1108
I have a input spec YAML file, I am using it to generate the client code -
This is what I have tried ->
I tried www.editor.swagger.io, gave me a GUI, when I clicked on Authorize, I got 2 ways -> Basic Auth and Beaer Auth using a access token -> Working fine (Just to test the design)
When I generated the code using swagger code gen maven, works fine.
BUT
When I am using openapi code gen using maven to generate client code, I am not getting bearerAuth part,
I have a method called setAccessToken() --> If you see when setAccessToken is called, it is directly throwing exception when i generated code using openApi
public void setAccessToken(String accessToken) {
throw new RuntimeException("No OAuth2 authentication configured!");
}
When I am using swagger code gen...I am not getting this problem...as you can see below the code is getting generated correctly
public void setAccessToken(String accessToken) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setAccessToken(accessToken);
return;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");
}
This is how my YAML looks...
securitySchemes:
basicAuth:
type: http
scheme: basic
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- basicAuth: []
- bearerAuth: []
Upvotes: 2
Views: 3922
Reputation: 503
check setBearerAuth() api, there should be one more instead of setAccessToken. I had same issue.
Upvotes: 1