Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public enum ConfigName {
USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"),
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
BEAN_VALIDATION("use-bean-validation");
BEAN_VALIDATION("use-bean-validation"),
GENERATE_APIS("generate-apis"),
GENERATE_MODELS("generate-models");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,16 @@ public class CommonItemConfig {
*/
@ConfigItem(name = "use-bean-validation")
public Optional<Boolean> useBeanValidation;

/**
* Enable the generation of APIs. If you set this to {@code false}, APIs will not be generated.
*/
@ConfigItem(name = "generate-apis")
public Optional<Boolean> generateApis;

/**
* Enable the generation of models. If you set this to {@code false}, models will not be generated.
*/
@ConfigItem(name = "generate-models")
public Optional<Boolean> generateModels;
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ protected void generate(OpenApiGeneratorOptions options) {
getValues(config, openApiFilePath, CodegenConfig.ConfigName.BEAN_VALIDATION, Boolean.class)
.ifPresent(generator::withUseBeanValidation);

getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_APIS, Boolean.class)
.ifPresent(generator::withGenerateApis);

getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_MODELS, Boolean.class)
.ifPresent(generator::withGenerateModels);

SmallRyeConfig smallRyeConfig = config.unwrap(SmallRyeConfig.class);

getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.TYPE_MAPPINGS, String.class, String.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ public OpenApiClientGeneratorWrapper withUseBeanValidation(Boolean config) {
return this;
}

public OpenApiClientGeneratorWrapper withGenerateApis(Boolean config) {
configurator.addAdditionalProperty("generate-apis", config);
return this;
}

public OpenApiClientGeneratorWrapper withGenerateModels(Boolean config) {
configurator.addAdditionalProperty("generate-models", config);
return this;
}

public OpenApiClientGeneratorWrapper withApiNameSuffix(final String apiNameSuffix) {
this.configurator.setApiNameSuffix(apiNameSuffix);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ private void replaceWithQuarkusTemplateFiles() {
supportingFiles.clear();

Boolean enableSecurityGeneration = (Boolean) this.additionalProperties.get("enable-security-generation");
Boolean generateApis = (Boolean) this.additionalProperties.getOrDefault("generate-apis", Boolean.TRUE);
Boolean generateModels = (Boolean) this.additionalProperties.getOrDefault("generate-models", Boolean.TRUE);

if (enableSecurityGeneration == null || enableSecurityGeneration) {
if (ProcessUtils.hasHttpBasicMethods(this.openAPI) ||
Expand All @@ -92,10 +94,14 @@ private void replaceWithQuarkusTemplateFiles() {
}

apiTemplateFiles.clear();
apiTemplateFiles.put("api.qute", ".java");
if (generateApis) {
apiTemplateFiles.put("api.qute", ".java");
}

modelTemplateFiles.clear();
modelTemplateFiles.put("model.qute", ".java");
if (generateModels) {
modelTemplateFiles.put("model.qute", ".java");
}
}

public String authFileFolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class OpenApiConfigValidatorTest {
"quarkus.openapi-generator.codegen.additional-api-type-annotations",
"quarkus.openapi-generator.codegen.spec.spec_yaml.enable-security-generation",
"quarkus.openapi-generator.codegen.type-mappings.UUID=String",
"quarkus.openapi-generator.codegen.spec.spec_yaml.type-mappings.UUID=String"
"quarkus.openapi-generator.codegen.spec.spec_yaml.type-mappings.UUID=String",
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-apis=false",
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-models=false",
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-apis=true",
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-models=true",
Comment on lines +22 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These additions are no longer necessary, are they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hbelmiro I removed them but in the process messed my repo up pretty good so I had to create a new PR: #897

})
void test_known_configs_ok(String validConfiguration) {
assertThatCode(() -> OpenApiConfigValidator.validateInputConfiguration(List.of(validConfiguration)))
Expand Down
97 changes: 97 additions & 0 deletions client/integration-tests/generate-flags/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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-integration-tests</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-it-generate-flags</artifactId>
<name>Quarkus - Openapi Generator - Integration Tests - Client - Generate Flags</name>
<description>Example project for usage of the generate-models and generate-apis properties</description>

<dependencies>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager
</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
openapi: 3.0.3
info:
title: Test API
version: "1.0"
paths:
/{pathParam}:
get:
tags:
- NonExistentEndpoint
operationId: test
parameters:
- name: pathParam
in: path
required: true
schema:
type: string
minimum: 5
- name: headerParam
in: header
required: false
schema:
type: integer
maximum: 5
- name: cookieParam
in: cookie
required: true
schema:
type: string
minLength: 10
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
components:
schemas:
ExistentObject:
type: object
description: Some object not to be validated
required:
- id
- name
- size
properties:
id:
type: integer
minimum: 1
maximum: 100
name:
type: string
pattern: "[a-zA-Z]*"
minLength: 1
maxLength: 10
size:
type: number
minimum: 1.0
maximum: 10.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
openapi: 3.0.3
info:
title: Test API
version: "1.0"
paths:
/{pathParam}:
get:
tags:
- ExistentEndpoint
operationId: test
parameters:
- name: pathParam
in: path
required: true
schema:
type: string
minimum: 5
- name: headerParam
in: header
required: false
schema:
type: integer
maximum: 5
- name: cookieParam
in: cookie
required: true
schema:
type: string
minLength: 10
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
components:
schemas:
NonExistentObject:
type: object
description: Some object not to be validated
required:
- id
- name
- size
properties:
id:
type: integer
minimum: 1
maximum: 100
name:
type: string
pattern: "[a-zA-Z]*"
minLength: 1
maxLength: 10
size:
type: number
minimum: 1.0
maximum: 10.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkus.openapi-generator.codegen.spec.generate_models_false_yaml.generate-models = false
quarkus.openapi-generator.codegen.spec.generate_apis_false_yaml.generate-apis = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkiverse.openapi.generator.it;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class GenerateFlagsTest {

@Test
void testEndpointIsInPlace() throws ClassNotFoundException {
Class.forName("org.openapi.quarkus.generate_models_false_yaml.api.ExistentEndpointApi");
}

@Test
void testModelIsInPlace() throws ClassNotFoundException {
Class.forName("org.openapi.quarkus.generate_apis_false_yaml.model.ExistentObject");
}

@Test
void testEndpointIsNotInPlace() {
Assertions.assertThatThrownBy(() -> {
Class.forName("org.openapi.quarkus.generate_apis_false_yaml.model.NonExistentEndpointApi");
}).isInstanceOf(ClassNotFoundException.class);
}

@Test
void testModelIsNotInPlace() {
Assertions.assertThatThrownBy(() -> {
Class.forName("org.openapi.quarkus.generate_models_false_yaml.api.NonExistentObject");
}).isInstanceOf(ClassNotFoundException.class);
}

}
1 change: 1 addition & 0 deletions client/integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<module>enum-property</module>
<module>enum-unexpected</module>
<module>exclude</module>
<module>generate-flags</module>
<module>generation-input</module>
<module>generation-tests</module>
<module>include</module>
Expand Down
10 changes: 10 additions & 0 deletions docs/modules/ROOT/pages/client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ include::./includes/additional-request-args.adoc[leveloffset=+1, opts=optional]

include::./includes/bean-validation.adoc[leveloffset=+1, opts=optional]

[[generate-apis]]
== Generate APIs

include::./includes/generate-apis.adoc[leveloffset=+1, opts=optional]

[[generate-models]]
== Generate Models

include::./includes/generate-models.adoc[leveloffset=+1, opts=optional]

== Known Limitations

=== Supported Arguments
Expand Down
6 changes: 6 additions & 0 deletions docs/modules/ROOT/pages/includes/generate-apis.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
APIs are generated by default. To disable them set `generate-apis` to false:

[source,properties]
----
quarkus.openapi-generator.codegen.spec.my_openapi_yaml.generate-apis=false
----
Loading