Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Looking for non-trivial example of high-level AST usage #818

Open
MikeTaylor opened this issue May 17, 2018 · 3 comments
Open

Looking for non-trivial example of high-level AST usage #818

MikeTaylor opened this issue May 17, 2018 · 3 comments

Comments

@MikeTaylor
Copy link

I'm trying to write a program that walks a high-level AST (generated by raml.parseSync), visiting each resource, and emitting information about the various methods it provides. I am really struggling as The tutorial is spotty in its coverage, and the corresponding sample code exercises only the same parts of the API.

I've not been able to find a simple API reference -- what methods exists for which of the node types -- and have concluded that there isn't one, though please let me know if I'm wrong!

But failing that, can anyone please point me to a non-trivial piece of code that walks a high-level AST, so I can follow it to figure out what methods I need where?

(An example: I guessed that resource.elementsOfKind('methods') would give me the array of methods supported by the resource, but I can't figure out either from docs or from sample code how to ask each of these method objects what the actual HTTP method is (GET, POST, etc.))

@MikeTaylor
Copy link
Author

Can anyone help me with this? @KonstantinSviridov? I am tearing my hair out trying to access the JSON Schema associated with one of my resources. I've used resource.elementsOfKind('methods') to find the methods, picked out the one where m.name() === 'get', and pulled out the type using resource.attr('type') -- but now what? I have an ASTPropImpl but there is no documentation for what methods that supports. By introspection I discovered a list of 68 methods, but none of them pertains to the schema, or seems like a reasonable way to get the schema. And I have no idea where the answers to these questions can be found.

@MikeTaylor
Copy link
Author

I have moved on -- I am now using raml.loadSync instead, and walking the lower-level tree that results. This is much, much easier, as I can see what to do by inspecting the data structure.

So as far as I am concerned, this issue can be closed.

But if you want to people to use the high-level AST going forward, you are definitely going to want to make some dramatic improvements to the documentation, so I'll leave this open for now as a reminder of that, and you're welcome to keep it or close it as you prefer.

@postatum
Copy link
Contributor

Note that raml-js-parser-2 has been deprecated, the new official parser is webapi-parser. Feel free to give it a try and report any issue you may have on that repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants