Skip to content

Commit

Permalink
Merge pull request #25 from criteria-labs/fix-maximum-call-stack-size…
Browse files Browse the repository at this point in the history
…-exceeded

Fix maximum call stack size exceeded
  • Loading branch information
jcmosc authored Apr 25, 2024
2 parents 5027177 + a9eb059 commit e1a5ffd
Show file tree
Hide file tree
Showing 5 changed files with 281,586 additions and 7 deletions.
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/criteria-openapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@criteria/openapi",
"version": "0.9.0",
"version": "0.9.2",
"description": "TypeScript implementation of the OpenAPI specification.",
"keywords": [
"openapi",
Expand Down Expand Up @@ -35,8 +35,9 @@
"clean": "rimraf tsconfig.build.tsbuildinfo ./dist"
},
"dependencies": {
"@criteria/json-schema": "^0.9.0",
"@criteria/json-pointer": "^0.1.1"
"@criteria/json-schema": "^0.9.1",
"@criteria/json-pointer": "^0.1.1",
"toad-uri-js": "^5.0.1"
},
"devDependencies": {
"@types/jest": "^29.2.4",
Expand Down
11 changes: 10 additions & 1 deletion packages/criteria-openapi/src/openapi-index/OpenAPIIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ export class OpenAPIIndex extends DocumentIndex {
this.references.set(reference, info)
})

return chainForEach(foundReferences.values(), (info: ReferenceInfo<Metadata>) => {
// Help prevent Maximum call stack size exceeded errors
const unindexedReferences = [...foundReferences.values()].filter((info) => {
if (this.isURIIndexed(info.resolvedURI)) {
return false
}
const { absoluteURI, fragment } = splitFragment(info.resolvedURI)
return !this.isURIIndexed(absoluteURI)
})

return chainForEach(unindexedReferences.values(), (info: ReferenceInfo<Metadata>) => {
if (this.isURIIndexed(info.resolvedURI)) {
return
}
Expand Down
28 changes: 28 additions & 0 deletions packages/criteria-openapi/test/v3.0/github/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env jest */
import { resolve } from 'path'
import { dereferenceOpenAPI } from '../../../src/v3.0'
import retrieveFromFilesystem from '../../util/retrieveFromFilesystem'
import openAPI from './openapi.json'

describe('GitHub OpenAPI', () => {
describe('dereferenceOpenAPI()', () => {
describe('synchronous', () => {
test('does not result in Maximum call stack size exceeded', () => {
const output = dereferenceOpenAPI(openAPI as any, {
baseURI: resolve(__dirname, 'openapi.json'),
retrieve: retrieveFromFilesystem
}) as any
expect(output).toMatchObject({ openapi: '3.0.3' })
})
})
describe('asynchronous', () => {
test('does not result in Maximum call stack size exceeded', async () => {
const output = (await dereferenceOpenAPI(openAPI as any, {
baseURI: resolve(__dirname, 'openapi.json'),
retrieve: async (uri) => await retrieveFromFilesystem(uri)
})) as any
expect(output).toMatchObject({ openapi: '3.0.3' })
})
})
})
})
Loading

0 comments on commit e1a5ffd

Please sign in to comment.