You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The Kotlin multiplatform generator outputs code with syntax errors due to a type mismatch between the request body and private class created to represent the request body.
open suspend fun postFoo(body: kotlin.String?): HttpResponse<kotlin.String> { // body is a String
val localVariableAuthNames = listOf<String>()
val localVariableBody = PostFooRequest(body) // body passed to request object constructor
val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.POST,
"/foo/post",
query = localVariableQuery,
headers = localVariableHeaders
)
return jsonRequest(
localVariableConfig,
localVariableBody,
localVariableAuthNames
).wrap()
}
@Serializable
private class PostFooRequest(val value: Map<kotlin.String, kotlin.String>) { // constructor takes map not string
@Serializer(PostFooRequest::class)
companion object : KSerializer<PostFooRequest> {
private val serializer: KSerializer<Map<kotlin.String, kotlin.String>> = serializer<Map<String, kotlin.String>>()
override val descriptor = serializer.descriptor
override fun serialize(encoder: Encoder, obj: PostFooRequest) = serializer.serialize(encoder, obj.value)
override fun deserialize(decoder: Decoder) = PostFooRequest(serializer.deserialize(decoder))
}
}
Yields
Type mismatch: inferred type is String but Map<String, String> was expected
openapi-generator version
5.4.0
OpenAPI declaration file content or url
openapi: 3.0.0info:
title: Request body data type mismatch exampleversion: '1.0'description: Error examplecontact:
name: craigberry1servers:
- url: 'http://localhost:3000'paths:
/foo/post:
post:
summary: Get User Info by User IDtags: []responses:
'200':
description: OKcontent:
application/json:
schema:
type: stringoperationId: post-foodescription: Post endpoint that takes plain object in request body referenced from modelrequestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CategoriesGetRequest'parameters: []components:
schemas:
CategoriesGetRequest:
title: CategoriesGetRequesttype: object
Create a schema model of type object and no other properties
Create an endpoint which accepts this schema in the request body
Run api through kotlin/multiplatform generator
Observe type mismatch between the request body (kotlin.String) and the constructor args of the private class created (Map<kotlin.String, kotlin.String>)
Related issues/PRs
I have not found any similar issues.
Suggest a fix
I am not familiar enough with the code to suggest a fix. Some questions I would ask are:
Why is a request body of type object turned into a String?
Bug Report Checklist
Description
The Kotlin multiplatform generator outputs code with syntax errors due to a type mismatch between the request body and private class created to represent the request body.
Yields
openapi-generator version
5.4.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
object
and no other propertieskotlin.String
) and the constructor args of the private class created (Map<kotlin.String, kotlin.String>
)Related issues/PRs
I have not found any similar issues.
Suggest a fix
I am not familiar enough with the code to suggest a fix. Some questions I would ask are:
The text was updated successfully, but these errors were encountered: