Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define swagger property that is an unknown name?

Tags:

swagger

I need to define a swagger property that doesn't have a known name.

{
  "type": "object",
  "properties": {
      "?????": {
          "type": "array",
          "items": { "$ref": "#/definitions/ModelRelease" }
      }
}

The ????? portion of my definition is an integer of an unknown value. Any ideas?

like image 432
Nicholas Avatar asked Jun 22 '16 18:06

Nicholas


People also ask

What is schema in swagger?

OpenAPI 3.0 data types are based on an extended subset JSON Schema Specification Wright Draft 00 (aka Draft 5). The data types are described using a Schema object. To learn how to model various data types, see the following topics: Data Types.


1 Answers

You could use additionalProperties to define a hashmap ("?????" being a key in this hashmap without the need to define it):

{ 
  "type": "object", 
  "additionalProperties": { 
    "type": "array", 
    "items": { 
      "$ref": "#/definitions/ModelRelease" 
    }
  }
} 

In the general case, hashmaps can have an arbitrary number of items, but you can use minProperties and maxProperties to limit the item count. For example, if your object must have just one property:

{ 
  "type": "object",
  "additionalProperties": {
    "type": "array",
    "items": {
      "$ref": "#/definitions/ModelRelease" 
    }
  },
  "minProperties": 1,
  "maxProperties": 1
}
like image 186
Arnaud Lauret Avatar answered Oct 11 '22 12:10

Arnaud Lauret