Skip to content

@CookieValue parameter indents request body #419

Closed
@Briggybros

Description

@Briggybros

Describe the bug

When using @CookieValue to annotate a mapping parameter, the generated spec adds the cookie value to the definition of the request body; pushing the actual request body out to a property of the body. Adding an @Parameter annotation removes the cookie from the definition of the body, but the request body is still pushed to a property.

To Reproduce

Spring Boot: v2.1.2.RELEASE
springdoc-openapi-ui: 1.2.30

Actual:

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localhost:8900",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/{itemId}": {
            "put": {
                "tags": [
                    "hello-cookie-controller"
                ],
                "operationId": "putItem",
                "parameters": [
                    {
                        "name": "itemId",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "format": "uuid"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "cookie": {},
                                    "item": {
                                        "$ref": "#/components/schemas/Item"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "default response",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "$ref": "#/components/schemas/Item"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Item": {
                "type": "object"
            }
        }
    }
}

Expected:

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localhost:8900",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/{itemId}": {
            "put": {
                "tags": [
                    "hello-cookie-controller"
                ],
                "operationId": "putItem",
                "parameters": [
                    {
                        "name": "itemId",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "format": "uuid"
                        }
                    },
                    {
                        "name": "cookie",
                        "in": "cookie",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/Item"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "default response",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "$ref": "#/components/schemas/Item"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Item": {
                "type": "object"
            }
        }
    }
}

Issue is the same in YAML.

Sample Controller:

@RestController("cookie")
public class HelloCookieController {

  @PutMapping("/{itemId}")
  @Operation
  public ResponseEntity<Item> putItem(
      @Parameter(
          name = "cookie",
          in = ParameterIn.COOKIE,
          schema = @Schema(implementation = String.class)
      )
      @CookieValue(
          name = "cookie"
      ) String cookie,
      @PathVariable UUID itemId,
      @RequestBody Item item
  ) {
    return ResponseEntity.ok(item);
  }

  public static class Item {
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions