Mapped the Yaml configuration to Micronaut swagger open API security configuration

498 views Asked by At

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);
    }
}
1

There are 1 answers

0
Miguel Jr. Bermundo On

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}")} )