Skip to content

Commit 991d0d1

Browse files
authored
Fix inconsistency between openapi contract and the generated code for URL parameters (Kotlin) (#23373)
* Add @SerialName annotation to parameter in Paths.kt.mustache * after bin execution
1 parent 5227b3d commit 991d0d1

File tree

2 files changed

+19
-19
lines changed
  • modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor2
  • samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server

2 files changed

+19
-19
lines changed

modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor2/Paths.kt.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Paths {
1818
{{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
1919
{{/allParams}}*/
2020
{{#hasParams}}
21-
@Serializable @Resource("{{{path}}}") class {{operationId}}({{#allParams}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
21+
@Serializable @Resource("{{{path}}}") class {{operationId}}({{#allParams}}@SerialName("{{baseName}}") val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
2222
{{/hasParams}}
2323
{{^hasParams}}
2424
@Serializable @Resource("{{{path}}}") class {{operationId}}

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/Paths.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,43 @@ object Paths {
2121
*
2222
* @param pet Pet object that needs to be added to the store
2323
*/
24-
@Serializable @Resource("/pet") class addPet(val pet: Pet)
24+
@Serializable @Resource("/pet") class addPet(@SerialName("Pet") val pet: Pet)
2525

2626
/**
2727
* Deletes a pet
2828
*
2929
* @param petId Pet id to delete
3030
* @param apiKey (optional)
3131
*/
32-
@Serializable @Resource("/pet/{petId}") class deletePet(val petId: kotlin.Long, val apiKey: kotlin.String? = null)
32+
@Serializable @Resource("/pet/{petId}") class deletePet(@SerialName("petId") val petId: kotlin.Long, @SerialName("api_key") val apiKey: kotlin.String? = null)
3333

3434
/**
3535
* Finds Pets by status
3636
* Multiple status values can be provided with comma separated strings
3737
* @param status Status values that need to be considered for filter
3838
*/
39-
@Serializable @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.List<kotlin.String>)
39+
@Serializable @Resource("/pet/findByStatus") class findPetsByStatus(@SerialName("status") val status: kotlin.collections.List<kotlin.String>)
4040

4141
/**
4242
* Finds Pets by tags
4343
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
4444
* @param tags Tags to filter by
4545
*/
46-
@Serializable @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.List<kotlin.String>)
46+
@Serializable @Resource("/pet/findByTags") class findPetsByTags(@SerialName("tags") val tags: kotlin.collections.List<kotlin.String>)
4747

4848
/**
4949
* Find pet by ID
5050
* Returns a single pet
5151
* @param petId ID of pet to return
5252
*/
53-
@Serializable @Resource("/pet/{petId}") class getPetById(val petId: kotlin.Long)
53+
@Serializable @Resource("/pet/{petId}") class getPetById(@SerialName("petId") val petId: kotlin.Long)
5454

5555
/**
5656
* Update an existing pet
5757
*
5858
* @param pet Pet object that needs to be added to the store
5959
*/
60-
@Serializable @Resource("/pet") class updatePet(val pet: Pet)
60+
@Serializable @Resource("/pet") class updatePet(@SerialName("Pet") val pet: Pet)
6161

6262
/**
6363
* Updates a pet in the store with form data
@@ -66,7 +66,7 @@ object Paths {
6666
* @param name Updated name of the pet (optional)
6767
* @param status Updated status of the pet (optional)
6868
*/
69-
@Serializable @Resource("/pet/{petId}") class updatePetWithForm(val petId: kotlin.Long, val name: kotlin.String? = null, val status: kotlin.String? = null)
69+
@Serializable @Resource("/pet/{petId}") class updatePetWithForm(@SerialName("petId") val petId: kotlin.Long, @SerialName("name") val name: kotlin.String? = null, @SerialName("status") val status: kotlin.String? = null)
7070

7171
/**
7272
* uploads an image
@@ -75,14 +75,14 @@ object Paths {
7575
* @param additionalMetadata Additional data to pass to server (optional)
7676
* @param file file to upload (optional)
7777
*/
78-
@Serializable @Resource("/pet/{petId}/uploadImage") class uploadFile(val petId: kotlin.Long, val additionalMetadata: kotlin.String? = null, val file: java.io.File? = null)
78+
@Serializable @Resource("/pet/{petId}/uploadImage") class uploadFile(@SerialName("petId") val petId: kotlin.Long, @SerialName("additionalMetadata") val additionalMetadata: kotlin.String? = null, @SerialName("file") val file: java.io.File? = null)
7979

8080
/**
8181
* Delete purchase order by ID
8282
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
8383
* @param orderId ID of the order that needs to be deleted
8484
*/
85-
@Serializable @Resource("/store/order/{orderId}") class deleteOrder(val orderId: kotlin.String)
85+
@Serializable @Resource("/store/order/{orderId}") class deleteOrder(@SerialName("orderId") val orderId: kotlin.String)
8686

8787
/**
8888
* Returns pet inventories by status
@@ -95,57 +95,57 @@ object Paths {
9595
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
9696
* @param orderId ID of pet that needs to be fetched
9797
*/
98-
@Serializable @Resource("/store/order/{orderId}") class getOrderById(val orderId: kotlin.Long)
98+
@Serializable @Resource("/store/order/{orderId}") class getOrderById(@SerialName("orderId") val orderId: kotlin.Long)
9999

100100
/**
101101
* Place an order for a pet
102102
*
103103
* @param order order placed for purchasing the pet
104104
*/
105-
@Serializable @Resource("/store/order") class placeOrder(val order: Order)
105+
@Serializable @Resource("/store/order") class placeOrder(@SerialName("Order") val order: Order)
106106

107107
/**
108108
* Create user
109109
* This can only be done by the logged in user.
110110
* @param user Created user object
111111
*/
112-
@Serializable @Resource("/user") class createUser(val user: User)
112+
@Serializable @Resource("/user") class createUser(@SerialName("User") val user: User)
113113

114114
/**
115115
* Creates list of users with given input array
116116
*
117117
* @param user List of user object
118118
*/
119-
@Serializable @Resource("/user/createWithArray") class createUsersWithArrayInput(val user: kotlin.collections.List<User>)
119+
@Serializable @Resource("/user/createWithArray") class createUsersWithArrayInput(@SerialName("User") val user: kotlin.collections.List<User>)
120120

121121
/**
122122
* Creates list of users with given input array
123123
*
124124
* @param user List of user object
125125
*/
126-
@Serializable @Resource("/user/createWithList") class createUsersWithListInput(val user: kotlin.collections.List<User>)
126+
@Serializable @Resource("/user/createWithList") class createUsersWithListInput(@SerialName("User") val user: kotlin.collections.List<User>)
127127

128128
/**
129129
* Delete user
130130
* This can only be done by the logged in user.
131131
* @param username The name that needs to be deleted
132132
*/
133-
@Serializable @Resource("/user/{username}") class deleteUser(val username: kotlin.String)
133+
@Serializable @Resource("/user/{username}") class deleteUser(@SerialName("username") val username: kotlin.String)
134134

135135
/**
136136
* Get user by user name
137137
*
138138
* @param username The name that needs to be fetched. Use user1 for testing.
139139
*/
140-
@Serializable @Resource("/user/{username}") class getUserByName(val username: kotlin.String)
140+
@Serializable @Resource("/user/{username}") class getUserByName(@SerialName("username") val username: kotlin.String)
141141

142142
/**
143143
* Logs user into the system
144144
*
145145
* @param username The user name for login
146146
* @param password The password for login in clear text
147147
*/
148-
@Serializable @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String)
148+
@Serializable @Resource("/user/login") class loginUser(@SerialName("username") val username: kotlin.String, @SerialName("password") val password: kotlin.String)
149149

150150
/**
151151
* Logs out current logged in user session
@@ -159,6 +159,6 @@ object Paths {
159159
* @param username name that need to be deleted
160160
* @param user Updated user object
161161
*/
162-
@Serializable @Resource("/user/{username}") class updateUser(val username: kotlin.String, val user: User)
162+
@Serializable @Resource("/user/{username}") class updateUser(@SerialName("username") val username: kotlin.String, @SerialName("User") val user: User)
163163

164164
}

0 commit comments

Comments
 (0)