Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hibernate-reactive-rest-data-panache when adding smallrye openapi #26074

Merged
merged 1 commit into from Jun 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,67 @@
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi;

import java.util.List;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.builder.Version;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.AbstractEntity;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.AbstractItem;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.Collection;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.CollectionsRepository;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.CollectionsResource;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.EmptyListItem;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.EmptyListItemsRepository;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.EmptyListItemsResource;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.Item;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.ItemsRepository;
import io.quarkus.hibernate.orm.rest.data.panache.deployment.repository.ItemsResource;
import io.quarkus.test.QuarkusProdModeTest;
import io.restassured.RestAssured;

class OpenApiIntegrationTest {

private static final String OPEN_API_PATH = "/q/openapi";

@RegisterExtension
static final QuarkusProdModeTest TEST = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(Collection.class, CollectionsResource.class, CollectionsRepository.class,
AbstractEntity.class, AbstractItem.class, Item.class, ItemsResource.class,
ItemsRepository.class, EmptyListItem.class, EmptyListItemsRepository.class,
EmptyListItemsResource.class)
.addAsResource("application.properties")
.addAsResource("import.sql"))
.setForcedDependencies(List.of(
new AppArtifact("io.quarkus", "quarkus-smallrye-openapi", Version.getVersion()),
new AppArtifact("io.quarkus", "quarkus-jdbc-h2-deployment", Version.getVersion()),
new AppArtifact("io.quarkus", "quarkus-resteasy-jsonb-deployment", Version.getVersion())))
.setRun(true);

@Test
public void testOpenApiForGeneratedResources() {
RestAssured.given().queryParam("format", "JSON")
.when().get(OPEN_API_PATH)
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("info.title", Matchers.equalTo("quarkus-hibernate-orm-rest-data-panache-deployment API"))
.body("paths.'/collections'", Matchers.hasKey("get"))
.body("paths.'/collections'", Matchers.hasKey("post"))
.body("paths.'/collections/{id}'", Matchers.hasKey("get"))
.body("paths.'/collections/{id}'", Matchers.hasKey("put"))
.body("paths.'/collections/{id}'", Matchers.hasKey("delete"))
.body("paths.'/empty-list-items'", Matchers.hasKey("get"))
.body("paths.'/empty-list-items'", Matchers.hasKey("post"))
.body("paths.'/empty-list-items/{id}'", Matchers.hasKey("get"))
.body("paths.'/empty-list-items/{id}'", Matchers.hasKey("put"))
.body("paths.'/empty-list-items/{id}'", Matchers.hasKey("delete"))
.body("paths.'/items'", Matchers.hasKey("get"))
.body("paths.'/items'", Matchers.hasKey("post"))
.body("paths.'/items/{id}'", Matchers.hasKey("get"))
.body("paths.'/items/{id}'", Matchers.hasKey("put"))
.body("paths.'/items/{id}'", Matchers.hasKey("delete"));
}
}
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>quarkus-hibernate-reactive-rest-data-panache-deployment</artifactId>
<name>Quarkus - Hibernate ORM Reactive data with Panache - Deployment</name>
<name>Quarkus - Hibernate Reactive Reactive data with Panache - Deployment</name>

<!-- Defaults, to simplify local testing -->
<properties>
Expand Down
@@ -0,0 +1,67 @@
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.openapi;

import java.util.List;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.builder.Version;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.AbstractEntity;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.AbstractItem;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.Collection;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.CollectionsRepository;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.CollectionsResource;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.EmptyListItem;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.EmptyListItemsRepository;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.EmptyListItemsResource;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.Item;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.ItemsRepository;
import io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository.ItemsResource;
import io.quarkus.test.QuarkusProdModeTest;
import io.restassured.RestAssured;

class OpenApiIntegrationTest {

private static final String OPEN_API_PATH = "/q/openapi";

@RegisterExtension
static final QuarkusProdModeTest TEST = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(Collection.class, CollectionsResource.class, CollectionsRepository.class,
AbstractEntity.class, AbstractItem.class, Item.class, ItemsResource.class,
ItemsRepository.class, EmptyListItem.class, EmptyListItemsRepository.class,
EmptyListItemsResource.class)
.addAsResource("application.properties")
.addAsResource("import.sql"))
.setForcedDependencies(List.of(
new AppArtifact("io.quarkus", "quarkus-smallrye-openapi", Version.getVersion()),
new AppArtifact("io.quarkus", "quarkus-reactive-pg-client-deployment", Version.getVersion()),
new AppArtifact("io.quarkus", "quarkus-resteasy-reactive-jsonb-deployment", Version.getVersion())))
.setRun(true);

