Skip to content

[BUG][scala-akka-http-server] optional array parameter has invalid default value #10675

@krrrr38

Description

@krrrr38

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

scala-akka-http-server generator generate invalid query parameter default value, such as parameters("status".as[String].?("new ListBuffer[String]() ")).

openapi-generator version

5.2.1

OpenAPI declaration file content or url

It can be reproduced with following optional array query parameter yaml using /pet/findByStatus.

> wget https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml
> cp petstore.yaml petstore-optional-array-parameter.yaml
> $EDITOR petstore-optional-array-parameter.yaml # edit findByStatus operation with `required: false`
> diff -c petstore.yaml petstore-optional-array-parameter.yaml
*** petstore.yaml       2021-10-24 11:39:56.000000000 +0900
--- petstore-optional-array-parameter.yaml      2021-10-24 11:39:37.000000000 +0900
***************
*** 82,88 ****
          - name: status
            in: query
            description: Status values that need to be considered for filter
!           required: true
            style: form
            explode: false
            deprecated: true
--- 82,88 ----
          - name: status
            in: query
            description: Status values that need to be considered for filter
!           required: false
            style: form
            explode: false
            deprecated: true
Steps to reproduce

Using above petstore-optional-array-parameter.yaml, generator generates with invalid default value "new ListBuffer[String]() ".

> ./mvnw clean install
> java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
  -g scala-akka-http-server \
  -i petstore-optional-array-parameter.yaml \
  -o /var/tmp/scala-akka-http-server
> grep findByStatus -A4 /var/tmp/scala-akka-http-server/src/main/scala/org/openapitools/server/api/PetApi.scala
    path("pet" / "findByStatus") {
      get {
        parameters("status".as[String].?("new ListBuffer[String]() ")) { (status) =>
            petService.findPetsByStatus(status = status)
        }
Related issues/PRs

N/A

Suggest a fix

It seems that it is generated by following steps.

It might be better to generate parameters("status".as[String].?), even if it's dataType is String.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions