API Description Utilities
API Description mixins for Lodash based on the Refract API Description namespace
Usage
This library takes a lodash
instance and adds API Description mixins, which are the functions described below. These functions are usable and chainable just like any other Lodash function. Additionally, all Lodash functions are available here.
It is recommended to use these functions and other Lodash functions when interacting with Refract because you get some safety when chaining and looking for data.
content
Takes a Refract element and returns its content, which MAY be of any JavaScript type.
// Returns an array with the resource element_content element: 'category' content: element: 'resource' content: ;
contentOrValue
Takes any value and checks if it is Refract element. If it is Refract element then returns its content, which MAY be of any JavaScript type. Otherwise returns value itself.
// Returns passed value_; // Returns array with the resource element_;
dataStructures
Takes a Refract element and returns an array of all dataStructure
elements found in the content.
// Returns array including the one dataStructure element in content_;
resources
Takes a Refract element and returns an array of all resource
elements found in the content.
// Returns array including the one resource element in content_;
transitions
Takes a Refract element and returns an array of all transition
elements found in the content.
// Returns array including the one transition element in content_;
copy
Takes a Refract element and returns an array of all copy
elements found in the content.
// Returns array including the one copy element in content_;
httpTransactions
Takes a Refract element and returns an array of all httpTransaction
elements found in the content.
// Returns array including the one httpTransaction element in content_;
httpRequests
Takes a Refract element and returns an array of all httpRequest
elements found in the content.
// Returns array including the one httpRequest element in content_;
httpResponses
Takes a Refract element and returns an array of all httpResponse
elements found in the content.
// Returns array including the one httpResponse element in content_;
messageBodies
Takes a Refract element and returns an array of all messageBody
elements found in the content.
// Returns array including the one messageBody element in content_;
messageBodySchemas
Takes a Refract element and returns an array of all messageBodySchema
elements found in the content.
// Returns array including the one messageBodySchema element in content_;
filterContent
Takes a Refract element and filter condition, gets its content, and filters it.
// Returns array including the one messageBodySchema element in content_;
Installation
npm install lodash-api-description --save
Using the library
If you are using this library in a project of yours, we recommend loading Lodash in its own module, using runInContext
, and adding mixins. Your module would look like:
// utils.jsvar lodash = ; // creates a copy of lodashvar apiDescriptionMixins = ;; // adds API Description mixins moduleexports = lodash;
Then when using this functionality in your project, you can do the following:
// Requiring custom lodash from another filevar lodash = ;
This prevents you from adding mixins to Lodash for entire project.
Development
$ npm install$ npm test
License
MIT (see LICENSE
file)
Apiary Inc. support@apiary.io