Skip to content

Commit e1a5ffd

Browse files
authored
Merge pull request #25 from criteria-labs/fix-maximum-call-stack-size-exceeded
Fix maximum call stack size exceeded
2 parents 5027177 + a9eb059 commit e1a5ffd

File tree

5 files changed

+281586
-7
lines changed

5 files changed

+281586
-7
lines changed

package-lock.json

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/criteria-openapi/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@criteria/openapi",
3-
"version": "0.9.0",
3+
"version": "0.9.2",
44
"description": "TypeScript implementation of the OpenAPI specification.",
55
"keywords": [
66
"openapi",
@@ -35,8 +35,9 @@
3535
"clean": "rimraf tsconfig.build.tsbuildinfo ./dist"
3636
},
3737
"dependencies": {
38-
"@criteria/json-schema": "^0.9.0",
39-
"@criteria/json-pointer": "^0.1.1"
38+
"@criteria/json-schema": "^0.9.1",
39+
"@criteria/json-pointer": "^0.1.1",
40+
"toad-uri-js": "^5.0.1"
4041
},
4142
"devDependencies": {
4243
"@types/jest": "^29.2.4",

packages/criteria-openapi/src/openapi-index/OpenAPIIndex.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ export class OpenAPIIndex extends DocumentIndex {
8181
this.references.set(reference, info)
8282
})
8383

84-
return chainForEach(foundReferences.values(), (info: ReferenceInfo<Metadata>) => {
84+
// Help prevent Maximum call stack size exceeded errors
85+
const unindexedReferences = [...foundReferences.values()].filter((info) => {
86+
if (this.isURIIndexed(info.resolvedURI)) {
87+
return false
88+
}
89+
const { absoluteURI, fragment } = splitFragment(info.resolvedURI)
90+
return !this.isURIIndexed(absoluteURI)
91+
})
92+
93+
return chainForEach(unindexedReferences.values(), (info: ReferenceInfo<Metadata>) => {
8594
if (this.isURIIndexed(info.resolvedURI)) {
8695
return
8796
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-env jest */
2+
import { resolve } from 'path'
3+
import { dereferenceOpenAPI } from '../../../src/v3.0'
4+
import retrieveFromFilesystem from '../../util/retrieveFromFilesystem'
5+
import openAPI from './openapi.json'
6+
7+
describe('GitHub OpenAPI', () => {
8+
describe('dereferenceOpenAPI()', () => {
9+
describe('synchronous', () => {
10+
test('does not result in Maximum call stack size exceeded', () => {
11+
const output = dereferenceOpenAPI(openAPI as any, {
12+
baseURI: resolve(__dirname, 'openapi.json'),
13+
retrieve: retrieveFromFilesystem
14+
}) as any
15+
expect(output).toMatchObject({ openapi: '3.0.3' })
16+
})
17+
})
18+
describe('asynchronous', () => {
19+
test('does not result in Maximum call stack size exceeded', async () => {
20+
const output = (await dereferenceOpenAPI(openAPI as any, {
21+
baseURI: resolve(__dirname, 'openapi.json'),
22+
retrieve: async (uri) => await retrieveFromFilesystem(uri)
23+
})) as any
24+
expect(output).toMatchObject({ openapi: '3.0.3' })
25+
})
26+
})
27+
})
28+
})

0 commit comments

Comments
 (0)