Skip to content

Commit

Permalink
Fix body error #TASK-7429
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfeSanahuja committed Feb 24, 2025
1 parent 2e7c288 commit 2dbc4a1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.opencb.opencga.core.common.GitRepositoryState;
import org.opencb.opencga.core.tools.annotations.*;
import org.opencb.opencga.server.generator.commons.ApiCommons;
import org.opencb.opencga.server.generator.models.RestParameter;
import org.opencb.opencga.server.generator.openapi.models.*;
import org.opencb.opencga.server.generator.openapi.common.SwaggerDefinitionGenerator;

Expand Down Expand Up @@ -149,7 +148,7 @@ private List<Parameter> extractParameters(java.lang.reflect.Method method, Strin
if (apiParam == null || apiParam.hidden()) {
continue;
}
if(apiParam.value().equals("body") || apiParam.name().equals("body")){
if(apiParam.value().equals("body") || apiParam.name().equals("body") || isBody(methodParam)){
parameter.setName("body");
parameter.setIn("body");
parameter.setDescription(apiParam.value());
Expand Down Expand Up @@ -199,6 +198,13 @@ private List<Parameter> extractParameters(java.lang.reflect.Method method, Strin
return parameters;
}

private boolean isBody(java.lang.reflect.Parameter methodParameter) {
return methodParameter.getAnnotation(PathParam.class) == null &&
methodParameter.getAnnotation(QueryParam.class) == null &&
methodParameter.getAnnotation(FormDataParam.class) == null;
}


private String getIn(java.lang.reflect.Parameter methodParameter) {
if (methodParameter.getAnnotation(PathParam.class) != null) {
return "path";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static FieldDefinition manageCollectionTypeForType(Type type) {
Type valueType = paramType.getActualTypeArguments()[1];

FieldDefinition mapDefinition = new MapDefinition();
mapDefinition.setType("map");
mapDefinition.setType("array");

((MapDefinition) mapDefinition).setKey(manageGenericType(keyType));
((MapDefinition) mapDefinition).setValue(manageGenericType(valueType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

public class Definition {

private String type; // "object"
private String type; // enum, object, array, string, integer, number, boolean, null
private Map<String, FieldDefinition> properties;
private String ref; // Campo adicional para manejar referencias

// Getters y Setters
public String getType() {
Expand All @@ -25,12 +24,6 @@ public void setProperties(Map<String, FieldDefinition> properties) {
this.properties = properties;
}

public String getRef() {
return ref;
}

public void setRef(String ref) {
this.ref = ref;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Response update(
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "Action to be performed if the array of admins is being updated.", allowableValues = "ADD,REMOVE", defaultValue = "ADD")
@QueryParam("adminsAction") ParamUtils.AddRemoveAction adminsAction,
@ApiParam(value = "JSON containing the params to be updated.", required = true) OrganizationUpdateParams parameters) {
@ApiParam(name = "body", value = "JSON containing the params to be updated.", required = true) OrganizationUpdateParams parameters) {
try {
if (adminsAction == null) {
adminsAction = ParamUtils.AddRemoveAction.ADD;
Expand Down Expand Up @@ -114,7 +114,7 @@ public Response updateConfiguration(
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "Action to be performed if the array of authenticationOrigins is being updated.",
allowableValues = "ADD,REMOVE,SET,REPLACE", defaultValue = "ADD") @QueryParam("authenticationOriginsAction") ParamUtils.UpdateAction authOriginsAction,
@ApiParam(value = "JSON containing the params to be updated.", required = true) OrganizationConfiguration parameters) {
@ApiParam(name = "body",value = "JSON containing the params to be updated.", required = true) OrganizationConfiguration parameters) {
try {
if (authOriginsAction == null) {
authOriginsAction = ParamUtils.UpdateAction.ADD;
Expand All @@ -139,7 +139,7 @@ public Response updateConfiguration(
})
public Response create(
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "JSON containing the organization to be created.", required = true) OrganizationCreateParams parameters) {
@ApiParam(name = "body",value = "JSON containing the organization to be created.", required = true) OrganizationCreateParams parameters) {
try {
OpenCGAResult<Organization> result = catalogManager.getOrganizationManager().create(parameters, queryOptions, token);
return createOkResponse(result);
Expand Down Expand Up @@ -187,7 +187,7 @@ public Response noteSearch(
})
public Response createNote(
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "JSON containing the Note to be added.", required = true) NoteCreateParams parameters) {
@ApiParam(name = "body",value = "JSON containing the Note to be added.", required = true) NoteCreateParams parameters) {
try {
OpenCGAResult<Note> result = catalogManager.getNotesManager().createOrganizationNote(parameters, queryOptions, token);
return createOkResponse(result);
Expand All @@ -209,7 +209,7 @@ public Response updateNote(
@ApiParam(value = "Action to be performed if the array of tags is being updated.", allowableValues = "ADD,REMOVE,SET", defaultValue = "ADD")
@QueryParam("tagsAction") ParamUtils.BasicUpdateAction tagsAction,
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "JSON containing the Note fields to be updated.", required = true) NoteUpdateParams parameters) {
@ApiParam(name = "body",value = "JSON containing the Note fields to be updated.", required = true) NoteUpdateParams parameters) {
try {
if (tagsAction == null) {
tagsAction = ParamUtils.BasicUpdateAction.ADD;
Expand Down Expand Up @@ -250,7 +250,7 @@ public Response updateUserInformation(
@ApiParam(value = ParamConstants.USER_DESCRIPTION, required = true) @PathParam("user") String userId,
@ApiParam(value = ParamConstants.ORGANIZATION_DESCRIPTION) @QueryParam(ParamConstants.ORGANIZATION) String organizationId,
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "JSON containing the User fields to be updated.", required = true) OrganizationUserUpdateParams parameters) {
@ApiParam(name = "body",value = "JSON containing the User fields to be updated.", required = true) OrganizationUserUpdateParams parameters) {
try {
OpenCGAResult<User> result = catalogManager.getOrganizationManager().updateUser(organizationId, userId, parameters, queryOptions, token);
return createOkResponse(result);
Expand All @@ -271,7 +271,7 @@ public Response updateUserStatus(
@ApiParam(value = ParamConstants.USER_DESCRIPTION, required = true) @PathParam("user") String userId,
@ApiParam(value = ParamConstants.ORGANIZATION_DESCRIPTION) @QueryParam(ParamConstants.ORGANIZATION) String organizationId,
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "JSON containing the User fields to be updated.", required = true) UserStatusUpdateParams parameters) {
@ApiParam(name = "body",value = "JSON containing the User fields to be updated.", required = true) UserStatusUpdateParams parameters) {
try {
OpenCGAResult<User> result = catalogManager.getUserManager().changeStatus(organizationId, userId, parameters.getStatus(), queryOptions, token);
return createOkResponse(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public UserWSServer(@Context UriInfo uriInfo, @Context HttpServletRequest httpSe
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a new user", response = User.class)
public Response create(
@ApiParam(value = "JSON containing the parameters", required = true) UserCreateParams user
@ApiParam(name = "body",value = "JSON containing the parameters", required = true) UserCreateParams user
) {
try {
if (!user.checkValidParams()) {
Expand Down Expand Up @@ -209,7 +209,7 @@ public Response resetPassword(
public Response updateByPost(
@ApiParam(value = ParamConstants.USER_DESCRIPTION, required = true) @PathParam("user") String userId,
@ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult,
@ApiParam(value = "JSON containing the params to be updated.", required = true) UserUpdateParams parameters) {
@ApiParam(name = "body", value = "JSON containing the params to be updated.", required = true) UserUpdateParams parameters) {
try {
ObjectUtils.defaultIfNull(parameters, new UserUpdateParams());

Expand All @@ -230,7 +230,7 @@ public Response updateConfiguration(
@ApiParam(value = ParamConstants.USER_DESCRIPTION, required = true) @PathParam("user") String userId,
@ApiParam(value = "Action to be performed: ADD or REMOVE a group", allowableValues = "ADD,REMOVE", defaultValue = "ADD")
@QueryParam("action") ParamUtils.AddRemoveAction action,
@ApiParam(value = "JSON containing anything useful for the application such as user or default preferences. " +
@ApiParam(name = "body",value = "JSON containing anything useful for the application such as user or default preferences. " +
"When removing, only the id will be necessary.", required = true) ConfigUpdateParams params) {
try {
if (action == null) {
Expand Down Expand Up @@ -270,7 +270,7 @@ public Response updateFilters(
@ApiParam(value = ParamConstants.USER_DESCRIPTION, required = true) @PathParam("user") String userId,
@ApiParam(value = "Action to be performed: ADD or REMOVE a group", allowableValues = "ADD,REMOVE", defaultValue = "ADD")
@QueryParam("action") ParamUtils.AddRemoveAction action,
@ApiParam(value = "Filter parameters. When removing, only the 'name' of the filter will be necessary", required = true) UserFilter params) {
@ApiParam(name = "body", value = "Filter parameters. When removing, only the 'name' of the filter will be necessary", required = true) UserFilter params) {
try {
if (action == null) {
action = ParamUtils.AddRemoveAction.ADD;
Expand All @@ -292,7 +292,7 @@ public Response updateFilters(
public Response updateFilterPOST(
@ApiParam(value = ParamConstants.USER_DESCRIPTION, required = true) @PathParam("user") String userId,
@ApiParam(value = "Filter id", required = true) @PathParam("filterId") String id,
@ApiParam(value = "Filter parameters", required = true) FilterUpdateParams params) {
@ApiParam(name = "body", value = "Filter parameters", required = true) FilterUpdateParams params) {
try {
return createOkResponse(catalogManager.getUserManager().updateFilter(userId, id,
new ObjectMap(getUpdateObjectMapper().writeValueAsString(params)), token));
Expand Down

0 comments on commit 2dbc4a1

Please sign in to comment.