Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

java - Problem with bearerAuth type authorization when using openapi code generator using a maven project and a input YAML

I have a input spec YAML file, I am using it to generate the client code -

This is what I have tried ->

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

  2. 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: []

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...