Gathering detailed insights and metrics for ajv-cli
Gathering detailed insights and metrics for ajv-cli
Gathering detailed insights and metrics for ajv-cli
Gathering detailed insights and metrics for ajv-cli
npm install ajv-cli
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
268 Stars
180 Commits
67 Forks
6 Watching
12 Branches
15 Contributors
Updated on 23 Nov 2024
TypeScript (96.53%)
JavaScript (3.47%)
Cumulative downloads
Total Downloads
Last day
4.2%
41,671
Compared to previous day
Last week
14.9%
230,046
Compared to previous week
Last month
25.1%
861,912
Compared to previous month
Last year
70.9%
6,147,359
Compared to previous year
1
23
Command line interface for ajv, one of the fastest json schema validators. Supports JSON, JSON5, and YAML.
1npm install -g ajv-cli
Parameter --spec
can be used with all commands (other than help) to choose JSON schema language:
--spec=draft7
(default) - support JSON Schema draft-07 (uses import Ajv from "ajv"
)--spec=draft2019
- support JSON Schema draft-2019-09 (uses import Ajv from "ajv/dist/2019"
)--spec=draft2020
- support JSON Schema draft-2020-12 (uses import Ajv from "ajv/dist/2020"
)--spec=jtd
- support JSON Type Definition (uses import Ajv from "ajv/dist/jtd"
)1ajv help 2ajv help validate 3ajv help compile 4ajv help migrate 5ajv help test
This command validates data files against JSON-schema
1ajv validate -s test/schema.json -d test/valid_data.json 2ajv -s test/schema.json -d test/valid_data.json
You can omit validate
command name and .json
from the input file names.
-s
- file name of JSON-schemaOnly one schema can be passed in this parameter
-d
- JSON dataMultiple data files can be passed, as in -r
parameter:
1ajv -s test/schema.json -d "test/valid*.json"
If some file is invalid exit code will be 1.
-r
- referenced schemasThe schema in -s
parameter can reference any of these schemas with $ref
keyword.
Multiple schemas can be passed both by using this parameter multiple times and with glob patterns. Glob pattern should be quoted and extensions cannot be omitted.
-m
- meta-schemasSchemas can use any of these schemas as a meta-schema (that is the schema used in $schema
keyword - it is used to validate the schema itself).
Multiple meta-schemas can be passed, as in -r
parameter.
-c
- custom keywords/formats definitionsYou can pass module(s) that define custom keywords/formats. The modules should export a function that accepts Ajv instance as a parameter. The file name should start with ".", it will be resolved relative to the current folder. The package name can also be passed - it will be used in require as is.
These modules can be written in TypeScript if you have ts-node
installed.
For example, you can use -c ajv-keywords
to add all keywords from ajv-keywords package or -c ajv-keywords/keywords/typeof
to add only typeof keyword.
--errors=
: error reporting format. Possible values:
js
(default): JavaScript objectjson
: JSON with indentation and line-breaksline
: JSON without indentation/line-breaks (for easy parsing)text
: human readable error messages with data paths--changes=
: detect changes in data after validation.
Data can be modified with Ajv options --remove-additional
, --use-defaults
and --coerce-types
).
The changes are reported in JSON-patch format (RFC6902).
Possible values are js
(default), json
and line
(see --errors
option).
This command validates and compiles schema without validating any data.
It can be used to check that the schema is valid and to create a standalone module exporting validation function(s).
1ajv compile -s schema 2 3# compile to module file 4ajv compile -s schema -o validate.js 5 6## compile to stdout, to allow code formatting (js-beautify has to be installed separately) 7ajv compile -s schema -o | js-beautify > validate.js
-s
- file name(s) of JSON-schema(s)Multiple schemas can be passed both by using this parameter multiple times and with glob patterns.
1ajv compile -s "test/schema*.json"
-o
- output file for compiled validation function moduleIf multiple schemas are compiled with this option the module will have multiple exports named as schema $id's or as file names, otherwise the module will export validation function as default export.
1ajv compile -s "schema.json" -o "validate_schema.js"
-o
without parameter should be used to output code to stdout to pass it to some code formatter.
This command also supports parameters -r
, -m
and -c
as in validate command.
This command validates and migrates schema from JSON Schema draft-04 to draft-07, draft-2019-09 or draft-2020-12 using json-schema-migrate package.
The version of JSON Schema is determined by --spec
parameter (only "draft7"
, "draft2019"
or "draft2020"
).
1ajv migrate -s schema 2 3# compile to specific file name 4ajv migrate -s schema -o migrated_schema.json
-s
- file name(s) of JSON-schema(s)Multiple schemas can be passed both by using this parameter multiple times and with glob patterns.
1ajv migrate -s "test/schema*.json"
If parameter -o
is not specified the migrated schema is written to the same file and the original file is preserved with .bak
extension.
If migration doesn't change anything in the schema file no changes in files are made.
-o
- output file for migrated schemaOnly a single schema can be migrated with this option.
1ajv compile -s "schema.json" -o migrated_schema.json
--indent=
: indentation in migrated schema JSON file, 4 by default--validate-schema=false
: skip schema validationThis command asserts that the result of the validation is as expected.
1ajv test -s test/schema.json -d test/valid_data.json --valid 2ajv test -s test/schema.json -d test/invalid_data.json --invalid
If the option --valid
(--invalid
) is used for the test
to pass (exit code 0) the data file(s) should be valid (invalid).
This command supports the same options and parameters as validate with the exception of --changes
.
You can pass the following Ajv options:
Option | Description |
---|---|
Strict mode | |
--strict= | true /false /log - set all strict mode restrictions |
--strict-schema= | log on (log ) or ignore (false ) strict restrictions (the default is to log) |
--strict-tuples= | throw on (true ) or ignore (false ) strict schema restrictions (the default is to throw) |
--strict-types= | throw on (true ) or ignore (false ) strict types restrictions (the default is to log) |
--strict-required= | throw on (true ) or log (log ) required properties restrictions (the default is to ignore) |
--allow-matching-properties | allow properties matching patterns in patternProperties |
--allow-union-types | allow union types |
--validate-formats=false | disable format validation |
Validation and reporting | |
--data | use $data references |
--all-errors | collect all validation errors |
--verbose | include schema and data in errors |
--comment | log schema $comment s |
--inline-refs= | referenced schemas compilation mode (true/false/<number>) |
Modify validated data | |
--remove-additional | remove additional properties (true/all/failing) |
--use-defaults | replace missing properties/items with the values from default keyword |
--coerce-types | change type of data to match type keyword |
Advanced | |
--multiple-of-precision | precision of multipleOf, pass integer number |
--messages=false | do not include text messages in errors |
--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) |
Code generation | |
--code-es5 | generate ES5 code |
--code-lines | generate multi-line code |
--code-optimize= | disable optimization (false ) or number of optimization passes (1 pass by default) |
--code-formats= | code to require formats object (only needed if you generate standalone code and do not use ajv-formats) |
Options can be passed using either dash-case or camelCase.
See Ajv Options for more information.
See https://github.com/ajv-validator/ajv-cli/releases
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/12 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More