简体   繁体   中英

Combine multiple annotations into one

Im using Java 11 Quarkus 2.9.2 Final and I would like to avoid duplication of a set of annotations:

      @APIResponse(
          responseCode = "401",
          description = "Unauthorized",
          content = @Content(mediaType = MediaType.APPLICATION_JSON)),
      @APIResponse(
          responseCode = "403",
          description = "Forbidden",
          content = @Content(mediaType = MediaType.APPLICATION_JSON)),
      @APIResponse(
          responseCode = "404",
          description = "Not Found",
          content = @Content(mediaType = MediaType.APPLICATION_JSON))

My plan is to make a custom annotation for it like @APIResponses40X().

Is this possible? Can someone help me?

I don't think what you are asking for is possible, but you can reduce by a lot duplicated code using Quarkus OpenAPI merge feature:

a request to /q/openapi will serve the combined OpenAPI document from the static file and the model generated from application endpoints code

Just create a static openapi.yml file and define reusable responses for status codes.
Every @APIResponse owns a ref property used to ref erence an element in your OpenAPI file; just reference the correct response.

https://swagger.io/docs/specification/describing-responses/
How to reference response components in OpenAPI?

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