javayamlswaggeropenapiopenapi-generator

How to define Map objects in Open API 3.0, for GET API


I have GET API, which takes Map as a request param. How to define this in Open API 3.0, in yaml format

@GetMapping
public void getDevicesInfo(@RequestParam(required = false) Map parameters)
{

}

Open API is not supporting Map type.


Solution

  • In your YAML file you need to add additionalProperties for Map in Java and use parameters for @RequestParam as :

    /api/v1/test:
      get:
        tags:
          - test
        operationId: getDevicesInfo
        parameters:
          - name: parameters
            in: query
            required: false
            schema:
              type: object
              additionalProperties:
                type: object
        responses:
          '200':
            description: OK
    

    The generated GET API looks like:

    enter image description here

    I hope it helps you :)