openapi-sampler
Advanced tools
Comparing version 1.0.0-beta.17 to 1.0.0-beta.18
@@ -277,3 +277,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.OpenAPISampler = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
function allOfSample(into, children, options, spec) { | ||
function allOfSample(into, children, options, spec, context) { | ||
var res = (0, _traverse2.traverse)(into, options, spec); | ||
@@ -291,3 +291,3 @@ var subSamples = []; | ||
type: res.type | ||
}, subSchema), options, spec), | ||
}, subSchema), options, spec, context), | ||
type = _traverse.type, | ||
@@ -414,3 +414,4 @@ readOnly = _traverse.readOnly, | ||
var defaults = { | ||
skipReadOnly: false | ||
skipReadOnly: false, | ||
maxSampleDepth: 15 | ||
}; | ||
@@ -457,2 +458,4 @@ | ||
var spec = arguments.length > 2 ? arguments[2] : undefined; | ||
var context = arguments.length > 3 ? arguments[3] : undefined; | ||
var depth = context && context.depth || 1; | ||
var arrayLength = schema.minItems || 1; | ||
@@ -478,3 +481,5 @@ | ||
var _traverse = (0, _traverse2.traverse)(itemSchema, options, spec), | ||
var _traverse = (0, _traverse2.traverse)(itemSchema, options, spec, { | ||
depth: depth + 1 | ||
}), | ||
sample = _traverse.value; | ||
@@ -602,3 +607,5 @@ | ||
var spec = arguments.length > 2 ? arguments[2] : undefined; | ||
var context = arguments.length > 3 ? arguments[3] : undefined; | ||
var res = {}; | ||
var depth = context && context.depth || 1; | ||
@@ -618,3 +625,4 @@ if (schema && _typeof(schema.properties) === 'object') { | ||
var sample = (0, _traverse.traverse)(schema.properties[propertyName], options, spec, { | ||
propertyName: propertyName | ||
propertyName: propertyName, | ||
depth: depth + 1 | ||
}); | ||
@@ -635,4 +643,8 @@ | ||
if (schema && _typeof(schema.additionalProperties) === 'object') { | ||
res.property1 = (0, _traverse.traverse)(schema.additionalProperties, options, spec).value; | ||
res.property2 = (0, _traverse.traverse)(schema.additionalProperties, options, spec).value; | ||
res.property1 = (0, _traverse.traverse)(schema.additionalProperties, options, spec, { | ||
depth: depth + 1 | ||
}).value; | ||
res.property2 = (0, _traverse.traverse)(schema.additionalProperties, options, spec, { | ||
depth: depth + 1 | ||
}).value; | ||
} | ||
@@ -779,3 +791,3 @@ | ||
function traverse(schema, options, spec, context) { | ||
// checking circular JS references by checking context | ||
// checking circular JS references by checking context | ||
// because context is passed only when traversing through nested objects happens | ||
@@ -787,2 +799,7 @@ if (context) { | ||
if (context && context.depth > options.maxSampleDepth) { | ||
(0, _utils.popSchemaStack)(seenSchemasStack, context); | ||
return (0, _utils.getResultForCircular)((0, _infer.inferType)(schema)); | ||
} | ||
if (schema.$ref) { | ||
@@ -805,3 +822,3 @@ if (!spec) { | ||
$refCache[ref] = true; | ||
result = traverse(referenced, options, spec); | ||
result = traverse(referenced, options, spec, context); | ||
$refCache[ref] = false; | ||
@@ -831,3 +848,3 @@ } else { | ||
allOf: undefined | ||
}), schema.allOf, options, spec); | ||
}), schema.allOf, options, spec, context); | ||
} | ||
@@ -841,3 +858,3 @@ | ||
(0, _utils.popSchemaStack)(seenSchemasStack, context); | ||
return traverse(schema.oneOf[0], options, spec); | ||
return traverse(schema.oneOf[0], options, spec, context); | ||
} | ||
@@ -847,3 +864,3 @@ | ||
(0, _utils.popSchemaStack)(seenSchemasStack, context); | ||
return traverse(schema.anyOf[0], options, spec); | ||
return traverse(schema.anyOf[0], options, spec, context); | ||
} | ||
@@ -850,0 +867,0 @@ |
{ | ||
"name": "openapi-sampler", | ||
"version": "1.0.0-beta.17", | ||
"version": "1.0.0-beta.18", | ||
"description": "Tool for generation samples based on OpenAPI payload/response schema", | ||
@@ -5,0 +5,0 @@ "main": "dist/openapi-sampler.js", |
import { traverse } from './traverse'; | ||
import { mergeDeep } from './utils'; | ||
export function allOfSample(into, children, options, spec) { | ||
export function allOfSample(into, children, options, spec, context) { | ||
let res = traverse(into, options, spec); | ||
@@ -9,3 +9,3 @@ const subSamples = []; | ||
for (let subSchema of children) { | ||
const { type, readOnly, writeOnly, value } = traverse({ type: res.type, ...subSchema }, options, spec); | ||
const { type, readOnly, writeOnly, value } = traverse({ type: res.type, ...subSchema }, options, spec, context); | ||
if (res.type && type && type !== res.type) { | ||
@@ -12,0 +12,0 @@ console.warn('allOf: schemas with different types can\'t be merged'); |
@@ -7,3 +7,4 @@ import { traverse, clearCache } from './traverse'; | ||
const defaults = { | ||
skipReadOnly: false | ||
skipReadOnly: false, | ||
maxSampleDepth: 15, | ||
}; | ||
@@ -10,0 +11,0 @@ |
import { traverse } from '../traverse'; | ||
export function sampleArray(schema, options = {}, spec) { | ||
export function sampleArray(schema, options = {}, spec, context) { | ||
const depth = (context && context.depth || 1); | ||
let arrayLength = schema.minItems || 1; | ||
@@ -20,3 +22,3 @@ if (Array.isArray(schema.items)) { | ||
let itemSchema = itemSchemaGetter(i); | ||
let { value: sample } = traverse(itemSchema, options, spec); | ||
let { value: sample } = traverse(itemSchema, options, spec, {depth: depth + 1}); | ||
res.push(sample); | ||
@@ -23,0 +25,0 @@ } |
import { traverse } from '../traverse'; | ||
export function sampleObject(schema, options = {}, spec) { | ||
export function sampleObject(schema, options = {}, spec, context) { | ||
let res = {}; | ||
const depth = (context && context.depth || 1); | ||
if (schema && typeof schema.properties === 'object') { | ||
@@ -17,3 +19,3 @@ let requiredKeys = (Array.isArray(schema.required) ? schema.required : []); | ||
const sample = traverse(schema.properties[propertyName], options, spec, { propertyName }); | ||
const sample = traverse(schema.properties[propertyName], options, spec, { propertyName, depth: depth + 1 }); | ||
if (options.skipReadOnly && sample.readOnly) { | ||
@@ -31,6 +33,6 @@ return; | ||
if (schema && typeof schema.additionalProperties === 'object') { | ||
res.property1 = traverse(schema.additionalProperties, options, spec).value; | ||
res.property2 = traverse(schema.additionalProperties, options, spec).value; | ||
res.property1 = traverse(schema.additionalProperties, options, spec, {depth: depth + 1 }).value; | ||
res.property2 = traverse(schema.additionalProperties, options, spec, {depth: depth + 1 }).value; | ||
} | ||
return res; | ||
} |
@@ -17,3 +17,3 @@ import { _samplers } from './openapi-sampler'; | ||
export function traverse(schema, options, spec, context) { | ||
// checking circular JS references by checking context | ||
// checking circular JS references by checking context | ||
// because context is passed only when traversing through nested objects happens | ||
@@ -25,2 +25,8 @@ if (context) { | ||
if (context && context.depth > options.maxSampleDepth) { | ||
popSchemaStack(seenSchemasStack, context); | ||
return getResultForCircular(inferType(schema)); | ||
} | ||
if (schema.$ref) { | ||
@@ -41,3 +47,3 @@ if (!spec) { | ||
$refCache[ref] = true; | ||
result = traverse(referenced, options, spec); | ||
result = traverse(referenced, options, spec, context); | ||
$refCache[ref] = false; | ||
@@ -69,2 +75,3 @@ } else { | ||
spec, | ||
context, | ||
); | ||
@@ -78,3 +85,3 @@ } | ||
popSchemaStack(seenSchemasStack, context); | ||
return traverse(schema.oneOf[0], options, spec); | ||
return traverse(schema.oneOf[0], options, spec, context); | ||
} | ||
@@ -84,3 +91,3 @@ | ||
popSchemaStack(seenSchemasStack, context); | ||
return traverse(schema.anyOf[0], options, spec); | ||
return traverse(schema.anyOf[0], options, spec, context); | ||
} | ||
@@ -108,3 +115,3 @@ | ||
} | ||
popSchemaStack(seenSchemasStack, context); | ||
@@ -111,0 +118,0 @@ return { |
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
87429
2457