@hyperjump/json-schema 0.18.5 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -1
- package/dist/json-schema-amd.js +4217 -3188
- package/dist/json-schema-amd.js.map +1 -1
- package/dist/json-schema-amd.min.js +2 -1
- package/dist/json-schema-amd.min.js.map +1 -1
- package/dist/json-schema-cjs.js +2388 -1359
- package/dist/json-schema-cjs.js.map +1 -1
- package/dist/json-schema-cjs.min.js +2 -1
- package/dist/json-schema-cjs.min.js.map +1 -1
- package/dist/json-schema-esm.js +2389 -1347
- package/dist/json-schema-esm.js.map +1 -1
- package/dist/json-schema-esm.min.js +2 -1
- package/dist/json-schema-esm.min.js.map +1 -1
- package/dist/json-schema-iife.js +4221 -3192
- package/dist/json-schema-iife.js.map +1 -1
- package/dist/json-schema-iife.min.js +2 -1
- package/dist/json-schema-iife.min.js.map +1 -1
- package/dist/json-schema-system.js +4220 -3178
- package/dist/json-schema-system.js.map +1 -1
- package/dist/json-schema-system.min.js +2 -1
- package/dist/json-schema-system.min.js.map +1 -1
- package/dist/json-schema-umd.js +4220 -3191
- package/dist/json-schema-umd.js.map +1 -1
- package/dist/json-schema-umd.min.js +2 -1
- package/dist/json-schema-umd.min.js.map +1 -1
- package/lib/draft-04.js +6 -6
- package/lib/draft-06.js +6 -6
- package/lib/draft-07.js +6 -6
- package/lib/draft-2019-09.js +7 -7
- package/lib/draft-2020-12.js +7 -7
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -88,6 +88,43 @@ JsonSchema.setMetaOutputFormat(JsonSchema.FLAG);
|
|
|
88
88
|
JsonSchema.setShouldMetaValidate(false);
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
### Media Types
|
|
92
|
+
JSV has a plugin system for adding support for different media types. By default
|
|
93
|
+
it's configured to accept schemas that have the `application/schema+json`
|
|
94
|
+
Content-Type (web) or a `.schema.json` file extension (filesystem). If for
|
|
95
|
+
example, you want to fetch schemas that are written in YAML, you can add a
|
|
96
|
+
MediaTypePlugin to support that.
|
|
97
|
+
|
|
98
|
+
* **Core.addMediaTypePlugin**: (contentType: string, plugin: MediaTypePlugin) => void
|
|
99
|
+
|
|
100
|
+
Add a custom media type handler to support things like YAML or to change the
|
|
101
|
+
way JSON is supported.
|
|
102
|
+
* **MediaTypePlugin**: object
|
|
103
|
+
|
|
104
|
+
* parse: (response: Response) => string -- Given a fetch Response object,
|
|
105
|
+
parse the body of the request
|
|
106
|
+
* matcher: (path) => boolean -- Given a filesystem path, return whether or
|
|
107
|
+
not the file should be considered a member of this media type
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
const JsonSchema = require("@hyperjump/json-schema");
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// Add support for JSON Schemas written in YAML
|
|
114
|
+
JsonSchema.addMediaTypePlugin("application/schema+yaml", {
|
|
115
|
+
parse: async (response) => YAML.parse(await response.text()),
|
|
116
|
+
matcher: (path) => path.endsWith(".schema.yaml")
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Example: Fetch schema with Content-Type: application/schema+yaml from the web
|
|
120
|
+
const schema = await JsonSchema.get("http://example.com/schemas/string");
|
|
121
|
+
|
|
122
|
+
// Example: Fetch from file with JSON Schema YAML file extension
|
|
123
|
+
const schema = await JsonSchema.get("file:///path/to/my/schemas/string.schema.yaml");
|
|
124
|
+
|
|
125
|
+
// Then validate against your schema like normal
|
|
126
|
+
```
|
|
127
|
+
|
|
91
128
|
## TypeScript
|
|
92
129
|
Although the package is written in JavaScript, type definitions are included for
|
|
93
130
|
TypeScript support. The following example shows the types you might want to
|
|
@@ -121,7 +158,7 @@ try {
|
|
|
121
158
|
```
|
|
122
159
|
|
|
123
160
|
## API
|
|
124
|
-
* **add**: (schema: object, url?: URI,
|
|
161
|
+
* **add**: (schema: object, url?: URI, dialectId?: string) => SDoc
|
|
125
162
|
|
|
126
163
|
Load a schema. See [JSC - $id](https://github.com/hyperjump-io/json-schema-core#id)
|
|
127
164
|
and [JSC - $schema](https://github.com/hyperjump-io/json-schema-core#schema-1)
|