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

json-schema-merge-allof

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-merge-allof - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

0

.eslintrc.js

@@ -0,0 +0,0 @@ module.exports = {

2

package.json
{
"name": "json-schema-merge-allof",
"version": "0.6.0",
"version": "0.7.0",
"description": "Simplify your schema by combining allOf into the root schema, safely.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -72,19 +72,2 @@ # json-schema-merge-allof [![Build Status](https://travis-ci.org/mokkabonna/json-schema-merge-allof.svg?branch=master)](https://travis-ci.org/mokkabonna/json-schema-merge-allof) [![Coverage Status](https://coveralls.io/repos/github/mokkabonna/json-schema-merge-allof/badge.svg?branch=master)](https://coveralls.io/github/mokkabonna/json-schema-merge-allof?branch=master)

### pattern
If a schema have the pattern keyword and we have a conflict, then we need to leave that expressed like this:
```js
{
type: 'string',
allOf: [{
pattern: '\\w+\\s\\w+'
}, {
pattern: '123$'
}]
}
```
Regular expressions does not have an AND operator, only OR.
### not

@@ -91,0 +74,0 @@

@@ -48,17 +48,9 @@ var cloneDeep = require('lodash/cloneDeep')

function getAllOf(schema) {
if (Array.isArray(schema.allOf)) {
var allOf = schema.allOf
delete schema.allOf
return [schema].concat(allOf.map(function(allSchema) {
return getAllOf(allSchema)
}))
} else {
return [schema]
}
let { allOf = [], ...copy } = schema
copy = isPlainObject(schema) ? copy : schema // if schema is boolean
return [copy, ...allOf.map(getAllOf)]
}
function getValues(schemas, key) {
return schemas.map(function(schema) {
return schema && schema[key]
})
return schemas.map(schema => schema && schema[key])
}

@@ -397,7 +389,4 @@

},
pattern(compacted, paths, mergeSchemas, options, reportUnresolved) {
var key = paths.pop()
reportUnresolved(compacted.map(function(regexp) {
return {[key]: regexp}
}))
pattern(compacted) {
return compacted.map(r => '(?=' + r + ')').join('')
},

@@ -546,3 +535,3 @@ multipleOf(compacted) {

var allSchemas = flattenDeep(getAllOf(rootSchema))
var merged = mergeSchemas(allSchemas, rootSchema)
var merged = mergeSchemas(allSchemas)

@@ -549,0 +538,0 @@ return merged

@@ -0,0 +0,0 @@ describe('extraction', function() {

var chai = require('chai')
var mergerModule = require('../../src')
var Ajv = require('ajv')
var _ = require('lodash')
var $RefParser = require('json-schema-ref-parser')

@@ -24,2 +25,97 @@

describe('module', function() {
it('merges schema with same object reference multiple places', () => {
var commonSchema = {
allOf: [{
properties: {
test: true
}
}]
}
var result = merger({
properties: {
list: {
items: commonSchema
}
},
allOf: [commonSchema]
})
expect(result).to.eql({
properties: {
list: {
items: {
properties: {
test: true
}
}
},
test: true
}
})
})
it('does not alter original schema', () => {
var schema = {
allOf: [{
properties: {
test: true
}
}]
}
var result = merger(schema)
expect(result).to.eql({
properties: {
test: true
}
})
expect(result).not.to.equal(schema) // not strict equal (identity)
expect(schema).to.eql({
allOf: [{
properties: {
test: true
}
}]
})
})
it('does not use any original objects or arrays', () => {
const schema = {
properties: {
arr: {
type: 'array',
items: {
type: 'object'
},
additionalItems: [{
type: 'array'
}]
}
},
allOf: [{
properties: {
test: true
}
}]
}
function innerDeconstruct(schema) {
const allChildObj = Object.entries(schema).map(([key, val]) => {
if (_.isObject(val)) return innerDeconstruct(val)
})
return [schema, ..._.flatten(allChildObj)]
}
const getAllObjects = schema => _(innerDeconstruct(schema)).compact().value()
const inputObjects = getAllObjects(schema)
const result = merger(schema)
const resultObjects = getAllObjects(result)
const commonObjects = _.intersection(inputObjects, resultObjects)
expect(commonObjects).to.have.length(0)
})
it('combines simple usecase', function() {

@@ -781,7 +877,3 @@ var result = merger({

type: 'string',
allOf: [{
pattern: 'bar'
}, {
pattern: 'foo'
}]
pattern: '(?=bar)(?=foo)'
}

@@ -803,7 +895,3 @@ }

expect(result).to.eql({
allOf: [{
pattern: 'fdsaf'
}, {
pattern: 'abba'
}]
pattern: '(?=fdsaf)(?=abba)'
})

@@ -810,0 +898,0 @@

@@ -43,7 +43,3 @@ var chai = require('chai')

type: 'string',
allOf: [{
pattern: 'bar'
}, {
pattern: 'foo'
}]
pattern: '(?=bar)(?=foo)'
}

@@ -50,0 +46,0 @@ }

@@ -0,0 +0,0 @@ var chai = require('chai')

@@ -0,0 +0,0 @@ var chai = require('chai')

@@ -0,0 +0,0 @@ var chai = require('chai')

@@ -0,0 +0,0 @@ describe('stripping', function() {

@@ -0,0 +0,0 @@ describe('validation', function() {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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