Open tylerlong opened 9 years ago
Hey @tylerlong – at the moment MSON parser is part of the API Blueprint parser – Drafter the simplest MSON document in API Blueprint would look like:
# Data Structures
## My Object
- name: john
(e.g. you need to start with # Data Structures
to before defining your MSON types)
@zdne we do a lot data-driven documentation around our APIs in addition to the apiary reference, and I could see some real uses for a MSON2JSON parser...just sayin...:)
@rcrooks we do have an OSS tool that does it but it is not wrapped in a CLI interface together with MSON parser just yet...
TODO: Update this thread once C++ Drafter with refract + MSON rendering is ready.
I'm interested as well
Hey @rcrooks, @jayniz and @tylerlong – I just want to give you a head up – the API Blueprint parser that can parse MSON (and produces JSON) out of it is now available:
Or you can play with the protagonist directly in Atom – https://twitter.com/zdne/status/647325114393079808
Thanks for the heads up Z - I was already using drafter to get the AST as json, but I was looking to transform it into json schema.
@jayniz it is now offering transformation to JSON, JSON schema coming soon™
@zdne any way to convert into JSON as the examples in https://github.com/apiaryio/mson/blob/master/README.md do it?
MSON
- id: 1
- name: A green door
- price: 12.50
- tags: home, green
JSON
{
"id": "1",
"name": "A green door",
"price": "12.50",
"tags": [ "home", "green" ]
}
@hobofan at this moment it would be a little bit "hacky"
Minimal blueprint would be something like:
# Data Structures
## My Object
- id: 1
- name: A green door
- price: 12.50
- tags: home, green
but you have to add something to render it as application JSON eg.
# GET /a
- response 200 (application/json)
- attributes (My Object)
And then run it through blueprint parser (drafter / protagonist)
So you will end up with:
@hobofan all the main pieces are there but there is no dedicated tool to make turn an MSON document into (multiple?) JSONs – I guess not enough demand at this time. Besides how it would work if the MSON document would have many data structures in it? Would it spit multiple JSONs?
@hobofan https://github.com/hobofan all the main pieces are there but there is no dedicated tool to make turn an MSON document into (multiple?) JSONs – I guess not enough demand at this time. Besides how it would work if the MSON document would have many data structures in it? Would it spit multiple JSONs?
We currently put each data structure from MSON into the
definitions
of the schema, and then set the properties of the schema itself to something like{properties: { "myType": { "$ref": "#/definitions/myType"}}
so when you would check an objectfoo
againstmyType
in that schema, you'd need to wrap it like this{"myType": foo}
.
As for the MSON to json schema - until a proper tool is released we're using drafter to parse the minimal MSON you mentioned into a refract ast and then manually transform this onto a json schema as described above.
What I meant to say is: @zdne yes yes, there is demand for MSON->Json schema :)
We open sourced the gem we made to convert MSON to JSON Schema. See this comment in issue #41
For what it's worth: I was playing today with Tonic and put together a simple (and ugly!) notebook to get JSON and JSON Schema from an MSON document: https://tonicdev.com/zdne/mson-renderer
Next step: Add an endpoint to it
Any parsers for mson?