-
Notifications
You must be signed in to change notification settings - Fork 56
Drafter - snowcrash parser harness #57
Comments
@ecordell And it won't work, because you want the Schema to be in human-readable form with indentation and prettified - not one-liner, right? I think this will bring much much much more complexity to Snow Crash, than we need right now. Probably other tools can handle Schema, and its validation of example Body. E.g. https://github.com/Baggz/Amanda is a great tool for that. |
Personally, this is functionality that I want in Dredd. Dredd generates API tests from a blueprint file. The argument for putting it in Gavel would be that Gavel already has the ability to check a json object against a schema, so it should be fairly easy to add. But there are some good arguments for putting it in Protagonist (and perhaps even Snowcrash) as well:
And against:
Anyway...maybe Gavel is the best place for this. But I think it's a useful thing to add somewhere in the toolchain, yes? |
While I believe this might be super handy I currently pivot Snow Crash as media-type independent. For Snow Crash an asset is an opaque structure. Which is also one of the reasons I am hesitating with the possibility to reference models inside an asset #33 Also note that I still believe that it should be perfectly OK to write blueprints with partially or completely undefined assets:
Which comes really handy when you are making sketches of your API. Now with that being said I do not want to neglect on the benefits of having the checks there at a compile time. While this one particular request might be covered in Gavel I am playing with the idea of building whole Snow Crash compiler infrastructure, or harness if you will. That will basically take care of task like Modularity, Data Dictionaries, Embedded Assets and perhaps this one as well. This infrastructure could be possible written in a scripting language using Snow Crash through a binding. Also note, that while I do not have the control over it, I would suggest bindings not to add functionality to over the Snow Crash except for what is needed to accommodate given's language habits. |
I've been thinking more about this. First, I think you make really good points and this functionality shouldn't really be a part of snowcrash (didn't really think it should be, just thought posting here would help suggest where it should go). But more than that, I've been thinking this sort of thing deserves its own separate tool.
There are a few things that I've come across in managing a fairly large API that are starting to seem more necessary than simply "nice to have":
I see all of these as related structural and stylistic checks. They don't really seem to fit into the Snowcrash -> Protagonist -> Gavel -> Dredd toolchain (or any equivalent toolchain in some other language). I was thinking a single tool could handle all of these tasks (perhaps). Or maybe two tools, one to handle the structural issues and one to handle the stylistic/data integrity issues. Consider this file structure: blueprint.md //generated dynamically
blueprint.config
/parts
intro.md
users.md
posts.md
/dictionaries
user.json
user.schema.json
userCollection.json The tool would:
It should be pretty clear how to split this into a tool that handles step 1 and a tool that handles 2-6. I should add that all of this should be configurable in some way, so that, for example, if you want example json responses that are invalid, you don't have to have them pass a validation. Does this in any way line up with your thoughts? Or did you have something completely different in mind? Edit: thinking about a tool workflow for something like this. Let's tentatively call this tool drafter (because a drafter make blueprints!)
|
Hat tip Sir! Including the In regards of the API Blueprint linter – I am a little bit confused here. Are you calling for a tool that validates a blueprint? However note that a such a tool AST media-type to blueprint is coming very soon for various other reasons. I do plan to provide it in the course of next month as a ruby gem. Another part of your harness I am not sure about is the purpose of the config file? Is this to drive the linting during the build phase, e.g. to decide whether or not to validate some assets? Would you care to provide a draft of this file? Also are you OK to rename this Issue to something like "Drafter – Snow Crash parser harness" or something more descriptive to where we are now? Great stuff! Thanks! |
Thanks! Glad we're on the same page.
Maybe linter is a bad name for it. I was just thinking about a tool that could take a (valid) blueprint file as an input that had several of different styles in it (maybe some resources are nested like the Gist Fox example, and others write out the URI for every single request) and outputs a blueprint file with a unified style and spacing. I think that part of the tool is the least important, but if it's still confusing I can try to explain with examples. The config file would just be to control how that output looks. Maybe it would be better to just have a dumber Drafter BuildFor me, right now, the most important and pressing need is a tool to do what I listed as step 1: combining multiple files into one blueprint. I've been mulling this over a bit more, and I think I can outline a solution that solves this problem, while keeping in mind these other issues. This is probably best described through an example. Consider the following file structure: blueprint.md //output
blueprint.skeleton.md //input
gists/gist.json
gists/gistCollection.json blueprint.skeleton.md
gists/gist.json
gists/gistCollection.json
Then, you would run this command:
This would simply scan the document for Or, perhaps the syntax would be something like The output: blueprint.md
That would be fairly simple to achieve (unless I'm missing something, that could be handled with some simple regex). This has a few advantages over my previous proposal:
Thoughts? (sorry this is so lengthy!) |
Thanks for explanation on the linter. So essentially it would be a pretty-printer + validator, same as jsonlint.com is.
Makes sense. Since part 1 is already done ( Now to the juicy part - Drafter. First my thoughts about referencing external assets: There is already some initial concept here apiaryio/api-blueprint#20 I would add & build on it. So the "template" blueprint is actually a real API Blueprint. I would propose following: Referencing an external asset:
Embedding an external asset:
(this is Markdown syntax for embedding pictures) In the first case (referencing) the parser would just add the reference to a (new) href key in AST. In the later, the parser harness would fetch & embed the asset from the path or URL into the AST. Does this makes sense? Note: I still want to comment on the command line arguments and the config file, but I will do it in another post for the sake of clarity |
Also what we are missing here is the part when you break up a blueprint into multiple files. I can see two approaches here:
What do you think? |
Wouldn't this prevent someone from embedding images in their documentation? Perhaps
|
It shouldn't the drafter should know when to replace it and when not from the context. But
This is a fair point. So apparently we must come with something as Thanks! |
Revisiting API Blueprint Plans & Issues) I have stumbled upon on yet still undecided Modularity issue – apiaryio/api-blueprint#8 – breaking a blueprint into multiple file. Please feel free to add any thoughts on this here or directly at apiaryio/api-blueprint#8 |
We have kicked-off the Drafter project. Initially it will provide expansion of MSON data structures (types) and rendering of representations out of it. Support for additional features is in the pipeline. If needed please continue with this discussion at apiaryio/drafter#31 |
@zdne Looks great! Can't wait to see what happens. If I manage to find some time I'd love to contribute. |
Thanks @ecordell ! At the moment it is just a simple wrapper but the real juice is coming soon! |
In the interest of keeping documentation up-to-date, it seems you would want to get warnings when your example Body doesn't fit your Schema.
Maybe this issue should be for a different project...it's definitely something snowcrash could handle, but perhaps it shouldn't have a dependency on json schema?
The text was updated successfully, but these errors were encountered: