-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add map and typedsl resolution documentation. (#96)
* Add map and typedsl resolution documentation. * Improve schema layout in spec. * Update Salad spec to mark as v1.0 instead of draft-1.
- Loading branch information
Showing
14 changed files
with
224 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
- | | ||
## Identifier maps | ||
The schema may designate certain fields as having a `mapSubject`. If the | ||
value of the field is a JSON object, it must be transformed into an array of | ||
JSON objects. Each key-value pair from the source JSON object is a list | ||
item, each list item must be a JSON objects, and the value of the key is | ||
assigned to the field specified by `mapSubject`. | ||
Fields which have `mapSubject` specified may also supply a `mapPredicate`. | ||
If the value of a map item is not a JSON object, the item is transformed to a | ||
JSON object with the key assigned to the field specified by `mapSubject` and | ||
the value assigned to the field specified by `mapPredicate`. | ||
### Identifier map example | ||
Given the following schema: | ||
``` | ||
- $include: map_res_schema.yml | ||
- | | ||
``` | ||
Process the following example: | ||
``` | ||
- $include: map_res_src.yml | ||
- | | ||
``` | ||
This becomes: | ||
``` | ||
- $include: map_res_proc.yml | ||
- | | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"mapped": [ | ||
{ | ||
"value": "daphne", | ||
"key": "fred" | ||
}, | ||
{ | ||
"value": "scooby", | ||
"key": "shaggy" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$graph": [{ | ||
"name": "MappedType", | ||
"type": "record", | ||
"documentRoot": true, | ||
"fields": [{ | ||
"name": "mapped", | ||
"type": { | ||
"type": "array", | ||
"items": "ExampleRecord" | ||
}, | ||
"jsonldPredicate": { | ||
"mapSubject": "key", | ||
"mapPredicate": "value" | ||
} | ||
}], | ||
}, | ||
{ | ||
"name": "ExampleRecord", | ||
"type": "record", | ||
"fields": [{ | ||
"name": "key", | ||
"type": "string" | ||
}, { | ||
"name": "value", | ||
"type": "string" | ||
} | ||
] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"mapped": { | ||
"shaggy": { | ||
"value": "scooby" | ||
}, | ||
"fred": "daphne" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
- | | ||
## Domain Specific Language for types | ||
Fields may be tagged `typeDSL: true`. If so, the field is expanded using the | ||
following micro-DSL for schema salad types: | ||
* If the type ends with a question mark `?` it is expanded to a union with `null` | ||
* If the type ends with square brackets `[]` it is expanded to an array with items of the preceeding type symbol | ||
* The type may end with both `[]?` to indicate it is an optional array. | ||
* Identifier resolution is applied after type DSL expansion. | ||
### Type DSL example | ||
Given the following schema: | ||
``` | ||
- $include: typedsl_res_schema.yml | ||
- | | ||
``` | ||
Process the following example: | ||
``` | ||
- $include: typedsl_res_src.yml | ||
- | | ||
``` | ||
This becomes: | ||
``` | ||
- $include: typedsl_res_proc.yml | ||
- | | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"extype": "string" | ||
}, | ||
{ | ||
"extype": [ | ||
"null", | ||
"string" | ||
] | ||
}, | ||
{ | ||
"extype": { | ||
"type": "array", | ||
"items": "string" | ||
} | ||
}, | ||
{ | ||
"extype": [ | ||
"null", | ||
{ | ||
"type": "array", | ||
"items": "string" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$graph": [ | ||
{"$import": "metaschema_base.yml"}, | ||
{ | ||
"name": "TypeDSLExample", | ||
"type": "record", | ||
"documentRoot": true, | ||
"fields": [{ | ||
"name": "extype", | ||
"type": "string", | ||
"jsonldPredicate": { | ||
_type: "@vocab", | ||
"typeDSL": true | ||
} | ||
}] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[{ | ||
"extype": "string" | ||
}, { | ||
"extype": "string?" | ||
}, { | ||
"extype": "string[]" | ||
}, { | ||
"extype": "string[]?" | ||
}] |
Oops, something went wrong.