Skip to content

Commit 10be4d3

Browse files
remove operation id prefix (#873) (#880)
Co-authored-by: yuhaibohotmail <[email protected]>
1 parent b4d52c0 commit 10be4d3

File tree

10 files changed

+264
-0
lines changed

10 files changed

+264
-0
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public enum ConfigName {
6767
USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"),
6868
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
6969
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
70+
REMOVE_OPERATION_ID_PREFIX("remove-operation-id-prefix"),
7071
BEAN_VALIDATION("use-bean-validation");
7172

7273
private final String name;

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/SpecItemConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ public class SpecItemConfig extends CommonItemConfig {
3838
*/
3939
@ConfigItem(name = "model-name-prefix")
4040
public Optional<String> modelNamePrefix;
41+
42+
/**
43+
* Remove operation id prefix
44+
*/
45+
@ConfigItem(name = "remove-operation-id-prefix")
46+
public Optional<String> removeOperationIdPrefix;
47+
4148
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.INPUT_BASE_DIR;
1414
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_PREFIX;
1515
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_SUFFIX;
16+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX;
1617
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.TEMPLATE_BASE_DIR;
1718
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.VALIDATE_SPEC;
1819

@@ -228,6 +229,9 @@ protected void generate(OpenApiGeneratorOptions options) {
228229
getModelNamePrefix(config, openApiFilePath)
229230
.ifPresent(generator::withModelNamePrefix);
230231

232+
getRemoveOperationIdPrefix(config, openApiFilePath)
233+
.ifPresent(generator::withRemoveOperationIdPrefix);
234+
231235
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY, Boolean.class)
232236
.ifPresent(generator::withMutiny);
233237

@@ -350,6 +354,11 @@ private Optional<String> getModelNamePrefix(final Config config, final Path open
350354
.getOptionalValue(getSpecConfigName(MODEL_NAME_PREFIX, openApiFilePath), String.class);
351355
}
352356

357+
private Optional<Boolean> getRemoveOperationIdPrefix(final Config config, final Path openApiFilePath) {
358+
return config
359+
.getOptionalValue(getSpecConfigName(REMOVE_OPERATION_ID_PREFIX, openApiFilePath), Boolean.class);
360+
}
361+
353362
private Optional<String> getInputBaseDirRelativeToModule(final Path sourceDir, final Config config) {
354363
return config.getOptionalValue(getGlobalConfigName(INPUT_BASE_DIR), String.class).map(baseDir -> {
355364
int srcIndex = sourceDir.toString().lastIndexOf("src");

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ public OpenApiClientGeneratorWrapper withModelNameSuffix(final String modelNameS
280280
return this;
281281
}
282282

283+
public OpenApiClientGeneratorWrapper withRemoveOperationIdPrefix(final Boolean removeOperationIdPrefix) {
284+
this.configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
285+
return this;
286+
}
287+
283288
public OpenApiClientGeneratorWrapper withModelNamePrefix(final String modelNamePrefix) {
284289
this.configurator.setModelNamePrefix(modelNamePrefix);
285290
return this;

client/integration-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<module>part-filename</module>
3434
<module>polymorphism</module>
3535
<module>return-response</module>
36+
<module>remove-operationid-prefix</module>
3637
<module>security</module>
3738
<module>simple</module>
3839
<module>skip-validation</module>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.quarkiverse.openapi.generator</groupId>
6+
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
7+
<version>3.0.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>quarkus-openapi-generator-it-remove-operationid-prefix</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - Client - remove operation id prefix</name>
12+
<description>Example project for general usage with remove operation id prefix</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+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>io.quarkus</groupId>
35+
<artifactId>quarkus-maven-plugin</artifactId>
36+
<extensions>true</extensions>
37+
<executions>
38+
<execution>
39+
<goals>
40+
<goal>build</goal>
41+
<goal>generate-code</goal>
42+
<goal>generate-code-tests</goal>
43+
</goals>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
<profiles>
50+
<profile>
51+
<id>native-image</id>
52+
<activation>
53+
<property>
54+
<name>native</name>
55+
</property>
56+
</activation>
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<artifactId>maven-surefire-plugin</artifactId>
61+
<configuration>
62+
<skipTests>${native.surefire.skip}</skipTests>
63+
</configuration>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-failsafe-plugin</artifactId>
67+
<executions>
68+
<execution>
69+
<goals>
70+
<goal>integration-test</goal>
71+
<goal>verify</goal>
72+
</goals>
73+
<configuration>
74+
<systemPropertyVariables>
75+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
76+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
77+
<maven.home>${maven.home}</maven.home>
78+
</systemPropertyVariables>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
<properties>
86+
<quarkus.package.type>native</quarkus.package.type>
87+
</properties>
88+
</profile>
89+
</profiles>
90+
91+
</project>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: code-with-quarkus API
5+
version: 1.0.0-SNAPSHOT
6+
servers:
7+
- url: http://localhost:8080
8+
description: Auto generated value
9+
- url: http://0.0.0.0:8080
10+
description: Auto generated value
11+
paths:
12+
/users:
13+
get:
14+
tags:
15+
- User Resource
16+
description: Find All
17+
operationId: UserResource_findAll
18+
responses:
19+
"200":
20+
description: OK
21+
content:
22+
application/json:
23+
schema:
24+
type: array
25+
items:
26+
$ref: "#/components/schemas/User"
27+
post:
28+
tags:
29+
- User Resource
30+
description: Add
31+
operationId: UserResource_add
32+
requestBody:
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "#/components/schemas/User"
37+
responses:
38+
"200":
39+
description: OK
40+
content:
41+
application/json:
42+
schema:
43+
$ref: "#/components/schemas/User"
44+
/users/{id}:
45+
get:
46+
tags:
47+
- User Resource
48+
description: Find
49+
operationId: UserResource_find
50+
parameters:
51+
- name: id
52+
in: path
53+
required: true
54+
schema:
55+
format: int32
56+
type: integer
57+
responses:
58+
"200":
59+
description: OK
60+
content:
61+
application/json:
62+
schema:
63+
$ref: "#/components/schemas/User"
64+
put:
65+
tags:
66+
- User Resource
67+
description: Update
68+
operationId: UserResource_update
69+
parameters:
70+
- name: id
71+
in: path
72+
required: true
73+
schema:
74+
format: int32
75+
type: integer
76+
requestBody:
77+
content:
78+
application/json:
79+
schema:
80+
$ref: "#/components/schemas/User"
81+
responses:
82+
"204":
83+
description: No Content
84+
delete:
85+
tags:
86+
- User Resource
87+
description: Delete
88+
operationId: UserResource_delete
89+
parameters:
90+
- name: id
91+
in: path
92+
required: true
93+
schema:
94+
format: int32
95+
type: integer
96+
responses:
97+
"204":
98+
description: No Content
99+
components:
100+
schemas:
101+
User:
102+
type: object
103+
properties:
104+
id:
105+
format: int32
106+
type: integer
107+
name:
108+
type: string
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
quarkus.rest-client.quarkus_simple_openapi_yaml.url=http://localhost:8080
2+
quarkus.openapi-generator.codegen.spec.openapi_remove_operation_id_prefix_yaml.remove-operation-id-prefix=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.quarkiverse.openapi.generator.it;
2+
3+
import static org.assertj.core.api.Assertions.assertThatCode;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import io.quarkus.test.junit.QuarkusTest;
8+
9+
@QuarkusTest
10+
public class RemoveOperationIdPrefixTest {
11+
12+
String apiClassName = "org.openapi.quarkus.openapi_remove_operation_id_prefix_yaml.api.UserResourceApi";
13+
String modelClassName = "org.openapi.quarkus.openapi_remove_operation_id_prefix_yaml.model.User";
14+
15+
@Test
16+
void apiIsBeingGenerated() {
17+
assertThatCode(() -> Class.forName(apiClassName).getMethod("find", Integer.class))
18+
.doesNotThrowAnyException();
19+
20+
assertThatCode(() -> Class.forName(apiClassName).getMethod("findAll"))
21+
.doesNotThrowAnyException();
22+
23+
assertThatCode(() -> Class.forName(apiClassName).getMethod("add", Class.forName(modelClassName)))
24+
.doesNotThrowAnyException();
25+
26+
assertThatCode(() -> Class.forName(apiClassName).getMethod("update", Integer.class, Class.forName(modelClassName)))
27+
.doesNotThrowAnyException();
28+
29+
assertThatCode(() -> Class.forName(apiClassName).getMethod("delete", Integer.class))
30+
.doesNotThrowAnyException();
31+
32+
}
33+
}

docs/modules/ROOT/pages/includes/getting-started.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ quarkus.openapi-generator.codegen.spec.petstore_json.model-name-suffix=CustomMod
8888
quarkus.openapi-generator.codegen.spec.petstore_json.model-name-prefix=CustomModelPrefix
8989
----
9090

91+
You can remove operationId prefix (e.g. User_findAll=> findAll). To do that, you must define the following properties:
92+
93+
[source,properties]
94+
----
95+
quarkus.openapi-generator.codegen.spec.petstore_json.remove-operation-id-prefix=true
96+
----
97+
9198
The same way you can add any additional annotations to the generated api files with `additional-api-type-annotations`. Given you want to include Foo and Bar annotations, you must define additional-api-type-annotations as:
9299

93100
[source,properties]

0 commit comments

Comments
 (0)