Skip to content

Commit c3e559b

Browse files
committed
Default useTags to true and simplify addOperationToGroup for kotlin-server
1 parent 532b6a1 commit c3e559b

8 files changed

Lines changed: 55 additions & 60 deletions

File tree

bin/configs/kotlin-server-jaxrs-spec-array-response.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ templateDir: modules/openapi-generator/src/main/resources/kotlin-server
66
additionalProperties:
77
interfaceOnly: "true"
88
useJakartaEe: true
9-
useTags: "true"

bin/configs/kotlin-server-jaxrs-spec-parameter-tests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/parameter-test-spec.
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
66
additionalProperties:
77
useCoroutines: "true"
8-
useTags: "true"

docs/generators/kotlin-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4848
|useCoroutines|Whether to use the Coroutines. This option is currently supported only when using jaxrs-spec library.| |false|
4949
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
5050
|useMutiny|Whether to use Mutiny (should not be used with useCoroutines). This option is currently supported only when using jaxrs-spec library.| |false|
51-
|useTags|use tags for creating interface and controller classnames| |false|
51+
|useTags|use tags for creating interface and controller classnames. This option is currently supported only when using jaxrs-spec library.| |true|
5252

5353
## IMPORT MAPPING
5454

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
6161
public static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
6262
public static final String JACKSON3_PACKAGE = "tools.jackson";
6363
public static final String JACKSON_PACKAGE = "jacksonPackage";
64-
public static final String USE_TAGS = "useTags";
65-
public static final String USE_TAGS_DESC = "use tags for creating interface and controller classnames";
6664
public static final String SCHEMA_IMPLEMENTS = "schemaImplements";
6765
public static final String SCHEMA_IMPLEMENTS_FIELDS = "schemaImplementsFields";
6866
public static final String X_KOTLIN_IMPLEMENTS_SKIP = "xKotlinImplementsSkip";

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import org.slf4j.Logger;
5858
import org.slf4j.LoggerFactory;
5959

