es-mapping-to-schema
Advanced tools
Comparing version 3.3.5 to 3.3.6
13
index.js
@@ -75,3 +75,3 @@ const _ = require('lodash'); | ||
const mappingType = mapping.properties ? 'object' : mapping.type; | ||
const type = convertEsTypeToSchemaType(mappingType, options.isArray); | ||
const type = convertEsTypeToSchemaType(mappingType, options.isArray, options.disableWarnings); | ||
@@ -170,3 +170,3 @@ if (schemaType === SANITIZATION_SCHEMA) { | ||
const convertEsTypeToSchemaType = (type, isArray) => { | ||
const convertEsTypeToSchemaType = (type, isArray, disableWarnings) => { | ||
if (_.includes(DIRECT_COPY_TYPES, type)) { | ||
@@ -188,3 +188,5 @@ return isArray ? 'array' : type; | ||
default: | ||
console.warn(`mapping type: ${_.isObject(type) ? JSON.stringify(type, null, 2) : type} is unsupported and will be ignored`); | ||
if (!disableWarnings) { | ||
console.warn(`mapping type: ${_.isObject(type) ? JSON.stringify(type, null, 2) : type} is unsupported and will be ignored`); | ||
} | ||
return null; | ||
@@ -196,4 +198,5 @@ } | ||
const DEFAULTS = { | ||
arrayPaths: [], | ||
validation: { | ||
disableWarnings: false, | ||
arrayPaths: [], | ||
validation: { | ||
all: { | ||
@@ -200,0 +203,0 @@ strict: false, |
@@ -8,2 +8,7 @@ const _ = require('lodash'); | ||
properties: { | ||
disableWarnings: { | ||
optional: true, | ||
def: false, | ||
type: 'boolean' | ||
}, | ||
arrayPaths: { | ||
@@ -10,0 +15,0 @@ optional: true, |
{ | ||
"name": "es-mapping-to-schema", | ||
"version": "3.3.5", | ||
"version": "3.3.6", | ||
"description": "Convert Elasticsearch mappings to Schema Inspector schemas", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -101,2 +101,4 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/637529966f1248808adb9fa263e98385)](https://www.codacy.com/app/GroupByInc/es-mapping-to-schema?utm_source=github.com&utm_medium=referral&utm_content=groupby/es-mapping-to-schema&utm_campaign=Badge_Grade) [![Coverage Status](https://coveralls.io/repos/github/groupby/es-mapping-to-schema/badge.svg?branch=master)](https://coveralls.io/github/groupby/es-mapping-to-schema?branch=master) [![CircleCI](https://circleci.com/gh/groupby/es-mapping-to-schema.svg?style=svg)](https://circleci.com/gh/groupby/es-mapping-to-schema) | ||
const Options = { | ||
// Do not display warnings when an unknown type is encountered | ||
disableWarnings: false, | ||
// 'arrayPaths' are used to define properties in the mapping that appear as objects but should be validated as arrays | ||
@@ -103,0 +105,0 @@ // This is because elasticsearch does not explicitly support arrays, but schema inspector does |
91
test.js
@@ -1418,2 +1418,65 @@ const chai = require('chai'); | ||
it('should apply strict sanitization to arrays of objects', () => { | ||
const mapping = { | ||
properties: { | ||
someObjectArray: { | ||
properties: { | ||
thing: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const expectedSchema = { | ||
type: 'object', | ||
strict: true, | ||
properties: { | ||
someObjectArray: { | ||
type: 'array', | ||
items: { | ||
strict: true, | ||
type: 'object', | ||
properties: { | ||
thing: { | ||
type: 'string', | ||
rules: [ | ||
'trim', | ||
'lower' | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const schemas = MappingToSchema(mapping, { | ||
arrayPaths: [ | ||
'someObjectArray' | ||
], | ||
sanitization: { | ||
all: { | ||
strict: true, | ||
types: [ | ||
'object', | ||
'integer', | ||
'string', | ||
'number', | ||
'array', | ||
'boolean', | ||
'date' | ||
], | ||
rules: [ | ||
'trim', | ||
'lower' | ||
] | ||
} | ||
} | ||
}); | ||
expect(schemas.sanitization).to.eql(expectedSchema); | ||
}); | ||
it('should nest validation in array', () => { | ||
@@ -1500,2 +1563,30 @@ const mapping = { | ||
}); | ||
it('optionally diaable warnings', () => { | ||
const mapping = { | ||
properties: { | ||
someString: { | ||
type: 'geo_point' | ||
} | ||
} | ||
}; | ||
MappingToSchema(mapping, { | ||
disableWarnings: true, | ||
validation: { | ||
all: { | ||
minLength: 1, | ||
types: [ | ||
'object', | ||
'integer', | ||
'string', | ||
'number', | ||
'array', | ||
'boolean', | ||
'date' | ||
] | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53438
1858
156