Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Resto del encabezado de la versión de la API en SwaggerUI

Quiero usar Springfox SwaggerUI para mi documentación de Rest API (spring-mvc). Uso el encabezado de la versión en la anotación @RequestMapping, pero si tengo dos versiones del mismo método, en SwaggerUI solo puedo ver una.

Por ejemplo:

 @GetMapping(value = "/users", headers = "X-API-VERSION=1") public List<User> getUsersV1(){...} @GetMapping(value = "/users", headers = "X-API-VERSION=2") public List<User> getUsersV2(){...}

El código anterior da como resultado solo un método visible en la documentación de la API.

¿Hay alguna opción para configurar Swagger para diferentes puntos finales teniendo en cuenta el encabezado de mi versión?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Después de algunas investigaciones, encontré una solución a mi problema, tal vez ayude a alguien en el futuro. Agrego el sufijo "#v" a la ruta usando PathDecorator.

Ahora puedo ver todos mis métodos en la documentación generada.

 @Component @Order(value = Ordered.HIGHEST_PRECEDENCE + 70) public class VersionPathDecorator implements PathDecorator { private final static Logger logger = LoggerFactory.getLogger(VersionPathDecorator.class); @Override public Function<String, String> decorator(PathContext context) { return (path) -> { StringBuilder sb = new StringBuilder(path); Field parent = null; try { parent = PathContext.class.getDeclaredField("parent"); parent.setAccessible(true); RequestMappingContext rmc = (RequestMappingContext) parent.get(context); rmc.headers() .stream() .filter(h -> RequestHeader.X_API_VERSION.headerName.equals(h.getName())) .map(NameValueExpression::getValue) .findFirst() .ifPresent(v -> sb.append("#v").append(v)); } catch (NoSuchFieldException | IllegalAccessException e) { logger.error("path decoration failed", e); } return sb.toString(); }; } @Override public boolean supports(DocumentationContext documentationContext) { return true; } }
about 4 years ago · Santiago Trujillo Report

0

Swagger identifica los servicios por su punto final.

Cada característica debe responder a un punto final diferente y no se deben usar encabezados para esa función.

Si está utilizando servicios REST, lea un poco sobre Restfull y siga sus principios. Esta URL puede ayudarlo: http://docs.oracle.com/javaee/6/tutorial/doc/gijqy.html

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!