API Blueprint Visitor
A Visitor base class that lets you derive your own visitors for manipulating API-Blueprint's AST, so that you can build awesome tools.
Installing
npm install api-blueprint-visitors
Getting Started
Two things are provided in api-blueprint-visitors:
- A Visitor base class
- The
makeASTVisitable
function, that makes Protagonist's AST visitable.
Let's imagine we want to create a script that counts all the Resources, Requests and Responses in a blueprint file.
Our visitor could look something like this:
{ thisresources = 0; thisrequests = 0; thisresponses = 0; } // Each `visit` method is called when the visitor visits the corresponding node. { thisresources++; } { thisrequests++; } { thisresponses++; } // Once all the AST has been traversed, `postVisit` is called. { console; console; console; }
Now, in order to visit the AST, we need to make that AST visitable:
fs;
And that's it! The visitor can visit Group, Resource, Action, Request, Response and Example.
Check the full example here.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
MIT