schema-to-object
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="1.2.0"></a> | ||
# [1.2.0](https://github.com/forsigner/schema-to-object/compare/v1.1.0...v1.2.0) (2018-01-02) | ||
### Features | ||
* merge schema-to-json ([d85f029](https://github.com/forsigner/schema-to-object/commit/d85f029)) | ||
<a name="1.1.0"></a> | ||
@@ -7,0 +17,0 @@ # [1.1.0](https://github.com/forsigner/schema-to-object/compare/v1.0.0...v1.1.0) (2017-12-30) |
'use strict'; | ||
var _require = require('./util'), | ||
clone = _require.clone, | ||
getLocalRef = _require.getLocalRef, | ||
mergeAllOf = _require.mergeAllOf; | ||
function clone(source) { | ||
return JSON.parse(JSON.stringify(source)); | ||
} | ||
var convert = function convert(schema, definitions) { | ||
var convert = function convert(schema, comment) { | ||
if (typeof schema.default !== 'undefined') { | ||
return schema.default; | ||
} else if (typeof schema.allOf !== 'undefined') { | ||
var mergedItem = mergeAllOf(schema.allOf, definitions); | ||
return convert(mergedItem, definitions); | ||
} else if (typeof schema.$ref !== 'undefined') { | ||
var reference = getLocalRef(schema.$ref, definitions); | ||
return convert(reference, definitions); | ||
} else if (schema.type === 'object') { | ||
@@ -27,7 +20,9 @@ var properties = schema.properties; | ||
if (properties[key].description) { | ||
properties['// ' + key] = properties[key].description; | ||
if (comment) { | ||
if (properties[key].description) { | ||
properties['// ' + key] = properties[key].description; | ||
} | ||
} | ||
properties[key] = convert(properties[key], definitions); | ||
properties[key] = convert(properties[key], comment); | ||
if (typeof properties[key] === 'undefined') { | ||
@@ -49,3 +44,3 @@ delete properties[key]; | ||
var _values = schema.items.map(function (item) { | ||
return convert(item, definitions); | ||
return convert(item, comment); | ||
}); | ||
@@ -64,3 +59,3 @@ // remove undefined items at the end (unless required by minItems) | ||
// object-typed arrays | ||
var value = convert(schema.items, definitions); | ||
var value = convert(schema.items, comment); | ||
if (typeof value === 'undefined') { | ||
@@ -78,5 +73,9 @@ return []; | ||
function main(schema) { | ||
return convert(clone(schema)); | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _options$comment = options.comment, | ||
comment = _options$comment === undefined ? false : _options$comment; | ||
return convert(clone(schema), comment); | ||
} | ||
module.exports = main; |
{ | ||
"name": "schema-to-object", | ||
"description": "", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "lib/defaults.js", | ||
@@ -6,0 +6,0 @@ "author": { |
4000
4
65