java - How to put a custom annotation on path variable in openApi - Stack Overflow

admin2025-04-16  2

In our project, we generate controllers with OpenAPI generator. In one of those controllers, there's an endpoint with a path variable, on which I need to put our custom annotation @Encrypted, like below:

@RequestMapping(
            method = RequestMethod.GET,
            value = "/notification/{id}/download",
            produces = { "application/pdf", "application/json" }
            )
ResponseEntity<org.springframework.core.io.Resource> downloadNotification(
        @Size(max = 255)  @PathVariable("id") @Encrypted String id
            );

and this is specification. I tried x-field-extra-annotation:

/notification/{id}/download:
  get:
    parameters:
      - name: id
        schema:
          maxLength: 255
          type: string
        in: path
        required: true
        x-field-extra-annotation: "@sbbol.annotation.Encrypted"

However, OpenAPI ignores it, and I get an endpoint without my annotation:

ResponseEntity<org.springframework.core.io.Resource> downloadNotification(
        @Size(max = 255)  @PathVariable("id") String id
            );

Is there a way to put a custom annotation on a path variable in OpenAPI?

转载请注明原文地址:http://anycun.com/QandA/1744789014a87644.html