dart-gde/discovery_api_dart_client_generator — pull request #111 by financeCoding (2014-03-12 23:12:27+00:00)
Title: Geo json

@scarygami @domesticmouse @kevmoo

Change set implements breaking changes from the discovery api. Introduction of `variant`, `discriminant`, top level `array` and `any` objects in the discovery documents. We now introduce `SchemaArray` and `SchemaAnyObject` to handle the new discovery api changes.

---

For example a definition of `"type": "array"`

```
"BboxBounds": {
"id": "BboxBounds",
"type": "array",
"description": "A rectangular geographic bounds, expressed as [lower_left_x, lower_left_y, upper_right_x, upper_right_y].",
"items": {
"type": "number",
"format": "double"
}
},
```

will now produce a class that extends from `SchemaArray`

```
/** A rectangular geographic bounds, expressed as [lower_left_x, lower_left_y, upper_right_x, upper_right_y]. */
class BboxBounds extends SchemaArray {

/** Create new BboxBounds from JSON data */
BboxBounds.fromJson(core.List json) {
innerList.addAll(json);
}

/** Create JSON Object for BboxBounds */
core.List toJson() {
return innerList;
}

/** Return String representation of BboxBounds */
core.String toString() => JSON.encode(this.toJson());

}
```

`SchemaArray` can support types defined in the discovery document.

```
"LineString": {
"id": "LineString",
"type": "array",
"description": "A coordinate array representing a line string.",
"items": {
"$ref": "Point"
}
}
```

```
/** A coordinate array representing a line string. */
class LineString extends SchemaArray {

/** Create new LineString from JSON data */
LineString.fromJson(core.List json) {
innerList.addAll(json.map((item) => new Point.fromJson(item)).toList());
}

/** Create JSON Object for LineString */
core.List toJson() {
return innerList.map((item) => item.toJson()).toList();
}

/** Return String representation of LineString */
core.String toString() => JSON.encode(this.toJson());

}
```

---

An example of `"type": "any"` can be defined expressed as follows

```
"GeoJsonProperties": {
"id": "GeoJsonProperties",
"type": "object",
"description": "The properties associated with a feature.",
"additionalProperties": {
"type": "any"
}
},
```

will now produce

```
/** The properties associated with a feature. */
class GeoJsonProperties extends SchemaAnyObject {

/** Create new GeoJsonProperties from JSON data */
GeoJsonProperties.fromJson(core.Map json) {
innerMap.addAll(json);
}

/** Create JSON Object for GeoJsonProperties */
core.Map toJson() {
return innerMap;
}

/** Return String representation of GeoJsonProperties */
core.String toString() => JSON.encode(this.toJson());

}
```

---

@domesticmouse does `"additionalProperties": {"type": "any"}` exclude the possibility of defined properties on an definition?