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 @@ -305,9 +305,23 @@ default Optional<Operation> processOperation(final AnnotationScannerContext cont

// validate operationId
String operationId = operation.getOperationId();

if (operationId != null) {
final MethodInfo conflictingMethod = context.getOperationIdMap().putIfAbsent(operationId, method);
if (conflictingMethod != null) {
saveOperationId(context, resourceClass, method, operationId);
}

return Optional.of(operation);
}

private void saveOperationId(AnnotationScannerContext context, ClassInfo resourceClass, MethodInfo method,
String operationId) {
final MethodInfo conflictingMethod = context.getOperationIdMap().putIfAbsent(operationId, method);

if (conflictingMethod != null) {
if (context.getAugmentedIndex().ancestry(method).values().contains(conflictingMethod)) {
// The conflict was a method from a parent class, replace it
context.getOperationIdMap().put(operationId, method);
} else {
final ClassInfo conflictingClass = conflictingMethod.declaringClass();
final String className = resourceClass.name().toString();
final String methodName = method.toString();
Expand All @@ -322,8 +336,6 @@ default Optional<Operation> processOperation(final AnnotationScannerContext cont
}
}
}

return Optional.of(operation);
}

default void setJsonViewContext(AnnotationScannerContext context, Type[] views) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ public LogRecord assertLogContaining(String substring) {
}
}

public void assertNoLogContaining(String substring) {
synchronized (handler.records) {
for (LogRecord rec : handler.records) {
if (rec.getMessage().contains(substring)) {
StringBuilder sb = new StringBuilder();
sb.append("Log containing \"").append(substring).append("\" was found.");
sb.append("\n");
sb.append("Log records recorded:\n");
for (LogRecord r : handler.records) {
sb.append("[").append(r.getLevel()).append("] ");
sb.append(r.getMessage()).append("\n");
}

throw new AssertionError(sb.toString());
}
}
}
}

private static class TestHandler extends Handler {

private List<LogRecord> records = Collections.synchronizedList(new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.jboss.jandex.Index;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

Expand All @@ -23,6 +24,9 @@
*/
class OperationIdTest extends JaxRsDataObjectScannerTestBase {

@RegisterExtension
public LogCapture logs = new LogCapture(ScannerLogging.class.getPackage().getName());

@ParameterizedTest
@CsvSource({
"METHOD, test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingGetResource, resource.testOperationIdMethod.json",
Expand Down Expand Up @@ -56,6 +60,7 @@ void testInheritedOperationIdsUtilizeConcreteClassName() throws Exception {
OpenAPI result = OpenApiProcessor.bootstrap(config, index);
printToConsole(result);
assertJsonEquals("resource.testOperationIdWithInheritance.json", result);
logs.assertNoLogContaining("Duplicate operationId");
} finally {
System.clearProperty(SmallRyeOASConfig.OPERATION_ID_STRAGEGY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface Salutation {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String get();
default String get() {
return "hi";
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package test.io.smallrye.openapi.runtime.scanner.resources.jakarta;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/english")
public class SalutationEnglish implements Salutation {

@Override
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "hello";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package test.io.smallrye.openapi.runtime.scanner.resources.jakarta;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/spanish")
public class SalutationSpanish implements Salutation {

@Override
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "hola";
}
Expand Down