Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13718
Closed
Open
Issue created 2 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

[BUG][Kotlin/okhttp-gson] wrong handling of empty response

Open

[BUG][Kotlin/okhttp-gson] wrong handling of empty response

Created by: zoltanwork

Description

We use a legacy REST server that returns a non-empty response even if it the response type is Unit. In this case the following exception is thrown: java.lang.IllegalArgumentException: Platform class kotlin.Unit requires explicit JsonAdapter to be registered at com.squareup.moshi.ClassJsonAdapter$1.create(ClassJsonAdapter.java:76) at com.squareup.moshi.Moshi.adapter(Moshi.java:146) at com.squareup.moshi.Moshi.adapter(Moshi.java:106) at com.squareup.moshi.Moshi.adapter(Moshi.java:75) at com.squareup.moshi._MoshiKotlinExtensionsKt.adapter(-MoshiKotlinExtensions.kt:40) ...

I checked another generator (Java/apache-httpclient) to see how it handles this case. There the Java class of the expected result is checked and the code doesn't call the JSON deserializer if no response is expected.

openapi-generator version

6.0.1

Suggest a fix/enhancement

Suggestion is to change the line 251 in the src\main\resources\kotlin-client\libraries\jvm-okhttp\infrastructure\ApiClient.kt.mustache from

        if (bodyContent.isEmpty()) {

to

        if (typeOf<T>() == typeOf<Unit?>()) {
  1. Oh no!

    You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico.

    Incoming!

    Drop your designs to start your upload.
Tasks
0

No tasks are currently assigned. Use tasks to break down this issue into smaller parts.

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


  • William Cheng
    William Cheng @wing328 · 2 years ago
    Contributor

    can you please file a PR with the suggested fix and we'll review accordingly? thanks

  • Administrator
    Administrator @root · 2 years ago
    Author Contributor

    Created by: zoltanwork

    Sorry , I am not familiar with github. I did what you suggested. Can you please check if it is OK? Thanks

Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
No estimate or time spent
Confidentiality
Not confidential
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
2
2 participants
William Cheng
Administrator
Reference: OpenAPITools/openapi-generator#13718

Menu

Explore Projects Groups Snippets