Skip to content

Commit 92b5a96

Browse files
authored
[issue-39] Added feature to ignore code generation for specific OpenA… (#171)
* [issue-39] Added feature to ignore code generation for specific OpenAPI documents Signed-off-by: Helber Belmiro <[email protected]> * [issue-39] Improved loop Signed-off-by: Helber Belmiro <[email protected]> Signed-off-by: Helber Belmiro <[email protected]>
1 parent 2ca2af1 commit 92b5a96

File tree

9 files changed

+456
-7
lines changed

9 files changed

+456
-7
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ Since the most part of this extension work is in the `generate-code` execution p
120120

121121
For more information, see the [Maven Logging Configuration](https://maven.apache.org/maven-logging.html) guide.
122122

123+
## Ignoring OpenAPI Specification Files
124+
125+
To ignore code generation for specific OpenAPI specification files, you can set the `quarkus.openapi-generator.codegen.ignore` property.
126+
127+
For instance, if you want to ignore code generation for `ignored-openapi.yaml` and `ignored-openapi-2.yaml` files, you need to define the `quarkus.openapi-generator.codegen.ignore` property like the following:
128+
129+
```properties
130+
quarkus.openapi-generator.codegen.ignore=ignored-openapi.yaml,ignored-openapi-2.yaml
131+
```
132+
133+
See the module [ignore](integration-tests/ignore) for an example of how to use this feature.
134+
123135
## Authentication Support
124136

125137
If your OpenAPI specification file has `securitySchemes` [definitions](https://spec.openapis.org/oas/v3.1.0#security-scheme-object), the inner generator

deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package io.quarkiverse.openapi.generator.deployment.codegen;
22

3-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.*;
4-
53
import java.io.IOException;
64
import java.nio.file.Files;
75
import java.nio.file.Path;
6+
import java.util.List;
87
import java.util.stream.Stream;
98

109
import org.eclipse.microprofile.config.Config;
@@ -18,6 +17,16 @@
1817
import io.quarkus.deployment.CodeGenProvider;
1918
import io.smallrye.config.SmallRyeConfig;
2019

20+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.VALIDATE_SPEC_PROPERTY_NAME;
21+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.VERBOSE_PROPERTY_NAME;
22+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getAdditionalModelTypeAnnotationsPropertyName;
23+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getBasePackagePropertyName;
24+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getCustomRegisterProvidersFormat;
25+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getImportMappingsPropertyName;
26+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSanitizedFileName;
27+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSkipFormModelPropertyName;
28+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getTypeMappingsPropertyName;
29+
2130
/**
2231
* Code generation for OpenApi Client. Generates Java classes from OpenApi spec files located in src/main/openapi or
2332
* src/test/openapi
@@ -41,16 +50,18 @@ public String inputDirectory() {
4150
public boolean trigger(CodeGenContext context) throws CodeGenException {
4251
final Path outDir = context.outDir();
4352
final Path openApiDir = context.inputDir();
53+
final List<String> ignoredFiles = context.config()
54+
.getOptionalValues("quarkus.openapi-generator.codegen.ignore", String.class).orElse(List.of());
4455

4556
if (Files.isDirectory(openApiDir)) {
4657
try (Stream<Path> openApiFilesPaths = Files.walk(openApiDir)) {
4758
openApiFilesPaths
4859
.filter(Files::isRegularFile)
49-
.map(Path::toString)
50-
.filter(s -> s.endsWith(this.inputExtension()))
51-
.map(Path::of).forEach(openApiFilePath -> {
52-
this.generate(context.config(), openApiFilePath, outDir);
53-
});
60+
.filter(path -> {
61+
String fileName = path.getFileName().toString();
62+
return fileName.endsWith(inputExtension()) && !ignoredFiles.contains(fileName);
63+
})
64+
.forEach(openApiFilePath -> generate(context.config(), openApiFilePath, outDir));
5465
} catch (IOException e) {
5566
throw new CodeGenException("Failed to generate java files from OpenApi files in " + openApiDir.toAbsolutePath(),
5667
e);

integration-tests/ignore/pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<parent>
4+
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
5+
<groupId>io.quarkiverse.openapi.generator</groupId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>quarkus-openapi-generator-it-ignore</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - Ignore</name>
12+
<description>Example project with OpenAPI documents that should be ignored</description>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.quarkiverse.openapi.generator</groupId>
17+
<artifactId>quarkus-openapi-generator</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.assertj</groupId>
21+
<artifactId>assertj-core</artifactId>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.quarkus</groupId>
26+
<artifactId>quarkus-junit5</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>io.quarkus</groupId>
34+
<artifactId>quarkus-maven-plugin</artifactId>
35+
<extensions>true</extensions>
36+
<executions>
37+
<execution>
38+
<goals>
39+
<goal>build</goal>
40+
<goal>generate-code</goal>
41+
<goal>generate-code-tests</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
<profiles>
49+
<profile>
50+
<id>native-image</id>
51+
<activation>
52+
<property>
53+
<name>native</name>
54+
</property>
55+
</activation>
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<artifactId>maven-surefire-plugin</artifactId>
60+
<configuration>
61+
<skipTests>${native.surefire.skip}</skipTests>
62+
</configuration>
63+
</plugin>
64+
<plugin>
65+
<artifactId>maven-failsafe-plugin</artifactId>
66+
<executions>
67+
<execution>
68+
<goals>
69+
<goal>integration-test</goal>
70+
<goal>verify</goal>
71+
</goals>
72+
<configuration>
73+
<systemPropertyVariables>
74+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
75+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
76+
<maven.home>${maven.home}</maven.home>
77+
</systemPropertyVariables>
78+
</configuration>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
<properties>
85+
<quarkus.package.type>native</quarkus.package.type>
86+
</properties>
87+
</profile>
88+
</profiles>
89+
90+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: greeting-flow API
5+
version: "1.0"
6+
paths:
7+
/hello_ignored_2:
8+
get:
9+
tags:
10+
- Ignored OpenAPI Resource 2
11+
operationId: hello_ignored_2
12+
responses:
13+
"200":
14+
description: OK
15+
content:
16+
text/plain:
17+
schema:
18+
type: string
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: greeting-flow API
5+
version: "1.0"
6+
paths:
7+
/hello_ignored:
8+
get:
9+
tags:
10+
- Ignored OpenAPI Resource
11+
operationId: hello_ignored
12+
responses:
13+
"200":
14+
description: OK
15+
content:
16+
text/plain:
17+
schema:
18+
type: string

0 commit comments

Comments
 (0)