Swagger Response Class Map

I have a REST API that returns essentially a map (String, Object), where Object is also

  • Custom bean (for example, a Bean class) or
  • List of items, all types of Bean

In JSON, this is very well suited for:

{
   "key1":{
      "val1":"some string",
      "val2":"some other string",
      "val3":"another string"
   },
   "key2":[
      {
         "val1":"some string",
         "val2":"some other string",
         "val3":"another string"
      },
      {
         "val1":"some string",
         "val2":"some other string",
         "val3":"another string"
      }
   ]
}

Through swagger annotations, is there a way to specify this type of dynamic map as a response class?

thank

+3
source share
1 answer

I read the 'Open API Specification' - 'Add Support for Map Data Types No. 38' . As far as I understand, he recommends using additional properties, but I was not able to get it to work with Swagger UI 2.1.4 (see My related question: Swagger: map of a line, an object).

: , , "".

Swagger , , , , .

, Bean, Beans: Bean .

, , :

your_property: {
    description: "This is a map that can contain several objects indexed by different keys. The value can be either a Bean or a list of Beans.",
    type: object,
    properties: {
        key_for_single_bean: {
            description: "The value associated to 'key_for_single_bean' is a single Bean",
            $ref: "#/definitions/Bean"
        },
        key_for_list_of_beans: {
            description: "The value associated to 'key_for_list_of_beans' is an array of Beans",
            type: array,
            items: {$ref: "#/definitions/Bean"}
        }
    }
}
0

All Articles