You’re correct. The Swagger spec (now OpenAPI) supports an extended subsect of 
JSON Schema. One of the things it does not support is multi-types.

JSON Schema wise – that’s absolutely valid.

 

 

From: <[email protected]> on behalf of Deryk Sinotte 
<[email protected]>
Reply-To: "[email protected]" 
<[email protected]>
Date: Monday, 11 July 2016 at 13:42
To: Swagger <[email protected]>
Subject: Re: How do I define an array of geospatial coordinates?

 

Thanks for responding. 

 

Just to be clear, I presume that you mean that the Swagger spec does not 
support this?  But the JSON Schema spec does?  It seems to be "legal" from the 
schema perspective and I've seen other JSON schema examples that have a similar 
approach.

 

Deryk

On Monday, 11 July 2016 12:29:18 UTC-7, Ron wrote: 

The spec doesn’t support multiple types under items, so you can’t really do 
that.

 

From: <[email protected]> on behalf of Deryk Sinotte 
<[email protected]>
Reply-To: "[email protected]" <[email protected]>
Date: Monday, 11 July 2016 at 12:07
To: Swagger <[email protected]>
Subject: How do I define an array of geospatial coordinates?

 

I feel like I'm missing something fundamental.  I have a Swagger file that 
contains the following body parameter to describe a geospatial position 
[longitude,latitude]: 

 

"parameters": [
  {
    "name": "body",
    "in": "body",
    "description": "Interesting description",
    "required": true,
    "schema": {
      "$ref": "#/definitions/Position"
    }
  }
]

I describe the Position as: 

 

"Position": {
  "description": "A single position",
  "type": "array",
  "minItems": 2,
  "maxItems": 2,
  "items": [
    {
      "type": "number"
    }
  ]

Which works and doesn't cause a problem for the Swagger UI but I want to 
provide a bit more detail:

 

"Position": {
  "description": "A single position",
  "type": "array",
  "minItems": 2,
  "items": [
    {
      "type": "number"
    },
    {
      "type": "number"
    }
  ]
 

As soon as that second item to the array, the Swagger UI will not display it.  
Ideally, I'd like to describe it something more like this:

 

"Longitude": {
  "title": "Longitudinal Value",
  "description": "A valid longitude (-180 to 180).",
  "type": "number",
  "minimum": -180,
  "maximum": 180,
  "default": 0
},
"Latitude": {
  "title": "Latitudinal Value",
  "description": "A valid latitude (-90 to 90).",
  "type": "number",
  "minimum": -90,
  "maximum": 90,
  "default": 0
},
"Position": {
  "description": "A single position",
  "type": "array",
  "minItems": 2,
  "maxItems": 2,
  "items": [
    {
      "$ref": "#/definitions/Longitude"
    },
    {
      "$ref": "#/definitions/Latitude"
    }
  ],
  "additionalItems": false
}

It just seems that once I add a second entry into the Position items array, the 
Swagger UI can't handle it.  Am I describing it incorrectly or is it some kind 
of Swagger UI limitation/bug?

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to