Skip to content

Commit 9f08867

Browse files
committed
Add tests and update samples for useTags in kotlin-server JAXRS codegen
1 parent ccbba80 commit 9f08867

6 files changed

Lines changed: 98 additions & 23 deletions

File tree

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

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

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
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;
3334
import static org.openapitools.codegen.languages.KotlinServerCodegen.Constants.*;
3435
import static org.openapitools.codegen.languages.features.BeanValidationFeatures.USE_BEANVALIDATION;
3536

@@ -509,4 +510,60 @@ public void fixJacksonJsonTypeInfoInheritance_canBeDisabled() throws IOException
509510
"visible = false"
510511
);
511512
}
513+
514+
@Test
515+
public void useTags_commonPathIsComputedForJaxrsSpecLibrary() throws IOException {
516+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
517+
output.deleteOnExit();
518+
519+
KotlinServerCodegen codegen = new KotlinServerCodegen();
520+
codegen.setOutputDir(output.getAbsolutePath());
521+
codegen.additionalProperties().put(LIBRARY, JAXRS_SPEC);
522+
codegen.additionalProperties().put(USE_TAGS, true);
523+
524+
new DefaultGenerator().opts(new ClientOptInput()
525+
.openAPI(TestUtils.parseSpec("src/test/resources/2_0/petstore.yaml"))
526+
.config(codegen))
527+
.generate();
528+
529+
String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/server";
530+
Path petApi = Paths.get(outputPath + "/apis/PetApi.kt");
531+
532+
assertFileContains(
533+
petApi,
534+
"@Path(\"/pet\")"
535+
);
536+
assertFileNotContains(
537+
petApi,
538+
"@Path(\"/\")"
539+
);
540+
}
541+
542+
@Test
543+
public void useTags_false_operationsGroupedByPathBaseForJaxrsSpecLibrary() throws IOException {
544+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
545+
output.deleteOnExit();
546+
547+
KotlinServerCodegen codegen = new KotlinServerCodegen();
548+
codegen.setOutputDir(output.getAbsolutePath());
549+
codegen.additionalProperties().put(LIBRARY, JAXRS_SPEC);
550+
codegen.additionalProperties().put(USE_TAGS, false);
551+
552+
new DefaultGenerator().opts(new ClientOptInput()
553+
.openAPI(TestUtils.parseSpec("src/test/resources/2_0/petstore.yaml"))
554+
.config(codegen))
555+
.generate();
556+
557+
String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/server";
558+
Path petApi = Paths.get(outputPath + "/apis/PetApi.kt");
559+
560+
assertFileContains(
561+
petApi,
562+
"class PetApi"
563+
);
564+
assertFileNotContains(
565+
petApi,
566+
"class DefaultApi"
567+
);
568+
}
512569
}

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

5858

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

samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/PetApi.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.io.InputStream
1111

1212

1313

14-
@Path("/")
14+
@Path("/pet")
1515
@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"), comments = "Generator version: 7.20.0-SNAPSHOT")
1616
class PetApi {
1717

@@ -22,23 +22,27 @@ class PetApi {
2222
}
2323

2424
@DELETE
25+
@Path("/{petId}")
2526
suspend fun deletePet(@PathParam("petId") petId: kotlin.Long,@HeaderParam("api_key") apiKey: kotlin.String?): Response {
2627
return Response.ok().entity("magic!").build();
2728
}
2829

2930
@GET
31+
@Path("/findByStatus")
3032
@Produces("application/xml", "application/json")
3133
suspend fun findPetsByStatus(@QueryParam("status") status: kotlin.collections.List<kotlin.String>): Response {
3234
return Response.ok().entity("magic!").build();
3335
}
3436

3537
@GET
38+
@Path("/findByTags")
3639
@Produces("application/xml", "application/json")
3740
suspend fun findPetsByTags(@QueryParam("tags") tags: kotlin.collections.List<kotlin.String>): Response {
3841
return Response.ok().entity("magic!").build();
3942
}
4043

4144
@GET
45+
@Path("/{petId}")
4246
@Produces("application/xml", "application/json")
4347
suspend fun getPetById(@PathParam("petId") petId: kotlin.Long): Response {
4448
return Response.ok().entity("magic!").build();
@@ -51,12 +55,14 @@ class PetApi {
5155
}
5256

5357
@POST
58+
@Path("/{petId}")
5459
@Consumes("application/x-www-form-urlencoded")
5560
suspend fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "name") name: kotlin.String?,@FormParam(value = "status") status: kotlin.String?): Response {
5661
return Response.ok().entity("magic!").build();
5762
}
5863

