Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for --uri-resolver #210

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ You can pass the following [Ajv options](https://ajv.js.org/options.html):
| Advanced |
| `--multiple-of-precision` | precision of multipleOf, pass integer number |
| `--messages=false` | do not include text messages in errors |
| `--uri-resolver=` | override embedded uriResolver (uri-js) with alternative (fast-uri) |
| `--loop-required=` | max size of `required` to compile to expression (rather than to loop) |
| `--loop-enum=` | max size of `enum` to compile to expression (rather than to loop) |
| `--own-properties` | only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"ajv": "^8.0.0",
"fast-json-patch": "^2.0.0",
"fast-uri": "^2.1.0",
"glob": "^7.1.0",
"js-yaml": "^3.14.0",
"json-schema-migrate": "^2.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {getOptions} from "./options"
import * as util from "./util"
import * as path from "path"
import * as draft6metaSchema from "ajv/lib/refs/json-schema-draft-06.json"
import * as fastUri from "fast-uri"

type AjvMethod = "addSchema" | "addMetaSchema"

Expand All @@ -30,6 +31,7 @@ const AjvClass: {[S in SchemaSpec]?: typeof AjvCore} = {

export default function (argv: ParsedArgs): AjvCore {
const opts = getOptions(argv)
if (argv["uri-resolver"] === "fast-uri") opts.uriResolver = fastUri
if (argv.o) opts.code.source = true
const Ajv: typeof AjvCore = AjvClass[argv.spec as SchemaSpec] || Ajv7
const ajv = new Ajv(opts)
Expand Down
2 changes: 2 additions & 0 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ Ajv options (see https://github.com/epoberezkin/ajv#options):

--own-properties only validate own properties (not relevant for JSON, but can have effect for JavaScript objects)

--uri-resolver= override embedded uriResolver (uri-js) with alternative (fast-uri)

--code-es5 generate ES5 code

--code-lines generate multi-line code
Expand Down
1 change: 1 addition & 0 deletions src/commands/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ajvOptions: SchemaMap = {
ownProperties: {type: "boolean"},
multipleOfPrecision: boolOrNat,
messages: {type: "boolean"},
uriResolver: {type: "string", enum: ["fast-uri"]},
[`${CODE}es5`]: {type: "boolean"},
[`${CODE}lines`]: {type: "boolean"},
[`${CODE}optimize`]: boolOrNat,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"allowJs": true,
"target": "ES2018",
"resolveJsonModule": true,
"esModuleInterop": false
"esModuleInterop": false,
"useUnknownInCatchVariables": false
}
}