简体   繁体   中英

Mapped the Yaml configuration to Micronaut swagger open API security configuration

I have the below YAML configuration for OAuth

OAuth:
  authorizationUrl: https://localhost:5001/connect/authorize
  tokenUrl: https://localhost:5001/connect/token
  scopes:
    - name: openid
      description: open id scope
    - name: profile
      description: profile scope
    - email: profile
      description: profile scope

And a record class for mapping something like below

@ConfigurationProperties("OAuth")
public record OAuthConfiguration(
        String authorizationUrl,
        String tokenUrl,
        List<SelectOptionModel> scopes
) {}

Now in the main method of micronaiut application I need to mapped the record value, not sure how can I achieve this

@SecurityScheme(name = "openid",
        type = SecuritySchemeType.OAUTH2,
        scheme = "bearer",
        bearerFormat = "jwt",
        flows = @OAuthFlows(
                authorizationCode = @OAuthFlow(
                        authorizationUrl = "", // This should be replace from record property 
                        tokenUrl = "", // This should be replace from record property 
                        scopes = {@OAuthScope(name = "openid", description = "OpenID"), // This should be replace from record property 
                                @OAuthScope(name = "profile", description = "profile"), // This should be replace from record property 
                                @OAuthScope(name = "email", description = "email") // This should be replace from record property 
                        }
                )
        )
)
public class ApiGateway {

    public static void main(String[] args) {
        Micronaut.run(ApiGateway.class, args);
    }
}

Instead of using YAML, put it on openapi.properties, see https://micronaut-projects.github.io/micronaut-openapi/3.0.1/guide/index.html

example:
in openapi.properties micronaut.openapi.expand.info.title=Testing App

in your annotation:
@OpenAPIDefinition( info = @Info(title = "${info.title}")} )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM