Skip to content

Conversation

erunion
Copy link
Member

@erunion erunion commented Oct 6, 2021

🧰 What's being changed?

This resolves a problem in our handling of API definitions with a circular reference where instead of not leaving them alone, we were dereferencing them. This was causing us to end up with [Circular] JS references that couldn't be stringified into the API definition cache, resulting in a hard crash of api.

Fixes #313

🧬 Testing

See the test I added to cache.test.js.

You can also test this with the definition @josei provided in #313:

const sdk = require('./src')('@codat/v1.1.0#1mld74kq6wk0s1');

sdk
  .ListCompanies()
  .then(res => res.json())
  .then(res => {
    console.log(res);
  })
  .catch(err => {
    console.log(err)
  });

You should see a Response dump with a 401 status code instead of:

RangeError: Maximum call stack size exceeded
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:54:16)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/Users/erunion/code/readmeio/api/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)

Note: If running the above code from within packages/api you may ned to clear your definition cache between these two manual tests -- you can do this with rm -rf node_modules/.cache.

@erunion erunion added area:core Issues related to `core`, which is the package that powers the SDKs at runtime bug Something isn't working labels Oct 6, 2021
@erunion erunion requested review from Dashron and julshotal October 6, 2021 18:10
@erunion erunion changed the title fix: issues with circular references being dereferenced and unable to… fix: issues with circular references crashing the sdk Oct 6, 2021
@erunion erunion changed the title fix: issues with circular references crashing the sdk fix: circular references crashing the sdk Oct 6, 2021
@erunion erunion merged commit 5c68896 into main Oct 8, 2021
@erunion erunion deleted the fix/circular-crashes branch October 8, 2021 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Issues related to `core`, which is the package that powers the SDKs at runtime bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crashes with circular references

1 participant