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

Add support for reactive in the server extension #731

Merged
merged 7 commits into from
Jun 13, 2024
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
9 changes: 9 additions & 0 deletions docs/modules/ROOT/pages/includes/server-getting-started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Add the following dependency to your project's `pom.xml` file:
</dependency>
----

Note that since this extension has not been yet released, you'll need a local build of the dependency.

You will also need to add or update the `quarkus-maven-plugin` configuration with the following:

WARNING: You probably already have this configuration if you created your application with https://code.quarkus.io/[Code Quarkus]. That said, double-check your configuration not to add another `plugin` entry.
Expand Down Expand Up @@ -55,6 +57,13 @@ If a base package name is not provided, it will be used the default `io.apicurio
quarkus.openapi.generator.base-package=io.petstore
----

By default, the extension generates non-reactive code. If you would like to change it, you can do it as follows:

[source,properties]
----
quarkus.openapi.generator.reactive=true
----

Run `mvn compile` to generate your classes in `target/generated-sources/jaxrs` path:

[source]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CodegenConfig {
private static final String CODEGEN_BASE_PACKAGE = CODEGEN_TIME_CONFIG_PREFIX + ".base-package";
private static final String CODEGEN_SPEC = CODEGEN_TIME_CONFIG_PREFIX + ".spec";
private static final String INPUT_BASE_DIR = CODEGEN_TIME_CONFIG_PREFIX + ".input-base-dir";
private static final String CODEGEN_REACTIVE = CODEGEN_TIME_CONFIG_PREFIX + ".reactive";

public static String getBasePackagePropertyName() {
return CODEGEN_BASE_PACKAGE;
Expand All @@ -22,4 +23,8 @@ public static String getSpecPropertyName() {
public static String getInputBaseDirPropertyName() {
return INPUT_BASE_DIR;
}

public static String getCodegenReactive() {
return CODEGEN_REACTIVE;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkiverse.openapi.server.generator.deployment.codegen;

import static io.quarkiverse.openapi.server.generator.deployment.CodegenConfig.getBasePackagePropertyName;
import static io.quarkiverse.openapi.server.generator.deployment.CodegenConfig.getCodegenReactive;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -38,6 +39,7 @@ public ApicurioCodegenWrapper(Config config, File outdir, JaxRsProjectSettings p
this.outdir = outdir;
this.projectSettings = projectSettings;
this.projectSettings.setJavaPackage(getBasePackage(config));
this.projectSettings.setReactive(getReactiveValue(config));
}

public void generate(Path openApiResource) throws CodeGenException {
Expand Down Expand Up @@ -110,6 +112,12 @@ private String getBasePackage(final Config config) {
.orElse(DEFAULT_PACKAGE);
}

private Boolean getReactiveValue(final Config config) {
return config
.getOptionalValue(getCodegenReactive(), Boolean.class)
.orElse(Boolean.FALSE);
}

private static JaxRsProjectSettings defaultProjectSettings() {
JaxRsProjectSettings projectSettings = new JaxRsProjectSettings();
projectSettings.setJavaPackage(DEFAULT_PACKAGE);
Expand Down
101 changes: 9 additions & 92 deletions server/integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-openapi-generator-server-parent</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
Expand All @@ -8,98 +9,14 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-server-integration-tests</artifactId>
<packaging>pom</packaging>

<artifactId>quarkus-openapi-generator-server-integration-tests-parent</artifactId>
<name>Quarkus - Openapi Generator - Server - Integration Tests</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-server</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>reactive</module>
<module>resteasy</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
109 changes: 109 additions & 0 deletions server/integration-tests/reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-openapi-generator-server-integration-tests-parent</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-server-integration-tests-quarkus-rest</artifactId>
<name>Quarkus - Openapi Generator - Server - Integration Tests - Quarkus REST (formerly RESTEasy Reactive)</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-server</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package petstore;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import io.petstore.PetResource;
import io.petstore.beans.ApiResponse;
import io.petstore.beans.Pet;

public class PetStoreImpl implements PetResource {

private static final Map<Long, Pet> PETS = new HashMap<>();

@Override
public CompletionStage<Pet> updatePet(Pet data) {
return CompletableFuture.completedFuture(PETS.put(data.getId(), data));
}

@Override
public CompletionStage<Pet> addPet(Pet data) {
return CompletableFuture.completedFuture(PETS.put(data.getId(), data));
}

@Override
public CompletionStage<List<Pet>> findPetsByStatus(String status) {
return null;
}

@Override
public CompletionStage<List<Pet>> findPetsByTags(List<String> tags) {
return null;
}

@Override
public CompletionStage<Pet> getPetById(long petId) {
return CompletableFuture.completedFuture(PETS.get(petId));
}

@Override
public CompletionStage<Void> updatePetWithForm(long petId, String name, String status) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletionStage<Void> deletePet(String apiKey, long petId) {
PETS.remove(petId);
return CompletableFuture.completedFuture(null);
}

@Override
public CompletionStage<ApiResponse> uploadFile(long petId, String additionalMetadata, InputStream data) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Codegen properties
quarkus.openapi.generator.spec=petstore-openapi.json
quarkus.openapi.generator.base-package=io.petstore
quarkus.openapi.generator.reactive=true
Loading