davsclaus commented on code in PR #15257:
URL: https://github.com/apache/camel/pull/15257#discussion_r1725149290
##########
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java:
##########
@@ -145,6 +149,21 @@ public void validateOpenApi(OpenAPI openAPI,
PlatformHttpConsumerAware platformH
}
}
+ /**
+ * If the operation has no operationId specified, generate one based on
the path and the operation method.
+ *
+ * @param path The path for this operation, such as /users.
+ * @param httpMethod The operation to perform
+ * @return A generated operation id based on the path and the
operation. Slashes and braces in the path
+ * are replaced with placeholder characters.
+ */
+ private String generateOperationId(String path, HttpMethod httpMethod) {
+ final String sanitizedPath = path.replace('/', '.').replaceAll("[{}]",
"_");
+ final String opId = GEN_OPID + httpMethod.name() + sanitizedPath;
+ LOG.warn("Generated operationId {} for path {} and method {}", opId,
path, httpMethod.name());
Review Comment:
WARN is maybe too high level - the openapi spec seem to allow no operation
id, and as such we should just accept this - so a DEBUG logging is maybe better
##########
components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategyTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.rest.openapi;
+
+import io.swagger.v3.oas.models.OpenAPI;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.platform.http.PlatformHttpComponent;
+import org.apache.camel.component.platform.http.spi.PlatformHttpConsumerAware;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.mock;
+
+class RestOpenapiProcessorStrategyTest extends ManagedCamelTestSupport {
+
+ private CamelContext camelContext;
+
+ @BeforeEach
+ public void createMocks() throws Exception {
+ initializeContextForComponent("rest-openapi");
+ }
+
+ @Test
+ void testMissingOperationId() throws Exception {
+ RestOpenapiProcessorStrategy restOpenapiProcessorStrategy = new
DefaultRestOpenapiProcessorStrategy();
+ ((DefaultRestOpenapiProcessorStrategy)
restOpenapiProcessorStrategy).setCamelContext(camelContext);
+ restOpenapiProcessorStrategy.setMissingOperation("fail");
+ Exception ex = assertThrows(IllegalArgumentException.class,
+ () ->
restOpenapiProcessorStrategy.validateOpenApi(getOpenApi(),
mock(PlatformHttpConsumerAware.class)));
+ assertTrue(ex.getMessage().contains("direct:GENOPID_GET.users"));
+ assertTrue(ex.getMessage().contains("direct:GENOPID_GET.user._id_"));
+
+ }
+
+ private OpenAPI getOpenApi() {
+ return RestOpenApiEndpoint.loadSpecificationFrom(camelContext,
"missing-opid.yaml");
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // from("direct:GENOPID_GETusers").to("mock:getUsers");
+ from("direct:getUsers").to("mock:getUsers");
+ }
+ };
+ }
+
+ @Override
+ protected CamelContext createCamelContext(String componentName) {
+
+ camelContext = new DefaultCamelContext();
+ PlatformHttpComponent httpCmpn = mock(PlatformHttpComponent.class);
+ // camelContext.addComponent("platform-http", new
PlatformHttpComponent());
Review Comment:
This code should maybe be removed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]