Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1173,11 +1173,10 @@ private boolean existOperationId(String operationId) {
return false;
}
for (PathItem path : openAPI.getPaths().values()) {
String pathOperationId = extractOperationIdFromPathItem(path);
if (operationId.equalsIgnoreCase(pathOperationId)) {
Set<String> pathOperationIds = extractOperationIdFromPathItem(path);
if (pathOperationIds.contains(operationId)) {
return true;
}

}
return false;
}
Expand Down Expand Up @@ -1213,23 +1212,30 @@ protected ResolvedParameter getParameters(Type type, List<Annotation> annotation
return extractParametersResult;
}

private String extractOperationIdFromPathItem(PathItem path) {
if (path.getGet() != null) {
return path.getGet().getOperationId();
} else if (path.getPost() != null) {
return path.getPost().getOperationId();
} else if (path.getPut() != null) {
return path.getPut().getOperationId();
} else if (path.getDelete() != null) {
return path.getDelete().getOperationId();
} else if (path.getOptions() != null) {
return path.getOptions().getOperationId();
} else if (path.getHead() != null) {
return path.getHead().getOperationId();
} else if (path.getPatch() != null) {
return path.getPatch().getOperationId();
private Set<String> extractOperationIdFromPathItem(PathItem path) {
Set<String> ids = new HashSet<>();
if (path.getGet() != null && StringUtils.isNotBlank(path.getGet().getOperationId())) {
ids.add(path.getGet().getOperationId());
}
return "";
if (path.getPost() != null && StringUtils.isNotBlank(path.getPost().getOperationId())) {
ids.add(path.getPost().getOperationId());
}
if (path.getPut() != null && StringUtils.isNotBlank(path.getPut().getOperationId())) {
ids.add(path.getPut().getOperationId());
}
if (path.getDelete() != null && StringUtils.isNotBlank(path.getDelete().getOperationId())) {
ids.add(path.getDelete().getOperationId());
}
if (path.getOptions() != null && StringUtils.isNotBlank(path.getOptions().getOperationId())) {
ids.add(path.getOptions().getOperationId());
}
if (path.getHead() != null && StringUtils.isNotBlank(path.getHead().getOperationId())) {
ids.add(path.getHead().getOperationId());
}
if (path.getPatch() != null && StringUtils.isNotBlank(path.getPatch().getOperationId())) {
ids.add(path.getPatch().getOperationId());
}
return ids;
}

private boolean isEmptyComponents(Components components) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ public void testResolveDuplicatedOperationId() {
assertNotNull(paths);
Operation firstOperation = paths.get(PATH_REF).getGet();
Operation secondOperation = paths.get(PATH_2_REF).getGet();
Operation thirdOperation = paths.get(PATH_REF).getPost();
assertNotNull(firstOperation);
assertNotNull(secondOperation);
assertNotNull(thirdOperation);
assertNotEquals(firstOperation.getOperationId(), secondOperation.getOperationId());
assertNotEquals(firstOperation.getOperationId(), thirdOperation.getOperationId());
assertNotEquals(secondOperation.getOperationId(), thirdOperation.getOperationId());
}

@Test(description = "Get a Duplicated Operation Id with same id as method name")
Expand All @@ -229,9 +233,15 @@ public void testResolveDuplicatedOperationIdMethodName() {
assertNotNull(paths);
Operation firstOperation = paths.get("/1").getGet();
Operation secondOperation = paths.get("/2").getGet();
Operation secondPostOperation = paths.get("/2").getPost();
Operation thirdPostOperation = paths.get("/3").getPost();
assertNotNull(firstOperation);
assertNotNull(secondOperation);
assertNotNull(secondPostOperation);
assertNotNull(thirdPostOperation);
assertNotEquals(firstOperation.getOperationId(), secondOperation.getOperationId());
assertNotEquals(secondOperation.getOperationId(), secondPostOperation.getOperationId());
assertNotEquals(secondPostOperation.getOperationId(), thirdPostOperation.getOperationId());
Operation thirdOperation = paths.get("/3").getGet();
Operation fourthOperation = paths.get("/4").getGet();
assertNotNull(thirdOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

Expand All @@ -17,6 +18,15 @@ public Response getSummaryAndDescription() {
return Response.ok().entity("ok").build();
}

@POST
@Path("/")
@Operation(operationId = "operationId",
summary = "Operation Summary",
description = "Operation Description")
public Response postSummaryAndDescription() {
return Response.ok().entity("ok").build();
}

@GET
@Path("/path")
@Operation(operationId = "operationId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

Expand All @@ -23,12 +24,27 @@ public Response getSummaryAndDescription2() {
return Response.ok().entity("ok").build();
}

@POST
@Path("/2")
@Operation(operationId = "postSummaryAndDescription3",
summary = "Operation Summary",
description = "Operation Description")
public Response postSummaryAndDescription2() {
return Response.ok().entity("ok").build();
}

@GET
@Path("/3")
public Response getSummaryAndDescription3() {
return Response.ok().entity("ok").build();
}

@POST
@Path("/3")
public Response postSummaryAndDescription3() {
return Response.ok().entity("ok").build();
}

@GET
@Path("/4")
public Response getSummaryAndDescription3(String foo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ paths:
'*/*': {}
/notannotatedoperation:
get:
operationId: getUser_1
operationId: getUser_2
responses:
default:
description: default response
Expand All @@ -506,7 +506,7 @@ paths:
type: string
/notannotatedoperationduplicated:
get:
operationId: getUser_2
operationId: getUser_3
requestBody:
content:
'*/*':
Expand All @@ -521,7 +521,7 @@ paths:
type: string
/operationsresource2:
get:
operationId: getUser_3
operationId: getUser_4
responses:
default:
description: default response
Expand Down Expand Up @@ -569,7 +569,7 @@ paths:
schema:
type: string
post:
operationId: getUser_4
operationId: getUser_5
requestBody:
content:
'*/*':
Expand Down Expand Up @@ -599,7 +599,7 @@ paths:
type: string
/operationwithouannotation:
get:
operationId: getUser_4
operationId: getUser_6
responses:
default:
description: default response
Expand Down Expand Up @@ -1190,7 +1190,7 @@ paths:
description: Status OK
/noimplementationresponseresource:
get:
operationId: getUser_5
operationId: getUser_7
parameters:
- name: userId
in: query
Expand Down