Skip to content

Arrays handling seems bugged #155

@krbob

Description

@krbob

I found a bug when generating api for a service responsing with an array of objects. Generated code doesn't point to proper class definition (TestObject in the example below replaced with Any?) despite it was properly generated.

Input:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0",
    "title": "test-swagger",
    "description": "https://test-swagger.com/"
  },
  "schemes": [
    "https",
    "http"
  ],
  "produces": [
    "application/json"
  ],
  "consumes": [
    "application/json"
  ],
  "paths": {
    "/api/test/swagger": {
      "get": {
        "tags": [
          "test-swagger"
        ],
        "summary": "Test swagger.",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "Uniqe id.",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "properties": {
                "cities": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/TestObject"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "TestObject": {
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}

Output:

package com.test.package.apis

import com.test.package.models.Any?
import retrofit2.http.GET
import retrofit2.http.Headers

@JvmSuppressWildcards
interface TestSwaggerApi {
    /**
     * Test swagger.
     * The endpoint is owned by defaultname service owner
     * @param id Uniqe id. (required)
     */
    @Headers(
        "Content-Type: application/json"
    )
    @GET("/api/test/swagger")
    suspend fun apiTestSwaggerGet(
        @retrofit2.http.Query("id") id: String
    ): Map<String, Any?>
}
package com.test.package.models

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
 * @property name
 */
@JsonClass(generateAdapter = true)
data class TestObject(
    @Json(name = "name") @field:Json(name = "name") var name: String? = null
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions