Skip to content

Commit cd6470e

Browse files
authored
Wildcard tag support for openapi tags config (#218)
1 parent e908f3b commit cd6470e

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

mkdocs/docs/features/openapi-codegen.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ Maven:
7373
<configOptions>
7474
<mode>java_client</mode>
7575
<tags>{
76-
"common": {
77-
"httpClientTag": "some.tag.CanonicalName.class",
78-
"telemetryTag": "some.tag.CanonicalName.class"
76+
"*": { // применится для всех тегов, кроме явно указанных (в данном случае instrument)
77+
"httpClientTag": "some.tag.Common.class",
78+
"telemetryTag": "some.tag.Common.class"
79+
}
80+
"instrument": { // применится для instrument
81+
"httpClientTag": "some.tag.Instrument.class",
82+
"telemetryTag": "some.tag.Instrument.class"
7983
}
8084
}
8185
</tags>
@@ -86,11 +90,17 @@ Gradle:
8690
configOptions = [
8791
mode: "java_client",
8892
tags: """
89-
"common": {
90-
"httpClientTag": "some.tag.CanonicalName.class",
91-
"telemetryTag": "some.tag.CanonicalName.class"
93+
{
94+
"*": { // применится для всех тегов, кроме явно указанных (в данном случае instrument)
95+
"httpClientTag": "some.tag.Common.class",
96+
"telemetryTag": "some.tag.Common.class"
97+
},
98+
"instrument": { // применится для instrument
99+
"httpClientTag": "some.tag.Instrument.class",
100+
"telemetryTag": "some.tag.Instrument.class"
101+
}
92102
}
93-
"""
103+
"""
94104
]
95105
```
96106

openapi/openapi-generator/src/main/java/ru/tinkoff/kora/openapi/generator/KoraCodegen.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,18 +1243,24 @@ record AuthMethodGroup(String name, List<CodegenSecurity> methods) {}
12431243
}
12441244
}
12451245

1246+
TagData tagData = null;
12461247
for (var entry : this.tags.entrySet()) {
12471248
if (op.tags.stream().anyMatch(t -> t.getName().equals(entry.getKey()))) {
1248-
var tagData = entry.getValue();
1249-
if (tagData.httpClientTag != null) {
1250-
httpClientAnnotationParams.put("httpClientTag", tagData.httpClientTag);
1251-
}
1252-
if (tagData.telemetryTag != null) {
1253-
httpClientAnnotationParams.put("telemetryTag", tagData.telemetryTag);
1254-
}
1249+
tagData = entry.getValue();
12551250
break;
12561251
}
12571252
}
1253+
if (tagData == null) {
1254+
tagData = this.tags.get("*");
1255+
}
1256+
if (tagData != null) {
1257+
if (tagData.httpClientTag != null) {
1258+
httpClientAnnotationParams.put("httpClientTag", tagData.httpClientTag);
1259+
}
1260+
if (tagData.telemetryTag != null) {
1261+
httpClientAnnotationParams.put("telemetryTag", tagData.telemetryTag);
1262+
}
1263+
}
12581264

12591265
op.vendorExtensions.put("x-java-import", operationImports);
12601266
var multipartForm = op.consumes != null && op.consumes.stream()

0 commit comments

Comments
 (0)