Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Message-body Attributes #28

Closed
xyzjace opened this issue Sep 29, 2013 · 7 comments
Closed

Nested Message-body Attributes #28

xyzjace opened this issue Sep 29, 2013 · 7 comments

Comments

@xyzjace
Copy link

xyzjace commented Sep 29, 2013

RE: the tweet I sent to @apiblueprint and with @zdne.

We're currently documenting an API which takes POST params of the form:

some_object: {
      a_required_field: {},
      an_optional_field: {},
      perhaps_an_object: {
          a_nested_nested_field: {}
      },
},
some_other_object: {
      a_required_field: {},
      another_required_field: {},
      further_required_field: {},
},
etc..

and we'd love to see the ability to represent this nesting of parameters, or even describing of an object's optional/required parameters in the Blueprint spec.

I envisage it may look something like:

+ Parameters
    + currency (optional, string, `` ) ... A standard currency
    + merchant (required, merchant, `` ) ... A merchant object
        + reference_number (required, string, `` ) ... A merchant's external reference number
        + name (optional, string, ``) ... A merchant's full name
    + product (required, product, `` ) ... A product object
        + code (required, string, `` ) ... A product code

Or perhaps it could take the form:

+ Parameters
    + currency (optional, string, `` ) ... A standard currency
    + merchant (required, merchant, `` ) ... A merchant object
        + Parameters
            + reference_number (required, string, `` ) ... A merchant's external reference number
            + name (optional, string, ``) ... A merchant's full name
    + product (required, product, `` ) ... A product object
        + Parameters
            + code (required, string, `` ) ... A product code

I think the first option would be a lot cleaner.

Are there any plans on implementing something along these lines? Or how would we go about getting that in motion?

Cheers,
Jason

@zdne
Copy link
Contributor

zdne commented Sep 30, 2013

@xyzjace

Personally I really like this idea. I do plan to introduce description of message-body parameters (a.k.a. state or attributes) in the upcoming API Blueprint format - #25.

Originally I was thinking about utilizing some sort "JSON pointer" or just something simple as MongoDB dot notation but this seems really natural and thus might be a better fit for Markdown documents.

It could even be extended for URI parameters. Intriguing.

Let's merge this issue with #25. OK?

Regarding a time frame: I probably won't have time to start working on it before November, so if you could contribute to speed it up it would be great. Both a pull request to the API Blueprint specification & examples as well as to the actual parser are welcome.

@BRMatt
Copy link

BRMatt commented Sep 30, 2013

Sorry if I'm misunderstanding the problem, but couldn't this be solved by using the schema section to document a JSON schema?

@zzen
Copy link
Contributor

zzen commented Sep 30, 2013

@BRMatt probably could - all of parameter descriptions are redundant to Schema. It's a simpler syntax for people who wouldn't go through writing a full-spec schema.

@BRMatt
Copy link

BRMatt commented Sep 30, 2013

@zzen Awesome, thanks for clarifying that.

@zdne
Copy link
Contributor

zdne commented Sep 30, 2013

@BRMatt

You are indeed correct. You can achieve similar, if not all, of this by using a JSON Schema.

However while following should be roughly equivalent:

Body:

+ model (application/json)
    + body

         ```
         { "message": "Hello World" }
         ```

Schema:

+ model (application/json)
    + schema

        ```
        {
            "type":"object",
            "$schema": "http://json-schema.org/draft-03/schema",
            "id": "http://jsonschema.net",
            "required":false,
            "properties":{
                "message": {
                    "type":"string",
                    "id": "http://jsonschema.net/message",
                    "required":false
                }
            }
        }
        ```

Attributes:

+ model
    + Parameters
        + message (string, `Hello World`)

The parametric approach has arguably two huge benefits:

  1. It is somewhat more natural to write and read

    While almost every API is now utilizing the JSON media type not everybody has embraced the JSON Schema. And even if you are using the JSON schema you might find it easier to use Markdown for key description from within Markdown document than inside a JSON (description) field.

  2. It is agnostic to a media type.

    Being agnostic to media type opens a whole new world of possibilities. For example one can genereate XML, JSON or even a CSV from just one model definition. Or go even beyond and utilize referencing and user-provided tokens etc.

@zdne zdne mentioned this issue Oct 2, 2013
This was referenced Dec 16, 2013
@zdne
Copy link
Contributor

zdne commented Jan 31, 2014

Note: I have renamed this issue from Nested Parameters to distinguish between URI (template) parameters and entity body properties.

@zdne zdne added the feature label Apr 3, 2014
@zdne zdne assigned zdne and unassigned zdne Jul 2, 2014
@zdne
Copy link
Contributor

zdne commented Oct 29, 2014

To be addressed with #25

@zdne zdne closed this as completed Oct 29, 2014
@zdne zdne added the Duplicate label Oct 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants