Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ajv-keywords

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-keywords - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

keywords/allRequired.js

43

keywords/_formatLimit.js

@@ -12,2 +12,17 @@ 'use strict';

var $dataMetaSchema = {
type: 'object',
required: [ '$data' ],
properties: {
$data: {
type: 'string',
anyOf: [
{ format: 'relative-json-pointer' },
{ format: 'json-pointer' }
]
}
},
additionalProperties: false
};
module.exports = function (minMax) {

@@ -21,19 +36,7 @@ var keyword = 'format' + minMax;

errors: 'full',
dependencies: ['format'],
metaSchema: {
anyOf: [
{ type: 'string' },
{
type: 'object',
required: [ '$data' ],
properties: {
$data: {
type: 'string',
anyOf: [
{ format: 'relative-json-pointer' },
{ format: 'json-pointer' }
]
}
},
additionalProperties: false
}
{type: 'string'},
$dataMetaSchema
]

@@ -44,3 +47,11 @@ }

ajv.addKeyword(keyword, defFunc.definition);
ajv.addKeyword('formatExclusive' + minMax);
ajv.addKeyword('formatExclusive' + minMax, {
dependencies: ['format' + minMax],
metaSchema: {
anyOf: [
{type: 'boolean'},
$dataMetaSchema
]
}
});
extendFormats(ajv);

@@ -47,0 +58,0 @@ return ajv;

@@ -12,3 +12,3 @@ 'use strict';

schemas.push(getSchema(pointer, schema[pointer]));
return { 'allOf': schemas };
return {'allOf': schemas};
},