5964
@POST
65+
@Path("/{petId}/uploadImage")
6066
@Consumes("multipart/form-data")
6167
@Produces("application/json")
6268
suspend fun uploadFile(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "additionalMetadata") additionalMetadata: kotlin.String?, @FormParam(value = "file") fileInputStream: InputStream?): Response {

samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,32 @@ import java.io.InputStream
1010

1111

1212

13-
@Path("/")
13+
@Path("/store")
1414
@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"), comments = "Generator version: 7.20.0-SNAPSHOT")
1515
class StoreApi {
1616

1717
@DELETE
18+
@Path("/order/{orderId}")
1819
suspend fun deleteOrder(@PathParam("orderId") orderId: kotlin.String): Response {
1920
return Response.ok().entity("magic!").build();
2021
}
2122

2223
@GET
24+
@Path("/inventory")
2325
@Produces("application/json")
2426
suspend fun getInventory(): Response {
2527
return Response.ok().entity("magic!").build();
2628
}
2729

2830
@GET
31+
@Path("/order/{orderId}")
2932
@Produces("application/xml", "application/json")
3033
suspend fun getOrderById(@PathParam("orderId") orderId: kotlin.Long): Response {
3134
return Response.ok().entity("magic!").build();
3235
}
3336

3437
@POST
38+
@Path("/order")
3539
@Produces("application/xml", "application/json")
3640
suspend fun placeOrder( body: Order): Response {
3741
return Response.ok().entity("magic!").build();

samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/apis/UserApi.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.io.InputStream
1010

1111

1212

13-
@Path("/")
13+
@Path("/user")
1414
@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen"), comments = "Generator version: 7.20.0-SNAPSHOT")
1515
class UserApi {
1616

@@ -20,38 +20,45 @@ class UserApi {
2020
}
2121

2222
@POST
23+
@Path("/createWithArray")
2324
suspend fun createUsersWithArrayInput( body: kotlin.collections.List<User>): Response {
2425
return Response.ok().entity("magic!").build();
2526
}
2627

2728
@POST
29+
@Path("/createWithList")
2830
suspend fun createUsersWithListInput( body: kotlin.collections.List<User>): Response {
2931
return Response.ok().entity("magic!").build();
3032
}
3133

3234
@DELETE
35+
@Path("/{username}")
3336
suspend fun deleteUser(@PathParam("username") username: kotlin.String): Response {
3437
return Response.ok().entity("magic!").build();
3538
}
3639

3740
@GET
41+
@Path("/{username}")
3842
@Produces("application/xml", "application/json")
3943
suspend fun getUserByName(@PathParam("username") username: kotlin.String): Response {
4044
return Response.ok().entity("magic!").build();
4145
}
4246

4347
@GET
48+
@Path("/login")
4449
@Produces("application/xml", "application/json")
4550
suspend fun loginUser(@QueryParam("username") username: kotlin.String,@QueryParam("password") password: kotlin.String): Response {
4651
return Response.ok().entity("magic!").build();
4752
}
4853

4954
@GET
55+
@Path("/logout")
5056
suspend fun logoutUser(): Response {
5157
return Response.ok().entity("magic!").build();
5258
}
5359

5460
@PUT
61+
@Path("/{username}")
5562
suspend fun updateUser(@PathParam("username") username: kotlin.String, body: User): Response {
5663
return Response.ok().entity("magic!").build();
5764
}

0 commit comments

Comments
 (0)