diff --git a/client/deployment/src/main/resources/templates/libraries/microprofile/api.qute b/client/deployment/src/main/resources/templates/libraries/microprofile/api.qute index d315a412..218d5a5e 100644 --- a/client/deployment/src/main/resources/templates/libraries/microprofile/api.qute +++ b/client/deployment/src/main/resources/templates/libraries/microprofile/api.qute @@ -43,7 +43,7 @@ public interface {classname} { @io.quarkiverse.openapi.generator.markers.OperationMarker(name="{defaultSecurityScheme}", openApiSpecId="{quarkus-generator.openApiSpecId}", operationId="{op.operationId}", method="{op.httpMethod}", path="{contextPath}{commonPath}{op.path.orEmpty}") {/if} @jakarta.ws.rs.{op.httpMethod} - {#if op.subresourceOperation} + {#if op.subresourceOperation || op.path eq '/'} @jakarta.ws.rs.Path("{op.path}") {/if} {#if op.hasConsumes} diff --git a/client/integration-tests/path/pom.xml b/client/integration-tests/path/pom.xml new file mode 100644 index 00000000..c9e9f38d --- /dev/null +++ b/client/integration-tests/path/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + io.quarkiverse.openapi.generator + quarkus-openapi-generator-integration-tests + 3.0.0-SNAPSHOT + + + quarkus-openapi-generator-it-path + Quarkus - Openapi Generator - Integration Tests - Client - path + Test from path + + + + io.quarkiverse.openapi.generator + quarkus-openapi-generator + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-junit5 + test + + + + + + + io.quarkus + quarkus-maven-plugin + true + + + + build + generate-code + generate-code-tests + + + + + + + + + native-image + + + native + + + + + + maven-surefire-plugin + + ${native.surefire.skip} + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + + + \ No newline at end of file diff --git a/client/integration-tests/path/src/main/openapi/openapi-path-with-forward-slash.yaml b/client/integration-tests/path/src/main/openapi/openapi-path-with-forward-slash.yaml new file mode 100644 index 00000000..50a12a95 --- /dev/null +++ b/client/integration-tests/path/src/main/openapi/openapi-path-with-forward-slash.yaml @@ -0,0 +1,108 @@ +--- +openapi: 3.0.3 +info: + title: code-with-quarkus API + version: 1.0.0-SNAPSHOT +servers: +- url: http://localhost:8080 + description: Auto generated value +- url: http://0.0.0.0:8080 + description: Auto generated value +paths: + /users/: + get: + tags: + - User Resource + description: Find All + operationId: UserResource_findAll + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/User" + post: + tags: + - User Resource + description: Add + operationId: UserResource_add + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/User" + /users/{id}: + get: + tags: + - User Resource + description: Find + operationId: UserResource_find + parameters: + - name: id + in: path + required: true + schema: + format: int32 + type: integer + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/User" + put: + tags: + - User Resource + description: Update + operationId: UserResource_update + parameters: + - name: id + in: path + required: true + schema: + format: int32 + type: integer + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + responses: + "204": + description: No Content + delete: + tags: + - User Resource + description: Delete + operationId: UserResource_delete + parameters: + - name: id + in: path + required: true + schema: + format: int32 + type: integer + responses: + "204": + description: No Content +components: + schemas: + User: + type: object + properties: + id: + format: int32 + type: integer + name: + type: string diff --git a/client/integration-tests/path/src/main/openapi/openapi-path.yaml b/client/integration-tests/path/src/main/openapi/openapi-path.yaml new file mode 100644 index 00000000..270c78d9 --- /dev/null +++ b/client/integration-tests/path/src/main/openapi/openapi-path.yaml @@ -0,0 +1,108 @@ +--- +openapi: 3.0.3 +info: + title: code-with-quarkus API + version: 1.0.0-SNAPSHOT +servers: +- url: http://localhost:8080 + description: Auto generated value +- url: http://0.0.0.0:8080 + description: Auto generated value +paths: + /users: + get: + tags: + - User Resource + description: Find All + operationId: UserResource_findAll + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/User" + post: + tags: + - User Resource + description: Add + operationId: UserResource_add + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/User" + /users/{id}: + get: + tags: + - User Resource + description: Find + operationId: UserResource_find + parameters: + - name: id + in: path + required: true + schema: + format: int32 + type: integer + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/User" + put: + tags: + - User Resource + description: Update + operationId: UserResource_update + parameters: + - name: id + in: path + required: true + schema: + format: int32 + type: integer + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + responses: + "204": + description: No Content + delete: + tags: + - User Resource + description: Delete + operationId: UserResource_delete + parameters: + - name: id + in: path + required: true + schema: + format: int32 + type: integer + responses: + "204": + description: No Content +components: + schemas: + User: + type: object + properties: + id: + format: int32 + type: integer + name: + type: string diff --git a/client/integration-tests/path/src/main/resources/application.properties b/client/integration-tests/path/src/main/resources/application.properties new file mode 100644 index 00000000..11a6c1a9 --- /dev/null +++ b/client/integration-tests/path/src/main/resources/application.properties @@ -0,0 +1 @@ +quarkus.rest-client.quarkus_simple_openapi_yaml.url=http://localhost:8080 diff --git a/client/integration-tests/path/src/test/java/io/quarkiverse/openapi/generator/it/PathTest.java b/client/integration-tests/path/src/test/java/io/quarkiverse/openapi/generator/it/PathTest.java new file mode 100644 index 00000000..b65b2201 --- /dev/null +++ b/client/integration-tests/path/src/test/java/io/quarkiverse/openapi/generator/it/PathTest.java @@ -0,0 +1,106 @@ +package io.quarkiverse.openapi.generator.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import jakarta.ws.rs.Path; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class PathTest { + + @Test + void testPathGenerated() throws ClassNotFoundException, NoSuchMethodException { + String apiClassName = "org.openapi.quarkus.openapi_path_yaml.api.UserResourceApi"; + String modelClassName = "org.openapi.quarkus.openapi_path_yaml.model.User"; + + assertThat( + Class.forName(apiClassName) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/users"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceFind", Integer.class) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/{id}"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceFindAll") + .getAnnotation(Path.class)) + .isNull(); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceAdd", Class.forName(modelClassName)) + .getAnnotation(Path.class)) + .isNull(); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceUpdate", Integer.class, Class.forName(modelClassName)) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/{id}"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceDelete", Integer.class) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/{id}"); + } + + @Test + void testPathWithForwardSlashGenerated() throws ClassNotFoundException, NoSuchMethodException { + String apiClassName = "org.openapi.quarkus.openapi_path_with_forward_slash_yaml.api.UserResourceApi"; + String modelClassName = "org.openapi.quarkus.openapi_path_with_forward_slash_yaml.model.User"; + + assertThat( + Class.forName(apiClassName) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/users"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceFind", Integer.class) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/{id}"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceFindAll") + .getAnnotation(Path.class) + .value()) + .isEqualTo("/"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceAdd", Class.forName(modelClassName)) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceUpdate", Integer.class, Class.forName(modelClassName)) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/{id}"); + + assertThat( + Class.forName(apiClassName) + .getMethod("userResourceDelete", Integer.class) + .getAnnotation(Path.class) + .value()) + .isEqualTo("/{id}"); + } + +} diff --git a/client/integration-tests/pom.xml b/client/integration-tests/pom.xml index 5af18540..57798840 100644 --- a/client/integration-tests/pom.xml +++ b/client/integration-tests/pom.xml @@ -31,6 +31,7 @@ mutiny-return-response open-api-normalizer part-filename + path polymorphism return-response remove-operationid-prefix