Open patiramyadav opened 3 years ago
When I add requestBody it works and I see generated code as follows:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MockRequest'
required: false
Then
suspend fun cancelAbc(id: java.util.UUID) : MockResponse{
val localVariableConfig = cancelAbcRequestConfig(id = id)
val localVarResponse = request<Unit, MockResponse>(
localVariableConfig
)
.....
}
Changed to
suspend fun cancelAbc(id: java.util.UUID, mockRequest: MockRequest?) : MockResponse{
val localVariableConfig = cancelAbcRequestConfig(id = id)
val localVarResponse = request<MockRequest, MockResponse>(
localVariableConfig
)
.....
}
The problem is Unit
as request type when no explicit requestBody is added in specification of openAPI.
👍
@krzema12 Can you please review this and let me know any suggestion? I am very beginner for openAPI generator.
@patiramyadav sorry, I have literally no experience with Moshi. I contributed to Kotlin Multiplatform template where I kinda know kotlinx.serialization used for JSON serialization.
Anyway, my high-level suggestions about the bugfixing process in OpenAPI generator would be to:
kotlin-moshi-codegen
here: https://github.com/OpenAPITools/openapi-generator/blob/master/.github/workflows/samples-kotlin.yaml#L32 . Best if this bugfix was done in a TDD manner (first, add a test that would fail without this bugfix, and then make the test pass with a proper bugfix).I'm also affected by this bug, which started around April. I noticed it can be "fixed" in the generated code by adding a "content == null" branch in the ApiClient class like this:
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
when {
content is File -> content.asRequestBody(mediaType.toMediaTypeOrNull())
content == null -> ByteArray(0).toRequestBody()
When using latest version 5.2.0. I have tested with 5.2.1-SNAPSHOT and has still this issue. This works with 5.1.1 version.
Spec:
Note: no requestBody for patch.
Generated code:
Here, the request type is
Unit
. while 5.1.1 generates onlyrequest<MockResponse>
no request type.Extra related dependencies: