-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add callback accessors into operation class #515
Conversation
Tests look fine, what is |
The callback examples are going to be used to show a callback tab in the response component - this is the ticket that references it |
src/operation.js
Outdated
|
||
const callback = this.schema.callbacks[identifier] ? this.schema.callbacks[identifier][expression] : false; | ||
if (!callback || !callback[method]) return false; | ||
return new Operation(this.oas, expression, method, callback[method]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to make this return a Callback
instance? You can copy these couple lines from my webhook PR:
- https://github.com/readmeio/oas/pull/516/files#diff-f952ef6706aee84d0da82da3a6391a50394558b80d0ac7e4d437bcac22bb51aaR384-R387
- https://github.com/readmeio/oas/pull/516/files#diff-bfe9874d239014961b1ae4e89875a6155667db834a410aaaa2ebe3cf89820556R634
Should also update your tests to assert that this returns instances of that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to disable an eslint rule but it should use a fresh Callback class now 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it's ok to disable that multiple-class-per-file rule because it's not worth the trouble of having a 2 line file just to export a child class
That link cleared up callback examples for me. Thanks! 👍 after Jon's comment is addressed! |
🧰 Changes
Adds support for RM-2271
The nested loops and array concatenation in this are super gross - they exist mostly due to callbacks being able to have multiple expressions and each expression being a
Path Item Object
which supports multiple methods and needing to concat these returned arrays to prevent nested arrays (we want just one array of multiple objects)The operation class now has the following support for callbacks:
hasCallbacks()
returns a boolean based on whether or not the schema has any callbacksgetCallback(identifier, expression, method)
returns anoperation
created from a specific callback (found via theidentifier
,expression
, andmethod
)getCallbacks()
returns an array ofoperations
created viagetCallback()
for all existing callbacksgetCallbackExamples()
returns an object of theidentifier
,expression
,method
, andexample
(which and array of objects containingstatus
andmediaTypes
fromgetRequestExamples()
) An array is used here instead of just an object in case the response for the example contains multiple status codes🧬 QA & Testing
see tests*
callbacks.json is just the /callbacks route of kitchen-sink right now with an example added + callbacks with multiple expressions and methods for testing
*most of the testing for get-callback-examples is covered by the tests for get-response-examples due to the use of
getResponseExamples()
, but a few tests were duplicated for callbacks just to double check all info is coming back as intended!