Skip to content

Commit

Permalink
Fix apiParam name #TASK-5914
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfeSanahuja committed Jan 16, 2025
1 parent ee1a577 commit 712787c
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ public Swagger generateJsonOpenApi(ApiCommons apiCommons, String token, String e
bearerAuth.put("description", "Use 'Bearer <token>' to authenticate");
securityDefinitions.put("BearerAuth", bearerAuth);
swagger.setSecurityDefinitions(securityDefinitions);

for (Class<?> clazz : classes) {
Api api = clazz.getAnnotation(Api.class);
if (api == null) {
continue;
}
tags.add(new Tag(api.value(), api.description()));

// Obtener ruta base de la clase
javax.ws.rs.Path classPathAnnotation = clazz.getAnnotation(javax.ws.rs.Path.class);
String basePath = classPathAnnotation.value();
if (classPathAnnotation == null) {
continue;
}

// Procesar métodos
for (java.lang.reflect.Method wsmethod : clazz.getDeclaredMethods()) {
ApiOperation apiOperation = wsmethod.getAnnotation(ApiOperation.class);
Expand All @@ -65,17 +66,20 @@ public Swagger generateJsonOpenApi(ApiCommons apiCommons, String token, String e
beansDefinitions.add((Class) apiOperation.response());
}
method.getResponses().put("200", responses);

// Obtener el método HTTP
String httpMethod = extractHttpMethod(wsmethod);
if (httpMethod == null) continue;
Consumes consumes = wsmethod.getAnnotation(Consumes.class);

// Extraer parámetros
List<Parameter> parameters = extractParameters(wsmethod, token);
method.setParameters(parameters);
if (consumes != null){
method.getConsumes().addAll(Arrays.asList(consumes.value()));
}
method.getProduces().add("application/json");

// Ruta completa del endpoint
javax.ws.rs.Path methodPathAnnotation = wsmethod.getAnnotation(javax.ws.rs.Path.class);
String fullPath = basePath + (methodPathAnnotation != null ? methodPathAnnotation.value() : "");
Expand All @@ -85,6 +89,7 @@ public Swagger generateJsonOpenApi(ApiCommons apiCommons, String token, String e
tokens.add("Bearer "+token);
}
method.setSecurity(Collections.singletonList(Collections.singletonMap("BearerAuth", tokens)));

// Crear o actualizar el Path
paths.put(fullPath, new HashMap<>());
paths.get(fullPath).put(httpMethod, method);
Expand Down Expand Up @@ -136,7 +141,7 @@ private List<Parameter> extractParameters(java.lang.reflect.Method method, Strin
ApiParam apiParam = methodParam.getAnnotation(ApiParam.class);
if (apiParam != null) {
Parameter parameter = new Parameter();
parameter.setName(apiParam.value());
parameter.setName(apiParam.name());
parameter.setDescription(apiParam.value());
parameter.setRequired(apiParam.required());
parameter.setType(methodParam.getType().getSimpleName().toLowerCase(Locale.ROOT));
Expand Down Expand Up @@ -169,16 +174,6 @@ private List<Parameter> extractParameters(java.lang.reflect.Method method, Strin
}
}

// Añadir encabezado Authorization con el token preconfigurado
/* Parameter authorizationHeader = new Parameter();
authorizationHeader.setName("Authorization");
authorizationHeader.setIn("header");
authorizationHeader.setDescription("Bearer token for authorization");
authorizationHeader.setRequired(true);
authorizationHeader.setType("string");
authorizationHeader.setDefaultValue("Bearer " + token);
parameters.add(authorizationHeader);*/

return parameters;
}

Expand Down

0 comments on commit 712787c

Please sign in to comment.