Springdoc OpenApi Annotations @ExtensionProperty Not Evaluating Properties from application.yml

83 Views Asked by At

I have a spring boot 3.2 project for my microservice and am using the springdoc dependency to ultimately generate an OAS document for consumption by AWS API Gateway (AGW). This service is using a REST API configuration but through VPC Link so I need to ensure that the 'x-amazon-apigateway-integration' extensions are defined in my OAS doc else when I import/re-import into AGW, I have to manually add the VPC links as they get wiped out (not fun)

I have defined properties in my application.yml file as follows:

api:
  base-request-mapping: "" 
  info:
    title: MKMTestWS (Test Microservice API)
    version: "1.0"
    description: "This API exposes endpoints for testing anything"
    termsOfService: "https://www.test.ca/terms"
  server:
    description: "API Server"
    url: "http://localhost:${server.port}"
  tag:
    name: "Test Rest API"
    description: "Test Rest API"
  extensions:
    name: 'x-amazon-apigateway-integration'
    properties:
      type: "http_proxy"
      connectionId: "1rqafw"
      uri: "http://my-vpc/nlb-link"
      passthroughBehavior: "when_no_match"
      connectionType: "VPC_LINK"

I use property placeholders at the class level which picks up some of the values above which works fine - my title, version, description etc. all get evaluated

@OpenAPIDefinition(
        info = @Info(
                title = "${api.info.title}",
                version = "${api.info.version}",
                description = "${api.info.description}",
                termsOfService = "${api.info.termsOfService}",
                contact = @Contact(
                        name = "${api.info.contact.name}",
                        url = "${api.info.contact.url}",
                        email = "${api.info.contact.email}")),
        servers = { @Server(description = "${api.server.description}", url = "${api.server.url}") })
@Tag(name = "${api.tag.name}", description = "${api.tag.description}")
@Slf4j
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
@RestController
@RequestMapping(value = "${api.base-request-mapping}/testcontroller", produces = MediaType.APPLICATION_JSON_VALUE)
public class TestController {
}

Result in OAS 3.x doc evaluates correctly:

{
  "openapi": "3.0.1",
  "info": {
    "title": "MKMTestWS (Test Microservice API)",
    "description": "This API exposes endpoints for testing anything",
    "termsOfService": "https://www.test.ca/terms",
    "contact": {
      "name": "Test ITS",
      "url": "https://www.test.ca",
      "email": "[email protected]"
    },
    "version": "1.0"
  },

However, when I try and put in property placeholders at the method level within the @Operation annotation inside the class, I get the literal string returned.

Code with annotations:

    @Operation(
            summary = "Get Test",
            description = "Get Test",
            extensions = { @Extension(
                name = "${api.extensions.name}",
                properties = { 
                @ExtensionProperty(name = "type", value = "${api.extensions.properties.type}"),
        @ExtensionProperty(name = "connectionId", value = "${api.extensions.properties.connectionId}"),
        @ExtensionProperty(name = "httpMethod", value = "GET"),
        @ExtensionProperty(
        name = "uri",
        value = "${api.extensions.properties.uri}/testcontroller/getTest"),
        @ExtensionProperty(name = "passthroughBehavior", value = "${api.extensions.properties.passthroughBehavior}"),
        @ExtensionProperty(name = "connectionType", value = "${api.extensions.properties.connectionType}") }) })    
    @GetMapping(value = "/getTest")
    @ResponseBody
    public ResponseEntity<StandardApiResponse<GenericResponse>> getTest(
            @RequestParam(required = false) String testParam) throws Exception {
        }

When I generate the OAS 3.x doc, I get literal strings:

        "x-${api.extensions.name}": {
          "passthroughBehavior": "${api.extensions.properties.passthroughBehavior}",
          "connectionId": "${api.extensions.properties.connectionId}",
          "type": "${api.extensions.properties.type}",
          "httpMethod": "GET",
          "uri": "${api.extensions.properties.uri}/testcontroller/getTest",
          "connectionType": "${api.extensions.properties.connectionType}"
        }

I've tried researching many avenues but all to no avail.

Here are my main relevant dependencies:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.3.0</version>
        </dependency>

Tried using @Value spring boot annotations to resolve the properties but couldn't put variables within the springdoc annotations. Tried single brackets/double etc....

Any help would be greatly appreciated!

0

There are 0 best solutions below