This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new ee4a102f6a Fix #6701 to support OpenAPI spec with yaml format (#6707)
ee4a102f6a is described below

commit ee4a102f6a5b02d2ef1bba3371514de24f8f5934
Author: Zheng Feng <zh.f...@gmail.com>
AuthorDate: Mon Oct 28 20:33:00 2024 +0800

    Fix #6701 to support OpenAPI spec with yaml format (#6707)
---
 .../CamelQuarkusSwaggerCodegenProvider.java        |  12 +--
 .../rest/openapi/it/RestOpenApiRoutes.java         |   6 ++
 .../rest-openapi/src/main/openapi/example.yaml     | 102 +++++++++++++++++++++
 .../src/main/resources/application.properties      |   2 +-
 .../component/rest/openapi/it/RestOpenapiTest.java |  10 ++
 5 files changed, 125 insertions(+), 7 deletions(-)

diff --git 
a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
 
b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
index 8c09b33d05..48df92c740 100644
--- 
a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
+++ 
b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
@@ -48,7 +48,7 @@ public class CamelQuarkusSwaggerCodegenProvider implements 
CodeGenProvider {
 
     @Override
     public String[] inputExtensions() {
-        return new String[] { "json" };
+        return new String[] { "json", "yaml" };
     }
 
     @Override
@@ -65,16 +65,16 @@ public class CamelQuarkusSwaggerCodegenProvider implements 
CodeGenProvider {
         }
 
         try {
-            List<String> jsonFiles = new ArrayList<>();
+            List<String> specFiles = new ArrayList<>();
             if (Files.isDirectory(context.inputDir())) {
                 try (Stream<Path> protoFilesPaths = 
Files.walk(context.inputDir())) {
                     protoFilesPaths
                             .filter(Files::isRegularFile)
-                            .filter(s -> s.toString().endsWith("json"))
+                            .filter(s -> s.toString().endsWith("json") || 
s.toString().endsWith("yaml"))
                             .map(Path::normalize)
                             .map(Path::toAbsolutePath)
                             .map(Path::toString)
-                            .forEach(jsonFiles::add);
+                            .forEach(specFiles::add);
                 }
             }
 
@@ -82,12 +82,12 @@ public class CamelQuarkusSwaggerCodegenProvider implements 
CodeGenProvider {
             String models = 
config.getOptionalValue("quarkus.camel.openapi.codegen.models", 
String.class).orElse("");
             boolean useBeanValidation = 
config.getValue("quarkus.camel.openapi.codegen.use-bean-validation", 
Boolean.class);
             boolean notNullJackson = 
config.getValue("quarkus.camel.openapi.codegen.not-null-jackson", 
Boolean.class);
-            for (String jsonFile : jsonFiles) {
+            for (String specFile : specFiles) {
                 CodegenConfigurator configurator = new CodegenConfigurator();
                 configurator.setLang("quarkus");
                 configurator.setLibrary("quarkus3");
                 configurator.setModelPackage(packageName);
-                configurator.setInputSpecURL(jsonFile);
+                configurator.setInputSpecURL(specFile);
                 
configurator.setOutputDir(context.outDir().toAbsolutePath().toString());
                 System.setProperty(CodegenConstants.MODELS, models);
                 configurator.getCodegenArguments()
diff --git 
a/integration-tests/rest-openapi/src/main/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenApiRoutes.java
 
b/integration-tests/rest-openapi/src/main/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenApiRoutes.java
index c1493d468c..ebfe02573d 100644
--- 
a/integration-tests/rest-openapi/src/main/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenApiRoutes.java
+++ 
b/integration-tests/rest-openapi/src/main/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenApiRoutes.java
@@ -25,6 +25,7 @@ public class RestOpenApiRoutes extends RouteBuilder {
     @Override
     public void configure() throws Exception {
         
rest().openApi().specification("petstore.json").missingOperation("ignore");
+        
rest().openApi().specification("example.yaml").missingOperation("ignore");
 
         from("direct:start-web-json")
                 
.toD("rest-openapi:#list?specificationUri=RAW(http://localhost:${header.test-port}/q/openapi?format=JSON)");
@@ -59,5 +60,10 @@ public class RestOpenApiRoutes extends RouteBuilder {
                     Pet pet = e.getMessage().getBody(Pet.class);
                     pet.setStatus(StatusEnum.PENDING);
                 });
+
+        from("direct:findCamels")
+                .process(e -> {
+                    e.getMessage().setBody("smart camel");
+                });
     }
 }
diff --git a/integration-tests/rest-openapi/src/main/openapi/example.yaml 
b/integration-tests/rest-openapi/src/main/openapi/example.yaml
new file mode 100644
index 0000000000..6361263206
--- /dev/null
+++ b/integration-tests/rest-openapi/src/main/openapi/example.yaml
@@ -0,0 +1,102 @@
+#
+# 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.
+#
+
+openapi: "3.0.3"
+info:
+  title: Camel API Example
+  version: 1.0.0
+  description: >
+    This is an example API.
+
+servers:
+  - url: http://ipsum.com/api
+    description: Development environment.
+  - url: http://lorem.com/api
+    description: Production environment.
+
+paths:
+  /v1/camel:
+    get:
+      operationId: findCamels
+      summary: Find camels
+      description: Search for camels.
+      parameters:
+        - in: query
+          name: name
+          description: A camel name.
+          required: true
+          schema:
+            type: string
+            example: "Glenn"
+      responses:
+        "200":
+          description: Matching camels are returned.
+          content:
+            application/json:
+              schema:
+                type: object
+                required:
+                  - camelList
+                properties:
+                  camelList:
+                    description: List containing matching camels.
+                    type: array
+                    items:
+                      $ref: "#/components/schemas/Camel"
+        "400":
+          "description": "Invalid input."
+
+components:
+  schemas:
+    Camel:
+      description: A representation of a camel.
+      type: object
+      required:
+        - id
+        - gender
+        - name
+      properties:
+        id:
+          $ref: "#/components/schemas/Id"
+        gender:
+          description: >
+            Gender:
+              - FEMALE: Female.
+              - MALE: Male.
+          type: string
+          enum: [ FEMALE, MALE ]
+          example: MALE
+        birthDate:
+          description: The date of birth.
+          type: string
+          format: date
+          example: 2024-10-28Z
+        name:
+          description: Name.
+          type: string
+          example: Glenn
+        rating:
+          description: Rating.
+          type: number
+          multipleOf: 0.01
+          example: 3.14
+
+    Id:
+      description: A camel id.
+      type: string
+      pattern: "^[A-Z]{3}-[0-9]{2}$"
+      example: ABC-42
diff --git 
a/integration-tests/rest-openapi/src/main/resources/application.properties 
b/integration-tests/rest-openapi/src/main/resources/application.properties
index bcda195242..59425bb75b 100644
--- a/integration-tests/rest-openapi/src/main/resources/application.properties
+++ b/integration-tests/rest-openapi/src/main/resources/application.properties
@@ -14,7 +14,7 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-quarkus.native.resources.includes=openapi.json,petstore.json
+quarkus.native.resources.includes=openapi.json,petstore.json,example.yaml
 
quarkus.camel.openapi.codegen.model-package=org.apache.camel.quarkus.component.rest.openapi.it.model
 quarkus.camel.openapi.codegen.not-null-jackson=true
 camel.rest.bindingMode=json
diff --git 
a/integration-tests/rest-openapi/src/test/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenapiTest.java
 
b/integration-tests/rest-openapi/src/test/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenapiTest.java
index 02980b9c4b..0b61197b02 100644
--- 
a/integration-tests/rest-openapi/src/test/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenapiTest.java
+++ 
b/integration-tests/rest-openapi/src/test/java/org/apache/camel/quarkus/component/rest/openapi/it/RestOpenapiTest.java
@@ -121,4 +121,14 @@ class RestOpenapiTest {
                 .body("id", is(123), "name", is("Test"), "status", 
is("available"));
     }
 
+    @Test
+    public void testGetCamel() {
+        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
+
+        RestAssured.given()
+                .get("/api/v1/camel")
+                .then()
+                .statusCode(200)
+                .body(is("\"smart camel\""));
+    }
 }

Reply via email to