title: Modelling GeoJSON in Swagger
body: <p>I'm trying to add a definition for GeoJSON in a Swagger API that serves JSON. I'm running into some issues with defining the options that GeoJSON has for features. </p>
  
  <p>A single feature can be a choice of <code>"Point"</code>, <code>"MultiPoint"</code>, <code>"LineString"</code>, <code>"MultiLineString"</code>, <code>"Polygon"</code>, or a <code>"MultiPolygon"</code>. Each of these though imposes different constraints on their <code>coordinates</code> field. For instance, a point might have a single coordinate consisting of an longtitude latitude pai, while a Polygon might have a field that looks like this:
  <code>[ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ]</code>.</p>
  
  <p>I've looked around but there seems no elegant solution to this problem except by just defining the geometry as a <code>string</code> instead of a complex object like this. This means a loss of information, and makes it undesirable to port APIs based on a Swagger specification because input strings will have to be parsed to an object first. </p>
  
  <p>The GeoJSON objects look like <a href="http://geojson.org/geojson-spec.html#examples" rel="nofollow">this</a>.</p>
  
  <p>What I've got so far is this:</p>
  
  <pre><code>  "Feature": {
        "type": "object",
        "properties": {
          "id": {
          },
          "geometry": {
            "$ref": "#/definitions/Geometry"
          },
          "type" : {
            "type" : "string"
          },
          "properties": {
              "type": "object"
          }
      }
  }
  </code></pre>
  
  <p>And the geometry definition looks like this:</p>
  
  <pre><code>"Geometry": {
    "type": "object",
    "properties": {
      "type":{
        "type": "string",
        "enum": ["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"]
      },
      "coordinates": {
        "type": "array",
        "items": {
          "type": "number",
          "example": [4.49965, 52.06891]
        }
      }
    }
  }
  </code></pre>