Skip to content

[JAVA] Retrofit2 Observable<Void> should be Observable<Response<Void>> #6553

@zkdzegede

Description

@zkdzegede
Description

API calls that have no response content causes a null pointer in retrofit.

Null is not a valid element

This is currently what is produced:

  @POST("logout")
  Observable<Void> logout();

This causes the: Observable onNext to never be called

Swagger-codegen version

2.2.3

Swagger declaration file content or url
  /logout:
    post:
      operationId: logout
      responses:
        200:
          description: success
        401:
          description: 401
Command line used for generation
{
  "library": "retrofit2",
  "groupId": "com.test",
  "artifactVersion":"0.0.2",
  "invokerPackage": "com.test",
  "modelPackage": "com.test.model",
  "apiPackage": "com.test.api",
  "useRxJava2": true,
  "hideGenerationTimestamp": true
}

swagger-codegen generate -i doc/api/definitions/test.yaml -c doc/api/config/test.json -l java -o libs/api/test

Using:
Kotlin, Java, Retrofit2

Steps to reproduce
  1. generate the api
  2. subscribe to api.logout()
Related issues/PRs

Suggest a fix/enhancement

Swagger-codgen produces Observable<Void> when it should produce Observable<Response<Void>>

I found the solution here: https://stackoverflow.com/questions/41914037/rxjava2-retrofit2-handling-null-for-204-put-and-delete-requests

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions