@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 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, schemaVersion?: string) => SDoc
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)