Skip to content

Commit 4e31e4d

Browse files
authored
fix(Kotlin): use the global apiNamePrefix and apiNameSuffix settings (#23822) (#23926)
1 parent 04a5661 commit 4e31e4d

12 files changed

Lines changed: 17 additions & 20 deletions

File tree

docs/generators/kotlin-misk.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2626
|actionRequestContentTypePrefix|Request ContentType Prefix for Action| |MediaTypes|
2727
|addModelMoshiJsonAnnotation|Add a Moshi JSON adapter annotation to all model classes| |true|
2828
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
29-
|apiSuffix|suffix for api classes| |Api|
3029
|artifactId|Generated artifact id (name of jar).| |null|
3130
|artifactVersion|Generated artifact's package version.| |1.0.0|
3231
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', 'original', and 'bestEffortBacktick' (like 'original' but tries to wrap values in backticks before falling back to sanitizing, e.g. `name,asc` stays `name,asc` rather than becoming nameCommaAsc; useful for sort/order enums)| |original|

docs/generators/kotlin-server.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
22-
|apiSuffix|suffix for api classes| |Api|
2322
|artifactId|Generated artifact id (name of jar).| |kotlin-server|
2423
|artifactVersion|Generated artifact's package version.| |1.0.0|
2524
|delegatePattern|Whether to generate the server files using the delegate pattern. This option is currently supported only when using ktor library.| |false|

docs/generators/kotlin-spring.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2121
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
2222
|annotationLibrary|Select the complementary documentation annotation library.|<dl><dt>**none**</dt><dd>Do not annotate Model and Api with complementary annotations.</dd><dt>**swagger1**</dt><dd>Annotate Model and Api using the Swagger Annotations 1.x library.</dd><dt>**swagger2**</dt><dd>Annotate Model and Api using the Swagger Annotations 2.x library.</dd></dl>|swagger2|
2323
|apiPackage|api package for generated code| |org.openapitools.api|
24-
|apiSuffix|suffix for api classes| |Api|
2524
|artifactId|Generated artifact id (name of jar).| |openapi-spring|
2625
|artifactVersion|Generated artifact's package version.| |1.0.0|
2726
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected.| |false|

docs/generators/kotlin-vertx.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
22-
|apiSuffix|suffix for api classes| |Api|
2322
|artifactId|Generated artifact id (name of jar).| |null|
2423
|artifactVersion|Generated artifact's package version.| |1.0.0|
2524
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', 'original', and 'bestEffortBacktick' (like 'original' but tries to wrap values in backticks before falling back to sanitizing, e.g. `name,asc` stays `name,asc` rather than becoming nameCommaAsc; useful for sort/order enums)| |original|

docs/generators/kotlin-wiremock.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
22-
|apiSuffix|suffix for api classes| |Api|
2322
|artifactId|Generated artifact id (name of jar).| |null|
2423
|artifactVersion|Generated artifact's package version.| |1.0.0|
2524
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', 'original', and 'bestEffortBacktick' (like 'original' but tries to wrap values in backticks before falling back to sanitizing, e.g. `name,asc` stays `name,asc` rather than becoming nameCommaAsc; useful for sort/order enums)| |original|

docs/generators/kotlin.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
22-
|apiSuffix|suffix for api classes| |Api|
2322
|artifactId|Generated artifact id (name of jar).| |kotlin-client|
2423
|artifactVersion|Generated artifact's package version.| |1.0.0|
2524
|collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd></dl>|list|

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public class CodegenConstants {
4141
public static final String API_PACKAGE = "apiPackage";
4242
public static final String API_PACKAGE_DESC = "package for generated api classes";
4343

44-
public static final String API_SUFFIX = "apiSuffix";
45-
public static final String API_SUFFIX_DESC = "suffix for api classes";
46-
4744
public static final String AUTOSET_CONSTANTS = "autosetConstants";
4845

4946
public static final String MODEL_PACKAGE = "modelPackage";

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
7373
@Setter protected String artifactVersion = "1.0.0";
7474
@Setter protected String groupId = "org.openapitools";
7575
@Setter protected String packageName = "org.openapitools";
76-
@Setter protected String apiSuffix = "Api";
7776

7877
@Setter protected String sourceFolder = "src/main/kotlin";
7978
@Setter protected String testFolder = "src/test/kotlin";
@@ -309,7 +308,6 @@ public AbstractKotlinCodegen() {
309308
cliOptions.clear();
310309
addOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC, sourceFolder);
311310
addOption(CodegenConstants.PACKAGE_NAME, "Generated artifact package name.", packageName);
312-
addOption(CodegenConstants.API_SUFFIX, CodegenConstants.API_SUFFIX_DESC, apiSuffix);
313311
addOption(CodegenConstants.GROUP_ID, "Generated artifact package's organization (i.e. maven groupId).", groupId);
314312
addOption(CodegenConstants.ARTIFACT_ID, "Generated artifact id (name of jar).", artifactId);
315313
addOption(CodegenConstants.ARTIFACT_VERSION, "Generated artifact's package version.", artifactVersion);
@@ -576,10 +574,6 @@ public void processOpts() {
576574
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
577575
}
578576

579-
if (additionalProperties.containsKey(CodegenConstants.API_SUFFIX)) {
580-
this.setApiSuffix((String) additionalProperties.get(CodegenConstants.API_SUFFIX));
581-
}
582-
583577
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_ID)) {
584578
this.setArtifactId((String) additionalProperties.get(CodegenConstants.ARTIFACT_ID));
585579
} else {
@@ -761,7 +755,7 @@ public String toApiName(String name) {
761755
if (name.length() == 0) {
762756
return "DefaultApi";
763757
}
764-
return (this.apiSuffix.isEmpty() ? camelize(name) : camelize(name) + this.apiSuffix);
758+
return this.apiNamePrefix + camelize(name) + this.apiNameSuffix;
765759
}
766760

767761
/**

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KtormSchemaCodegen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public KtormSchemaCodegen() {
227227
// cliOptions default redefinition need to be updated
228228
updateOption(CodegenConstants.ARTIFACT_ID, artifactId);
229229
updateOption(CodegenConstants.PACKAGE_NAME, packageName);
230-
removeOption(CodegenConstants.API_SUFFIX);
231230
removeOption(CodegenConstants.PARCELIZE_MODELS);
232231
removeOption(CodegenConstants.SERIALIZABLE_MODEL);
233232
removeOption(CodegenConstants.SERIALIZATION_LIBRARY);

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/AbstractKotlinCodegenTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,26 @@ public void convertApiNameWithEmptySuffix() {
239239

240240
@Test
241241
public void convertApiNameWithSuffix() {
242-
codegen.setApiSuffix("Test");
242+
codegen.setApiNameSuffix("Test");
243243
assertEquals(codegen.toApiName("Fake"), "FakeTest");
244244
assertEquals(codegen.toApiName(""), "DefaultApi");
245245
}
246246

247+
@Test
248+
public void convertApiNameWithPrefix() {
249+
codegen.setApiNamePrefix("Prefix");
250+
assertEquals(codegen.toApiName("Fake"), "PrefixFakeApi");
251+
assertEquals(codegen.toApiName(""), "DefaultApi");
252+
}
253+
254+
@Test
255+
public void convertApiNameWithPrefixAndSuffix() {
256+
codegen.setApiNamePrefix("Prefix");
257+
codegen.setApiNameSuffix("Suffix");
258+
assertEquals(codegen.toApiName("Fake"), "PrefixFakeSuffix");
259+
assertEquals(codegen.toApiName(""), "DefaultApi");
260+
}
261+
247262
@Test
248263
public void apIFileFolder() {
249264
codegen.setOutputDir("/User/open/api/tools");

0 commit comments

Comments
 (0)