Skip to content

@CookieValue parameter indents request body #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Briggybros opened this issue Feb 13, 2020 · 2 comments
Closed

@CookieValue parameter indents request body #419

Briggybros opened this issue Feb 13, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@Briggybros
Copy link

Briggybros commented Feb 13, 2020

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 {
  }
}
@Briggybros
Copy link
Author

Note: This can be made to work with the following, but it feels like a bit of a hack:

@RestController("cookie")
public class HelloCookieController {

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

  @AllArgsConstructor
  public static class Item {
  }
}

@bnasslahsen
Copy link
Collaborator

Thank you @Briggybros for your clear description.
The fix will be available on v1.2.31.

@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants