Skip to content

Commit 530beed

Browse files
fix(Parse): Solve remote and circular references
Swagger-parser resolves circular references with Object references. PathsParser does not handle this case and will result in an infinite loop. fix(ajv-openapi)!: remove draft-04 support To solve an error importing AJV when OpenAPI Mocker is used as API from another application, that is using higher versions of AJV Error: Cannot find module 'ajv/lib/refs/json-schema-draft-04.json' Require stack: [private-path]/[app-using-open-api-mocker-with-higher-ajv-version]/node_modules/ajv-openapi/index.js [private-path]/[app-using-open-api-mocker-with-higher-ajv-version]/node_modules/open-api-mocker/lib/schema-validator/index.js [private-path]/[app-using-open-api-mocker-with-higher-ajv-version]/node_modules/open-api-mocker/lib/paths/path.js [private-path]/[app-using-open-api-mocker-with-higher-ajv-version]/node_modules/open-api-mocker/lib/paths/parser.js [private-path]/[app-using-open-api-mocker-with-higher-ajv-version]/node_modules/open-api-mocker/lib/paths/index.js [private-path]/[app-using-open-api-mocker-with-higher-ajv-version]/node_modules/open-api-mocker/lib/open-api-mocker.js
1 parent fe43877 commit 530beed

File tree

4 files changed

+246
-415
lines changed

4 files changed

+246
-415
lines changed

lib/open-api-mocker.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
const jsonRefs = require('json-refs');
3+
const SwaggerParser = require('@apidevtools/swagger-parser');
44

5+
const { replaceCircularObject } = require('replace-circular-object');
56
const { Parser: OpenApiParser } = require('./openapi');
67
const { Parser: ServersParser } = require('./servers');
78
const { Parser: PathsParser } = require('./paths');
@@ -41,16 +42,16 @@ class OpenApiMocker {
4142
this.schema = await this.schema;
4243

4344
try {
44-
const parsedSchemas = await jsonRefs.resolveRefs(this.schema);
45-
46-
this.schema = parsedSchemas.resolved;
45+
this.schema = await SwaggerParser.validate(this.schema);
4746

4847
const openApiParser = new OpenApiParser();
4948
const openapi = openApiParser.parse(this.schema);
5049

5150
const serversParser = new ServersParser();
5251
const servers = serversParser.parse(this.schema);
5352

53+
this.schema = replaceCircularObject(this.schema);
54+
5455
const pathsParser = new PathsParser();
5556
const paths = pathsParser.parse(this.schema);
5657

lib/schema-validator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ajvOptions = {
1313
};
1414

1515
const openApiOptions = {
16-
useDraft04: true
16+
useDraft04: false
1717
};
1818

1919
const ajv = openApi(

0 commit comments

Comments
 (0)