Skip to content

[BUG] Kotlin: jvm-ktor library missing setContentType() when sending body #15811

@bcmedeiros

Description

@bcmedeiros

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Since Ktor needs the request to set a content type for the ContentNegotiation plugin to be activated, ktor fails with the following message:

Fail to prepare request body for sending.
The body type is: class generated.MyClass, with Content-Type: null.

Configuration is:
generatorName: kotlin
library: jvm-ktor

Workaround

You can manually set the content type for all requests doing something like:

    private val myApi = ConsentApi(baseUrl = "https://myapi.com/") {
        it.defaultRequest {
            contentType(ContentType.Application.Json)       // This shoud have been generated by the library
        }
        it.install(ContentNegotiation) {
            json()                                          // This line should have been generated as well
        }
    }
openapi-generator version

maven plugin 6.6.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
  1. Generate code for any spec containing a post/put method with a payload that needs to be serialized, using generatorName: kotlin and library: jvm-ktor.
  2. Call the post/put method
  3. Error will be thrown
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions