@hyperjump/json-schema 0.19.0 → 0.22.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,44 @@ 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
+ const YAML = require("yaml");
112
+
113
+
114
+ // Add support for JSON Schemas written in YAML
115
+ JsonSchema.addMediaTypePlugin("application/schema+yaml", {
116
+ parse: async (response) => YAML.parse(await response.text()),
117
+ matcher: (path) => path.endsWith(".schema.yaml")
118
+ });
119
+
120
+ // Example: Fetch schema with Content-Type: application/schema+yaml from the web
121
+ const schema = await JsonSchema.get("http://example.com/schemas/string");
122
+
123
+ // Example: Fetch from file with JSON Schema YAML file extension
124
+ const schema = await JsonSchema.get("file:///path/to/my/schemas/string.schema.yaml");
125
+
126
+ // Then validate against your schema like normal
127
+ ```
128
+
91
129
  ## TypeScript
92
130
  Although the package is written in JavaScript, type definitions are included for
93
131
  TypeScript support. The following example shows the types you might want to
@@ -121,7 +159,7 @@ try {
121
159
  ```
122
160
 
123
161
  ## API
124
- * **add**: (schema: object, url?: URI, schemaVersion?: string) => SDoc
162
+ * **add**: (schema: object, url?: URI, dialectId?: string) => SDoc
125
163
 
126
164
  Load a schema. See [JSC - $id](https://github.com/hyperjump-io/json-schema-core#id)
127
165
  and [JSC - $schema](https://github.com/hyperjump-io/json-schema-core#schema-1)