2

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.

Viktor Reinok
  • 113
  • 13
Mamatha K
  • 21
  • 1
  • 6
  • Do you mean what Java annotations to use (i.e. if you generate the API definition from the source code) or what's the OpenAPI YAML syntax for dictionaries/maps? – Helen Dec 16 '19 at 10:37
  • Can you provide an example of such request? – WeGa Feb 15 '23 at 16:08

1 Answers1

6

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 :)

Suraj Gautam
  • 1,524
  • 12
  • 21