Skip to content

Commit 0719839

Browse files
Improve remove operation id prefix (#886)
1 parent babae9b commit 0719839

File tree

9 files changed

+327
-4
lines changed

9 files changed

+327
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public enum ConfigName {
6969
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
7070
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
7171
REMOVE_OPERATION_ID_PREFIX("remove-operation-id-prefix"),
72+
REMOVE_OPERATION_ID_PREFIX_DELIMITER("remove-operation-id-prefix-delimiter"),
73+
REMOVE_OPERATION_ID_PREFIX_COUNT("remove-operation-id-prefix-count"),
7274
BEAN_VALIDATION("use-bean-validation");
7375

7476
private final String name;

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ public class SpecItemConfig extends CommonItemConfig {
4343
* Remove operation id prefix
4444
*/
4545
@ConfigItem(name = "remove-operation-id-prefix")
46-
public Optional<String> removeOperationIdPrefix;
46+
public Optional<Boolean> removeOperationIdPrefix;
4747

48+
/**
49+
* Remove operation id prefix
50+
*/
51+
@ConfigItem(name = "remove-operation-id-prefix-delimiter")
52+
public Optional<String> removeOperationIdPrefixDelimiter;
53+
54+
/**
55+
* Remove operation id prefix
56+
*/
57+
@ConfigItem(name = "remove-operation-id-prefix-count")
58+
public Optional<Integer> removeOperationIdPrefixCount;
4859
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
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;
1616
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX;
17+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX_COUNT;
18+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX_DELIMITER;
1719
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.TEMPLATE_BASE_DIR;
1820
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.VALIDATE_SPEC;
1921

@@ -232,6 +234,12 @@ protected void generate(OpenApiGeneratorOptions options) {
232234
getRemoveOperationIdPrefix(config, openApiFilePath)
233235
.ifPresent(generator::withRemoveOperationIdPrefix);
234236

237+
getRemoveOperationIdPrefixDelimiter(config, openApiFilePath)
238+
.ifPresent(generator::withRemoveOperationIdPrefixDelimiter);
239+
240+
getRemoveOperationIdPrefixCount(config, openApiFilePath)
241+
.ifPresent(generator::withRemoveOperationIdPrefixCount);
242+
235243
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY, Boolean.class)
236244
.ifPresent(generator::withMutiny);
237245

@@ -362,6 +370,16 @@ private Optional<Boolean> getRemoveOperationIdPrefix(final Config config, final
362370
.getOptionalValue(getSpecConfigName(REMOVE_OPERATION_ID_PREFIX, openApiFilePath), Boolean.class);
363371
}
364372

373+
private Optional<String> getRemoveOperationIdPrefixDelimiter(final Config config, final Path openApiFilePath) {
374+
return config
375+
.getOptionalValue(getSpecConfigName(REMOVE_OPERATION_ID_PREFIX_DELIMITER, openApiFilePath), String.class);
376+
}
377+
378+
private Optional<Integer> getRemoveOperationIdPrefixCount(final Config config, final Path openApiFilePath) {
379+
return config
380+
.getOptionalValue(getSpecConfigName(REMOVE_OPERATION_ID_PREFIX_COUNT, openApiFilePath), Integer.class);
381+
}
382+
365383
private Optional<String> getInputBaseDirRelativeToModule(final Path sourceDir, final Config config) {
366384
return config.getOptionalValue(getGlobalConfigName(INPUT_BASE_DIR), String.class).map(baseDir -> {
367385
int srcIndex = sourceDir.toString().lastIndexOf("src");

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ public OpenApiClientGeneratorWrapper withRemoveOperationIdPrefix(final Boolean r
290290
return this;
291291
}
292292

293+
public OpenApiClientGeneratorWrapper withRemoveOperationIdPrefixDelimiter(final String removeOperationIdPrefixDelimiter) {
294+
this.configurator.addAdditionalProperty("removeOperationIdPrefixDelimiter", removeOperationIdPrefixDelimiter);
295+
return this;
296+
}
297+
298+
public OpenApiClientGeneratorWrapper withRemoveOperationIdPrefixCount(final Integer removeOperationIdPrefixCount) {
299+
this.configurator.addAdditionalProperty("removeOperationIdPrefixCount", removeOperationIdPrefixCount);
300+
return this;
301+
}
302+
293303
public OpenApiClientGeneratorWrapper withModelNamePrefix(final String modelNamePrefix) {
294304
this.configurator.setModelNamePrefix(modelNamePrefix);
295305
return this;
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: org.acme.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: org.acme.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: org.acme.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: org.acme.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: org.acme.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: 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
quarkus.rest-client.quarkus_simple_openapi_yaml.url=http://localhost:8080
2+
23
quarkus.openapi-generator.codegen.spec.openapi_remove_operation_id_prefix_yaml.remove-operation-id-prefix=true
4+
5+
quarkus.openapi-generator.codegen.spec.openapi_prefix_delimiter_yaml.remove-operation-id-prefix=true
6+
quarkus.openapi-generator.codegen.spec.openapi_prefix_delimiter_yaml.remove-operation-id-prefix-delimiter=.
7+
8+
quarkus.openapi-generator.codegen.spec.openapi_prefix_count_yaml.remove-operation-id-prefix=true
9+
quarkus.openapi-generator.codegen.spec.openapi_prefix_count_yaml.remove-operation-id-prefix-delimiter=.
10+
quarkus.openapi-generator.codegen.spec.openapi_prefix_count_yaml.remove-operation-id-prefix-count=3

client/integration-tests/remove-operationid-prefix/src/test/java/io/quarkiverse/openapi/generator/it/RemoveOperationIdPrefixTest.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,55 @@
99
@QuarkusTest
1010
public class RemoveOperationIdPrefixTest {
1111

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";
12+
@Test
13+
void removeOperationIdPrefixTest() {
14+
String apiClassName = "org.openapi.quarkus.openapi_remove_operation_id_prefix_yaml.api.UserResourceApi";
15+
String modelClassName = "org.openapi.quarkus.openapi_remove_operation_id_prefix_yaml.model.User";
16+
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+
34+
@Test
35+
void removeOperationIdPrefixDelimiterTest() {
36+
String apiClassName = "org.openapi.quarkus.openapi_prefix_delimiter_yaml.api.UserResourceApi";
37+
String modelClassName = "org.openapi.quarkus.openapi_prefix_delimiter_yaml.model.User";
38+
39+
assertThatCode(() -> Class.forName(apiClassName).getMethod("find", Integer.class))
40+
.doesNotThrowAnyException();
41+
42+
assertThatCode(() -> Class.forName(apiClassName).getMethod("findAll"))
43+
.doesNotThrowAnyException();
44+
45+
assertThatCode(() -> Class.forName(apiClassName).getMethod("add", Class.forName(modelClassName)))
46+
.doesNotThrowAnyException();
47+
48+
assertThatCode(() -> Class.forName(apiClassName).getMethod("update", Integer.class, Class.forName(modelClassName)))
49+
.doesNotThrowAnyException();
50+
51+
assertThatCode(() -> Class.forName(apiClassName).getMethod("delete", Integer.class))
52+
.doesNotThrowAnyException();
53+
54+
}
1455

1556
@Test
16-
void apiIsBeingGenerated() {
57+
void removeOperationIdPrefixCountTest() {
58+
String apiClassName = "org.openapi.quarkus.openapi_prefix_count_yaml.api.UserResourceApi";
59+
String modelClassName = "org.openapi.quarkus.openapi_prefix_count_yaml.model.User";
60+
1761
assertThatCode(() -> Class.forName(apiClassName).getMethod("find", Integer.class))
1862
.doesNotThrowAnyException();
1963

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ You can remove operationId prefix (e.g. User_findAll=> findAll). To do that, you
9595
quarkus.openapi-generator.codegen.spec.petstore_json.remove-operation-id-prefix=true
9696
----
9797

98+
Character to use as a delimiter for the prefix. Default is '_'.You can define the prefix delimiter (e.g. User.findAll=> findAll):
99+
100+
[source,properties]
101+
----
102+
quarkus.openapi-generator.codegen.spec.petstore_json.remove-operation-id-prefix-delimiter=.
103+
----
104+
105+
You can define count of delimiter for the prefix (e.g. org.acme.UserResource.findAll=> findAll). Use -1 for last Default:
106+
107+
[source,properties]
108+
----
109+
quarkus.openapi-generator.codegen.spec.petstore_json.remove-operation-id-prefix-count=3
110+
----
111+
98112
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:
99113

100114
[source,properties]

0 commit comments

Comments
 (0)