@Test
public void testOpenApiForGeneratedResources() {
RestAssured.given().queryParam("format", "JSON")
.when().get(OPEN_API_PATH)
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("info.title", Matchers.equalTo("quarkus-hibernate-reactive-rest-data-panache-deployment API"))
.body("paths.'/collections'", Matchers.hasKey("get"))
.body("paths.'/collections'", Matchers.hasKey("post"))
.body("paths.'/collections/{id}'", Matchers.hasKey("get"))
.body("paths.'/collections/{id}'", Matchers.hasKey("put"))
.body("paths.'/collections/{id}'", Matchers.hasKey("delete"))
.body("paths.'/empty-list-items'", Matchers.hasKey("get"))
.body("paths.'/empty-list-items'", Matchers.hasKey("post"))
.body("paths.'/empty-list-items/{id}'", Matchers.hasKey("get"))
.body("paths.'/empty-list-items/{id}'", Matchers.hasKey("put"))
.body("paths.'/empty-list-items/{id}'", Matchers.hasKey("delete"))
.body("paths.'/items'", Matchers.hasKey("get"))
.body("paths.'/items'", Matchers.hasKey("post"))
.body("paths.'/items/{id}'", Matchers.hasKey("get"))
.body("paths.'/items/{id}'", Matchers.hasKey("put"))
.body("paths.'/items/{id}'", Matchers.hasKey("delete"));
}
}
@@ -1,6 +1,7 @@
package io.quarkus.rest.data.panache.deployment.methods;

import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType;

import javax.validation.Valid;
import javax.ws.rs.core.Response;
Expand All @@ -13,6 +14,7 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -100,8 +102,8 @@ public AddMethodImplementor(boolean withValidation, boolean isResteasyClassic, b
@Override
protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
resourceMetadata.getEntityType());

// Add method annotations
Expand Down
@@ -1,6 +1,7 @@
package io.quarkus.rest.data.panache.deployment.methods;

import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType;

import javax.ws.rs.core.Response;

Expand All @@ -13,6 +14,7 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -83,8 +85,8 @@ public DeleteMethodImplementor(boolean isResteasyClassic, boolean isReactivePana
@Override
protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
resourceMetadata.getIdType());

// Add method annotations
Expand Down
@@ -1,6 +1,7 @@
package io.quarkus.rest.data.panache.deployment.methods;

import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType;

import javax.ws.rs.core.Response;

Expand All @@ -13,6 +14,7 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -85,8 +87,8 @@ public GetMethodImplementor(boolean isResteasyClassic, boolean isReactivePanache
@Override
protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
resourceMetadata.getIdType());

// Add method annotations
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
import static io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor.DEFAULT_PAGE_INDEX;
import static io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor.DEFAULT_PAGE_SIZE;
import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType;

import java.util.List;

Expand All @@ -21,6 +22,7 @@
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor;
import io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator;
import io.quarkus.rest.data.panache.deployment.utils.SortImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;
Expand Down Expand Up @@ -131,8 +133,8 @@ protected String getResourceMethodName() {
private void implementPaged(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
// Method parameters: sort strings, page index, page size, uri info
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
List.class, int.class, int.class, UriInfo.class);

// Add method annotations
Expand Down Expand Up @@ -196,8 +198,8 @@ private void implementPaged(ClassCreator classCreator, ResourceMetadata resource

private void implementNotPaged(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceFieldDescriptor) {
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
List.class);

// Add method annotations
Expand Down
@@ -1,6 +1,7 @@
package io.quarkus.rest.data.panache.deployment.methods;

import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType;

import java.lang.annotation.Annotation;
import java.util.function.Supplier;
Expand All @@ -23,6 +24,7 @@
import io.quarkus.rest.data.panache.RestDataResource;
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.quarkus.rest.data.panache.runtime.UpdateExecutor;
import io.smallrye.mutiny.Uni;
Expand Down Expand Up @@ -132,8 +134,8 @@ public UpdateMethodImplementor(boolean withValidation, boolean isResteasyClassic
@Override
protected void implementInternal(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
resourceMetadata.getIdType(), resourceMetadata.getEntityType());

// Add method annotations
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static io.quarkus.gizmo.MethodDescriptor.ofMethod;
import static io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor.DEFAULT_PAGE_INDEX;
import static io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor.DEFAULT_PAGE_SIZE;
import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType;

import java.util.List;

Expand All @@ -24,6 +25,7 @@
import io.quarkus.rest.data.panache.deployment.ResourceMetadata;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.rest.data.panache.deployment.utils.PaginationImplementor;
import io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator;
import io.quarkus.rest.data.panache.deployment.utils.SortImplementor;
import io.quarkus.rest.data.panache.deployment.utils.UniImplementor;
import io.smallrye.mutiny.Uni;
Expand Down Expand Up @@ -123,8 +125,8 @@ protected String getResourceMethodName() {
private void implementPaged(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
// Method parameters: sort strings, page index, page size, uri info
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
List.class, int.class, int.class, UriInfo.class);

// Add method annotations
Expand Down Expand Up @@ -197,8 +199,8 @@ private void returnWrappedHalEntitiesWithLinks(BytecodeCreator body, ResourceMet

private void implementNotPaged(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceFieldDescriptor) {
MethodCreator methodCreator = classCreator.getMethodCreator(METHOD_NAME,
isNotReactivePanache() ? Response.class : Uni.class,
MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(METHOD_NAME, classCreator,
isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, resourceMetadata.getEntityType()),
List.class);

// Add method annotations
Expand Down