A generalized JSON scheme is a scheme parameterized by other schemes. This concept resembles generalized types in programming languages.
Consider an example in TypeScript:
interface PolyLine<T> {
points: T[];
totalLength: number;
}
interface Point2d {
x: number;
y: number;
}
interface GeoPoint {
lat: number;
lng: number;
}
interface Foo {
shape: PolyLine<Point2d>;
road: PolyLine<GeoPoint>;
}
The same data structures in the form of a generalized JSON scheme (yaml):
PolyLine:
type: object
properties:
points:
type: array
items:
$ref: $ctx/T
totalLength:
type: number
Point2d:
type: object
properties:
x:
type: number
y:
type: number
GeoPoint:
type: object
properties:
lat:
type: number
lng:
type: number
Foo:
type: object
properties:
shape:
$ref: "#/PolyLine?T=%23/Point2d"
road:
$ref: "#/PolyLine?T=%23/GeoPoint"