@@ -15,0 +15,0 @@ metaSchema: {

@@ -74,3 +74,4 @@ 'use strict';

out = $$outStack.pop();
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
if (!it.compositeRule && $breakOnError) {
/* istanbul ignore if */
if (it.async) {

@@ -166,3 +167,4 @@ out += ' throw new ValidationError([' + (__err) + ']); ';

out = $$outStack.pop();
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
if (!it.compositeRule && $breakOnError) {
/* istanbul ignore if */
if (it.async) {

@@ -169,0 +171,0 @@ out += ' throw new ValidationError([' + (__err) + ']); ';

@@ -63,3 +63,4 @@ 'use strict';

out = $$outStack.pop();
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
if (!it.compositeRule && $breakOnError) {
/* istanbul ignore if */
if (it.async) {

@@ -104,3 +105,4 @@ out += ' throw new ValidationError([' + (__err) + ']); ';

out = $$outStack.pop();
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
if (!it.compositeRule && $breakOnError) {
/* istanbul ignore if */
if (it.async) {

@@ -107,0 +109,0 @@ out += ' throw new ValidationError([' + (__err) + ']); ';

@@ -9,2 +9,4 @@ 'use strict';

dynamicDefaults: require('./dynamicDefaults'),
allRequired: require('./allRequired'),
anyRequired: require('./anyRequired'),
prohibited: require('./prohibited'),

@@ -11,0 +13,0 @@ uniqueItemProperties: require('./uniqueItemProperties'),

@@ -7,8 +7,8 @@ 'use strict';

macro: function (schema) {
if (schema.length == 0) return {};
if (schema.length == 1) return { not: { required: schema } };
if (schema.length == 0) return true;
if (schema.length == 1) return {not: {required: schema}};
var schemas = schema.map(function (prop) {
return { required: [prop] };
return {required: [prop]};
});
return { not: { anyOf: schemas } };
return {not: {anyOf: schemas}};
},

@@ -26,2 +26,1 @@ metaSchema: {

};

@@ -33,3 +33,3 @@ 'use strict';

if (schema == 'toEnumCase') {
if (schema.indexOf('toEnumCase') !== -1) {
// build hash table to enum values

@@ -36,0 +36,0 @@ cfg = {hash: {}};

{
"name": "ajv-keywords",
"version": "3.3.0",
"version": "3.4.0",
"description": "Custom JSON-Schema keywords for Ajv validator",

@@ -10,3 +10,3 @@ "main": "index.js",

"test": "npm run build && npm run eslint && npm run test-cov",
"eslint": "eslint index.js keywords/*.js",
"eslint": "eslint index.js keywords/*.js spec",
"test-spec": "mocha spec/*.spec.js -R spec",

@@ -35,19 +35,19 @@ "test-cov": "istanbul cover -x 'spec/**' node_modules/mocha/bin/_mocha -- spec/*.spec.js -R spec"

"peerDependencies": {
"ajv": "^6.0.0"
"ajv": "^6.9.1"
},
"devDependencies": {
"ajv": "^6.0.0",
"ajv": "^6.9.1",
"ajv-pack": "^0.3.0",
"chai": "^4.0.2",
"coveralls": "^3.0.0",
"chai": "^4.2.0",
"coveralls": "^3.0.2",
"dot": "^1.1.1",
"eslint": "^5.0.0",
"glob": "^7.1.1",
"glob": "^7.1.3",
"istanbul": "^0.4.3",
"js-beautify": "^1.7.4",
"js-beautify": "^1.8.9",
"json-schema-test": "^2.0.0",
"mocha": "^5.0.0",
"mocha": "^5.2.0",
"pre-commit": "^1.1.3",
"uuid": "^3.0.1"
"uuid": "^3.3.2"
}
}

@@ -30,2 +30,4 @@ # ajv-keywords

- [Keywords for objects](#keywords-for-objects)
- [allRequired](allrequired)
- [anyRequired](anyrequired)
- [patternRequired](#patternrequired)

@@ -36,3 +38,3 @@ - [prohibited](#prohibited)

- [Compound keywords](#compound-keywords)
- [switch](#switch)
- [switch](#switch) (deprecated)
- [select/selectCases/selectDefault](#selectselectcasesselectdefault) (BETA)

@@ -194,3 +196,3 @@ - [Keywords for all types](#keywords-for-all-types)

The value of keyword `formatMaximum` (`formatMinimum`) should be a string. This value is the maximum (minimum) allowed value for the data to be valid as determined by `format` keyword.
The value of keyword `formatMaximum` (`formatMinimum`) should be a string. This value is the maximum (minimum) allowed value for the data to be valid as determined by `format` keyword. If `format` is not present schema compilation will throw exception.

@@ -313,2 +315,54 @@ When this keyword is added, it defines comparison rules for formats `"date"`, `"time"` and `"date-time"`. Custom formats also can have comparison rules. See [addFormat](https://github.com/epoberezkin/ajv#api-addformat) method.

#### `allRequired`
This keyword allows to require the presence of all properties used in `properties` keyword in the same schema object.
This keyword applies only to objects. If the data is not an object, the validation succeeds.
The value of this keyword must be boolean.
If the value of the keyword is `false`, the validation succeeds.
If the value of the keyword is `true`, the validation succeeds if the data contains all properties defined in `properties` keyword (in the same schema object).
If the `properties` keyword is not present in the same schema object, schema compilation will throw exception.
```javascript
var schema = {
properties: {
foo: {type: 'number'},
bar: {type: 'number'}
}
allRequired: true
};
var validData = { foo: 1, bar: 2 };
var alsoValidData = { foo: 1, bar: 2, baz: 3 };
var invalidDataList = [ {}, { foo: 1 }, { bar: 2 } ];
```
#### `anyRequired`
This keyword allows to require the presence of any (at least one) property from the list.
This keyword applies only to objects. If the data is not an object, the validation succeeds.
The value of this keyword must be an array of strings, each string being a property name. For data object to be valid at least one of the properties in this array should be present in the object.
```javascript
var schema = {
anyRequired: ['foo', 'bar']
};
var validData = { foo: 1 };
var alsoValidData = { foo: 1, bar: 2 };
var invalidDataList = [ {}, { baz: 3 } ];
```
__Please note__: By combining `anyRequired` with `maxProperties: 1` you can achieve that exactly one property from the list is required to be present for the data object to pass validation.
#### `patternRequired`

@@ -355,3 +409,5 @@

__Please note__: `{prohibited: ['foo', 'bar']}` is equivalent to `{not: {anyRequired: ['foo', 'bar']}}` (i.e. it has the same validation result for any data).
#### `deepProperties`

@@ -452,4 +508,6 @@

#### `switch`
#### `switch` (deprecated)
__Please note__: this keyword is provided to preserve backward compatibility with previous versions of Ajv. It is strongly recommended to use `if`/`then`/`else` keywords instead, as they have been added to the draft-07 of JSON Schema specification.
This keyword allows to perform advanced conditional validation.

@@ -499,3 +557,3 @@

__Please note__: this keyword is moved here from Ajv, mainly to preserve backward compatibility. It is unlikely to become a standard. It's preferable to use `if`/`then`/`else` keywords if possible, as they are likely to be added to the standard. The above schema is equivalent to (for example):
The above schema is equivalent to (for example):

@@ -502,0 +560,0 @@ ```javascript

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc