finatra-swagger icon indicating copy to clipboard operation
finatra-swagger copied to clipboard

generating list of object instead of list of strings

Open sgomezvillamor opened this issue 4 years ago • 2 comments

When modelling an API with a List (found similar issues with a Map, eg:

.responseWith[List[String]](200, "Some list")

Generated swagger file misses the type of the elements:

      responses:
        '200':
          description: Consumer list.
          schema:
            type: array
            items:
              type: object

It works fine if we use a case class instead:

  case class ConsumersResponse(consumers: List[String])

...
      .responseWith[ConsumersResponse](200, "Consumer list.")

Swagger generated file is correct:

        '200':
          description: Consumer list.
          schema:
            $ref: '#/definitions/ConsumersResponse'
...

  ConsumersResponse:
    type: object
    required:
      - consumers
    properties:
      consumers:
        type: array
        items:
          type: string

Is there anything I can do to make it work without the workaround of the case class?

Thanks!

sgomezvillamor avatar Nov 30 '20 18:11 sgomezvillamor

any comment here @jakehschwartz ? thanks

sgomezvillamor avatar Dec 07 '20 06:12 sgomezvillamor

@sgomezvillamor Hey, I can take a look this week probably. I typically use case classes, which is why Ive never run into this before.

I also wonder if it could be a bug with the actual (swagger scala module)[https://github.com/swagger-api/swagger-scala-module]. You could try generating your swagger json using that to see if there is an issue with their code

jakehschwartz avatar Dec 08 '20 03:12 jakehschwartz