Skip to content

Generic fields in ParameterObject are not resolved #1128

Closed
@orange-buffalo

Description

@orange-buffalo

Consider the following use-case, where @ParameterObject refers to a class that extends a parametrized class:

open class AbstractParameterObject<T : Enum<T>> {

    var primitiveBaseField: Int? = null
    var genericField: T? = null
}

enum class ConcreteEnum {
    ONE,
    TWO
}

class ConcreteParameterObject : AbstractParameterObject<ConcreteEnum>() {
    var primitiveConcreteField: Int? = null
}

@RestController
@RequestMapping("/")
class HelloController {

    @GetMapping
    fun test(@ParameterObject requestData: ConcreteParameterObject): String = "hello"

}

Expected schema should contain the genericField definition, but it does not:

"parameters": [
  {
    "name": "primitiveConcreteField",
    "in": "query",
    "required": false,
    "schema": {
      "type": "integer",
      "format": "int32"
    }
  },
  {
    "name": "primitiveBaseField",
    "in": "query",
    "required": false,
    "schema": {
      "type": "integer",
      "format": "int32"
    }
  }
],

I reproduced the problem with a test in springdoc-openapi code base - please see the branch changes - and was able to get the field in the API definition. Unfortunately, the schema is still not generated properly. The issue is that at the moment when calculateSchema is called, the information about the original parameter class (ConcreteParameterObject from the example above) is already lost and we only have the declaring class for the getter (AbstractParameterObject). Obviously, there is not enough information to resolve the type information and wrong schema gets generated (or not at all for the enum case).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions