How do I define an array of geospatial coordinates?

760 views
Skip to first unread message

Deryk Sinotte

unread,
Jul 11, 2016, 3:07:03 PM7/11/16
to Swagger
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?

Ron Ratovsky

unread,
Jul 11, 2016, 3:29:18 PM7/11/16
to swagger-sw...@googlegroups.com

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

--
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 swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deryk Sinotte

unread,
Jul 11, 2016, 4:42:05 PM7/11/16
to Swagger
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

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
Jul 11, 2016, 5:03:02 PM7/11/16
to swagger-sw...@googlegroups.com

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.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


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 swagger-swaggers...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages