es-mapping-to-schema
Advanced tools
Comparing version 3.2.4 to 3.3.0
14
index.js
@@ -29,4 +29,8 @@ const _ = require('lodash'); | ||
schema[name] = determineType(mapping[name], {}, schemaType, nextOptions); | ||
result[name] = recurseMappingObjects(mapping[name], schema[name], schemaType, nextOptions, nextLocalOptions); | ||
// if (nextOptions.isArray) { | ||
// console.log('name: ' + name); | ||
// } else { | ||
schema[name] = determineType(mapping[name], {}, schemaType, nextOptions); | ||
result[name] = recurseMappingObjects(mapping[name], schema[name], schemaType, nextOptions, nextLocalOptions); | ||
// } | ||
@@ -41,6 +45,6 @@ return result; | ||
if (mapping.properties || mapping.type === 'object' || mapping.type === 'nested') { | ||
if (mapping.properties || mapping.type === 'object' || mapping.type === 'nested' || options.isArray) { | ||
if (options.isArray) { | ||
schema.items = {}; | ||
schema.items.type = 'object'; | ||
schema.items.type = determineType(mapping, {}, schemaType, Object.assign({}, options, {isArray: false})).type; | ||
@@ -164,3 +168,3 @@ if (mapping.properties) { | ||
if (_.includes(DIRECT_COPY_TYPES, type)) { | ||
return type === 'object' && isArray ? 'array' : type; | ||
return isArray ? 'array' : type; | ||
} else { | ||
@@ -167,0 +171,0 @@ switch (type) { |
{ | ||
"name": "es-mapping-to-schema", | ||
"version": "3.2.4", | ||
"version": "3.3.0", | ||
"description": "Convert Elasticsearch mappings to Schema Inspector schemas", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
43
test.js
@@ -1218,2 +1218,45 @@ const chai = require('chai'); | ||
}); | ||
it('should allow arrays of simple objects', () => { | ||
const mapping = { | ||
properties: { | ||
arrayOfStrings: { | ||
type: 'string' | ||
} | ||
} | ||
}; | ||
const expectedSchema = { | ||
type: 'object', | ||
properties: { | ||
arrayOfStrings: { | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
}; | ||
const schemas = MappingToSchema(mapping, { | ||
arrayPaths: [ | ||
'arrayOfStrings' | ||
], | ||
sanitization: { | ||
all: { | ||
types: [ | ||
'object', | ||
'string', | ||
'integer', | ||
'number', | ||
'array', | ||
'boolean', | ||
'date' | ||
] | ||
} | ||
} | ||
}); | ||
expect(schemas.validation).to.eql(expectedSchema); | ||
}); | ||
}); |
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
46701
1541