Skip to content
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

[BUG][Spring] Fix cookie in parameters are always generated as required #12598

Closed
5 of 6 tasks
jorgerod opened this issue Jun 15, 2022 · 0 comments · Fixed by #12599
Closed
5 of 6 tasks

[BUG][Spring] Fix cookie in parameters are always generated as required #12598

jorgerod opened this issue Jun 15, 2022 · 0 comments · Fixed by #12599

Comments

@jorgerod
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

In the generation of Cookie type parameters, the required option is not being taken into account and when generating the code the @CookieValue is always required.

openapi-generator version

5.4.0, 6.0.0

OpenAPI declaration file content or url
  /v1/product/{id}:
    get:
      tags:
        - product
      summary: 'Find product by given id'
      description: 'The user must have any permission in the application.'
      operationId: 'findProductById'
      parameters:
        - name: 'id'
          in: 'path'
          description: 'ID of product to return'
          schema:
            type: string
          required: true
        - in: 'cookie'
          name: CookieFalse
          required: false
          schema:
            type: string
        - in: 'cookie'
          name: CookieTrue
          required: true
          schema:
            type: string
        - in: 'cookie'
          name: CookieDefault
          schema:
            type: string
Generation Details

Actual

  @ApiOperation(value = "Find product by given id", nickname = "findProductById",
      notes = "The user must have any permission in the application.", response = ProductDTO.class, authorizations = {
          @Authorization(value = "ItxApiKey")
      }, tags = {"product",})
  @ApiResponses(value = {
      @ApiResponse(code = 200, message = "OK", response = ProductDTO.class)})
  @RequestMapping(
      method = RequestMethod.GET,
      value = "/v1/product/{id}",
      produces = {"application/json"})
  public ResponseEntity<ProductDTO> findProductById2(
      @ApiParam(value = "ID of product to return", required = true) @PathVariable("id") String id,
      @NotNull @ApiParam(value = "", required = true) @CookieValue("CookieTrue") String cookieTrue,
      @ApiParam(value = "") @CookieValue("CookieFalse") String cookieFalse,
      @ApiParam(value = "") @CookieValue("CookieDefault") String cookieDefault) {
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
  }

Expected

  @ApiOperation(value = "Find product by given id", nickname = "findProductById",
      notes = "The user must have any permission in the application.", response = ProductDTO.class, authorizations = {
          @Authorization(value = "ItxApiKey")
      }, tags = {"product",})
  @ApiResponses(value = {
      @ApiResponse(code = 200, message = "OK", response = ProductDTO.class)})
  @RequestMapping(
      method = RequestMethod.GET,
      value = "/v1/product/{id}",
      produces = {"application/json"})
  public ResponseEntity<ProductDTO> findProductById2(
      @ApiParam(value = "ID of product to return", required = true) @PathVariable("id") String id,
      @NotNull @ApiParam(value = "", required = true) @CookieValue("CookieTrue") String cookieTrue,
      @ApiParam(value = "") @CookieValue(name = "CookieFalse", required = false) String cookieFalse,
      @ApiParam(value = "") @CookieValue(name = "CookieDefault", required = false) String cookieDefault) {
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
  }
Suggest a fix

Modify cookieParams.mustache to take into account the required field.

@jorgerod jorgerod changed the title [BUG] [JAVA | Spring] Fix cookie in parameters are always generated as required [BUG][Spring] Fix cookie in parameters are always generated as required Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant