Skip to content

Spring Data Web Support #3184

@DarioArena87

Description

@DarioArena87

Is your feature request related to a problem? Please describe.
I'm not sure if i'm doing something wrong or if i'm missing something but i think that when an application defines controllers using Spring Data Web Support (example on Baeldung) the resulting openapi specification is incorrectly generated.
I've tried to reproduce the example from the tutorial and included org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.14 in my project.
The generated openapi spec defines a parameter of type "User" for the method instead of it's id type (number or at least string):

"/users/{id}": {
      "get": {
        "tags": [
          "users-controller"
        ],
        "operationId": "findUserById",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/User"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      }
    }

... User definition schema ...

Describe the solution you'd like

In this case i think that the openapi spec should be generated with the path parameter id having as type the type of the entity id. For this specific case it should be "number" or "integer" but for entities wih ids of type String/UUID it should be "string". If the entity defines a composite id, annotated with @embeddable, the generated parameter specification should be of that type (I don't think it is widely used to have paths containing string representations of objects but maybe for a request body it could be useful)

Describe alternatives you've considered

If you manually force the type of the parameter the specification is generated correctly:

    @GetMapping("/{id}")
    User findUserById(@Parameter(schema = @Schema(type = "number")) @PathVariable("id") User user) {
        ...
    }
"/users/{id}": {
      "get": {
        "tags": [
          "users-controller"
        ],
        "operationId": "findUserById",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "number"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      }
    }

Is it possible to make this happen automatically? If spring doc already supports this, maybe can it be exposed in the documentation more clearly?

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