Skip to content

Commit 25198e8

Browse files
authored
fix: handle circular references (#9)
* fix: use clone instead of JSON * add test
1 parent c0fdf4e commit 25198e8

File tree

4 files changed

+1060
-116
lines changed

4 files changed

+1060
-116
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var deepEqual = require('deep-equal');
22
var convert = require('./lib/convert');
3+
var clone = require('clone');
34

45
module.exports = openapiSchemaToJsonSchema;
56
module.exports.fromSchema = openapiSchemaToJsonSchema;
@@ -9,7 +10,7 @@ function openapiSchemaToJsonSchema(schema, options) {
910
options = resolveOptions(options);
1011

1112
if (options.cloneSchema) {
12-
schema = JSON.parse(JSON.stringify(schema));
13+
schema = clone(schema);
1314
}
1415

1516
var jsonSchema = convert.fromSchema(schema, options);
@@ -20,7 +21,7 @@ function openapiParameterToJsonSchema(parameter, options) {
2021
options = resolveOptions(options);
2122

2223
if (options.cloneSchema) {
23-
parameter = JSON.parse(JSON.stringify(parameter));
24+
parameter = clone(parameter);
2425
}
2526

2627
var jsonSchema = convert.fromParameter(parameter, options);
@@ -62,9 +63,9 @@ function resolveOptions(options) {
6263
}
6364

6465
function patternPropertiesHandler(schema) {
65-
var pattern;
66-
var patternsObj = schema.patternProperties;
67-
var additProps = schema.additionalProperties;
66+
var pattern;
67+
var patternsObj = schema.patternProperties;
68+
var additProps = schema.additionalProperties;
6869

6970
if (typeof additProps !== 'object') {
7071
return schema;
@@ -81,8 +82,8 @@ function patternPropertiesHandler(schema) {
8182
}
8283

8384
function resolveNotSupported(notSupported, toRetain) {
84-
var i = 0;
85-
var index;
85+
var i = 0;
86+
var index;
8687

8788
for (i; i < toRetain.length; i++) {
8889
index = notSupported.indexOf(toRetain[i]);

0 commit comments

Comments
 (0)