60+
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.USE_TAGS;
61+
6062
public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanValidationFeatures {
6163

6264
public static final String DEFAULT_LIBRARY = Constants.KTOR;
@@ -85,7 +87,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
8587
private Boolean metricsFeatureEnabled = true;
8688
private boolean interfaceOnly = false;
8789
private boolean useBeanValidation = false;
88-
private boolean useTags = false;
90+
private boolean useTags = true;
8991
private boolean useCoroutines = false;
9092
private boolean useMutiny = false;
9193
private boolean returnResponse = false;
@@ -193,7 +195,7 @@ public KotlinServerCodegen() {
193195
addSwitch(Constants.METRICS, Constants.METRICS_DESC, getMetricsFeatureEnabled());
194196
addSwitch(Constants.INTERFACE_ONLY, Constants.INTERFACE_ONLY_DESC, interfaceOnly);
195197
addSwitch(USE_BEANVALIDATION, Constants.USE_BEANVALIDATION_DESC, useBeanValidation);
196-
addSwitch(USE_TAGS, USE_TAGS_DESC, useTags);
198+
addSwitch(USE_TAGS, Constants.USE_TAGS_DESC, useTags);
197199
addSwitch(Constants.USE_COROUTINES, Constants.USE_COROUTINES_DESC, useCoroutines);
198200
addSwitch(Constants.USE_MUTINY, Constants.USE_MUTINY_DESC, useMutiny);
199201
addSwitch(Constants.RETURN_RESPONSE, Constants.RETURN_RESPONSE_DESC, returnResponse);
@@ -426,6 +428,8 @@ public static class Constants {
426428
public static final String IS_KTOR = "isKtor";
427429
public static final String FIX_JACKSON_JSON_TYPE_INFO_INHERITANCE = "fixJacksonJsonTypeInfoInheritance";
428430
public static final String FIX_JACKSON_JSON_TYPE_INFO_INHERITANCE_DESC = "When true (default), ensures Jackson polymorphism works correctly by: (1) always setting visible=true on @JsonTypeInfo, and (2) adding the discriminator property to child models with appropriate default values. When false, visible is only set to true if all children already define the discriminator property.";
431+
public static final String USE_TAGS = "useTags";
432+
public static final String USE_TAGS_DESC = "use tags for creating interface and controller classnames. This option is currently supported only when using jaxrs-spec library.";
429433
}
430434

431435
@Override
@@ -730,16 +734,11 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
730734
return;
731735
}
732736

733-
final String basePath = StringUtils.substringBefore(resourcePath.startsWith("/") ? resourcePath.substring(1) : resourcePath, "/");
734-
if (!StringUtils.isEmpty(basePath)) {
735-
co.subresourceOperation = !co.path.isEmpty();
736-
}
737-
co.baseName = basePath;
738-
if (StringUtils.isEmpty(co.baseName) || co.baseName.chars().anyMatch(ch -> ch == '{' || ch == '}')) {
739-
co.baseName = "default";
737+
String basePath = StringUtils.substringBefore(resourcePath.startsWith("/") ? resourcePath.substring(1) : resourcePath, "/");
738+
if (StringUtils.isEmpty(basePath) || basePath.chars().anyMatch(ch -> ch == '{' || ch == '}')) {
739+
basePath = "default";
740740
}
741-
final List<CodegenOperation> opList = operations.computeIfAbsent(co.baseName, k -> new ArrayList<>());
742-
opList.add(co);
741+
super.addOperationToGroup(basePath, resourcePath, operation, co, operations);
743742
}
744743

745744
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
import static org.openapitools.codegen.TestUtils.assertFileContains;
3131
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
3232
import static org.openapitools.codegen.languages.AbstractKotlinCodegen.USE_JAKARTA_EE;
33-
import static org.openapitools.codegen.languages.AbstractKotlinCodegen.USE_TAGS;
3433
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.INTERFACE_ONLY;
3534
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.JAVALIN5;
3635
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.JAVALIN6;
3736
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.JAXRS_SPEC;
3837
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.RETURN_RESPONSE;
38+
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.USE_TAGS;
3939
import static org.openapitools.codegen.languages.features.BeanValidationFeatures.USE_BEANVALIDATION;
4040

4141
public class KotlinServerCodegenTest {
@@ -226,7 +226,6 @@ public void issue18177Arrays() throws IOException {
226226
codegen.additionalProperties().put(INTERFACE_ONLY, true);
227227
codegen.additionalProperties().put(USE_JAKARTA_EE, true);
228228
codegen.additionalProperties().put(LIBRARY, JAXRS_SPEC);
229-
codegen.additionalProperties().put(USE_TAGS, true);
230229
new DefaultGenerator().opts(new ClientOptInput()
231230
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue18177-array.yaml"))
232231
.config(codegen))
@@ -572,14 +571,14 @@ public void useTags_false_classNameFromTagsAndRootPathForJaxrsSpecLibrary() thro
572571
}
573572

574573
@Test
575-
public void useTags_notSpecified_behavesLikeUseTagsFalseForJaxrsSpecLibrary() throws IOException {
574+
public void useTags_notSpecified_behavesLikeUseTagsTrueForJaxrsSpecLibrary() throws IOException {
576575
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
577576
output.deleteOnExit();
578577

579578
KotlinServerCodegen codegen = new KotlinServerCodegen();
580579
codegen.setOutputDir(output.getAbsolutePath());
581580
codegen.additionalProperties().put(LIBRARY, JAXRS_SPEC);
582-
// useTags intentionally NOT set — must default to false
581+
// useTags intentionally NOT set — must default to true
583582

584583
new DefaultGenerator().opts(new ClientOptInput()
585584
.openAPI(TestUtils.parseSpec("src/test/resources/2_0/petstore.yaml"))
@@ -595,6 +594,7 @@ public void useTags_notSpecified_behavesLikeUseTagsFalseForJaxrsSpecLibrary() th
595594
"@Path(\"/findByStatus\")",
596595
"@Path(\"/{petId}\")"
597596
);
597+
assertFileNotContains(petApi, "@Path(\"/\")");
598598
assertFileNotContains(petApi, "@Path(\"/store\")");
599599
}
600600
}

samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ All URIs are relative to *http://petstore.swagger.io/v2*
3434

3535
Class | Method | HTTP request | Description
3636
------------ | ------------- | ------------- | -------------
37-
*PetApi* | [**addPet**](docs/PetApi.md#) | **POST** /pet | Add a new pet to the store
38-
*PetApi* | [**deletePet**](docs/PetApi.md#) | **DELETE** /pet/{petId} | Deletes a pet
39-
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#) | **GET** /pet/findByStatus | Finds Pets by status
40-
*PetApi* | [**findPetsByTags**](docs/PetApi.md#) | **GET** /pet/findByTags | Finds Pets by tags
41-
*PetApi* | [**getPetById**](docs/PetApi.md#) | **GET** /pet/{petId} | Find pet by ID
42-
*PetApi* | [**updatePet**](docs/PetApi.md#) | **PUT** /pet | Update an existing pet
43-
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#) | **POST** /pet/{petId} | Updates a pet in the store with form data
44-
*PetApi* | [**uploadFile**](docs/PetApi.md#) | **POST** /pet/{petId}/uploadImage | uploads an image
45-
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
46-
*StoreApi* | [**getInventory**](docs/StoreApi.md#) | **GET** /store/inventory | Returns pet inventories by status
47-
*StoreApi* | [**getOrderById**](docs/StoreApi.md#) | **GET** /store/order/{orderId} | Find purchase order by ID
48-
*StoreApi* | [**placeOrder**](docs/StoreApi.md#) | **POST** /store/order | Place an order for a pet
49-
*UserApi* | [**createUser**](docs/UserApi.md#) | **POST** /user | Create user
50-
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#) | **POST** /user/createWithArray | Creates list of users with given input array
51-
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#) | **POST** /user/createWithList | Creates list of users with given input array
52-
*UserApi* | [**deleteUser**](docs/UserApi.md#) | **DELETE** /user/{username} | Delete user
53-
*UserApi* | [**getUserByName**](docs/UserApi.md#) | **GET** /user/{username} | Get user by user name
54-
*UserApi* | [**loginUser**](docs/UserApi.md#) | **GET** /user/login | Logs user into the system
55-
*UserApi* | [**logoutUser**](docs/UserApi.md#) | **GET** /user/logout | Logs out current logged in user session
56-
*UserApi* | [**updateUser**](docs/UserApi.md#) | **PUT** /user/{username} | Updated user
37+
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
38+
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
39+
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
40+
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
41+
*PetApi* | [**getPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
42+
*PetApi* | [**updatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
43+
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
44+
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
45+
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
46+
*StoreApi* | [**getInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
47+
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
48+
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
49+
*UserApi* | [**createUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
50+
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
51+
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
52+
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
53+
*UserApi* | [**getUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
54+
*UserApi* | [**loginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
55+
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
56+
*UserApi* | [**updateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
5757

5858

5959
<a id="documentation-for-models"></a>

samples/server/petstore/kotlin-server/jaxrs-spec/README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ All URIs are relative to *http://petstore.swagger.io/v2*
3434

3535
Class | Method | HTTP request | Description
3636
------------ | ------------- | ------------- | -------------
37-
*PetApi* | [**addPet**](docs/PetApi.md#) | **POST** /pet | Add a new pet to the store
38-
*PetApi* | [**deletePet**](docs/PetApi.md#) | **DELETE** /pet/{petId} | Deletes a pet
39-
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#) | **GET** /pet/findByStatus | Finds Pets by status
40-
*PetApi* | [**findPetsByTags**](docs/PetApi.md#) | **GET** /pet/findByTags | Finds Pets by tags
41-
*PetApi* | [**getPetById**](docs/PetApi.md#) | **GET** /pet/{petId} | Find pet by ID
42-
*PetApi* | [**updatePet**](docs/PetApi.md#) | **PUT** /pet | Update an existing pet
43-
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#) | **POST** /pet/{petId} | Updates a pet in the store with form data
44-
*PetApi* | [**uploadFile**](docs/PetApi.md#) | **POST** /pet/{petId}/uploadImage | uploads an image
45-
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
46-
*StoreApi* | [**getInventory**](docs/StoreApi.md#) | **GET** /store/inventory | Returns pet inventories by status
47-
*StoreApi* | [**getOrderById**](docs/StoreApi.md#) | **GET** /store/order/{orderId} | Find purchase order by ID
48-
*StoreApi* | [**placeOrder**](docs/StoreApi.md#) | **POST** /store/order | Place an order for a pet
49-
*UserApi* | [**createUser**](docs/UserApi.md#) | **POST** /user | Create user
50-
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#) | **POST** /user/createWithArray | Creates list of users with given input array
51-
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#) | **POST** /user/createWithList | Creates list of users with given input array
52-
*UserApi* | [**deleteUser**](docs/UserApi.md#) | **DELETE** /user/{username} | Delete user
53-
*UserApi* | [**getUserByName**](docs/UserApi.md#) | **GET** /user/{username} | Get user by user name
54-
*UserApi* | [**loginUser**](docs/UserApi.md#) | **GET** /user/login | Logs user into the system
55-
*UserApi* | [**logoutUser**](docs/UserApi.md#) | **GET** /user/logout | Logs out current logged in user session
56-
*UserApi* | [**updateUser**](docs/UserApi.md#) | **PUT** /user/{username} | Updated user
37+
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
38+
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
39+
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
40+
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
41+
*PetApi* | [**getPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
42+
*PetApi* | [**updatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
43+
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
44+
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
45+
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
46+
*StoreApi* | [**getInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
47+
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
48+
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
49+
*UserApi* | [**createUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
50+
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
51+
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
52+
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
53+
*UserApi* | [**getUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
54+
*UserApi* | [**loginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
55+
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
56+
*UserApi* | [**updateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
5757

5858

5959
<a id="documentation-for-models"></a>

0 commit comments

Comments
 (0)