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

Ability to reference repeated data #236

Closed
foxx opened this issue Jul 22, 2015 · 7 comments
Closed

Ability to reference repeated data #236

foxx opened this issue Jul 22, 2015 · 7 comments

Comments

@foxx
Copy link

foxx commented Jul 22, 2015

Imagine the following scenario;

## Say hello [POST /say/hello]

Say hello to someone

+ Request (application/json)

    + Attributes
        + message (boolean) - Your hello message

    + Body

            {"message": "Japie, start the nederdraad!"}

    + Schema

            {}

+ Response 200 (application/json)
    + Body

            {}
    + Schema

            {}

+ Response 400 (application/json)
    + Body

            {"errors": [
                {"message": "some error", "code": 1},
                {"message": "some error", "code": 1}
            ]}
    + Schema

            {}

Lets assume that 4xx response will always contain the same data structure for all API endpoints. Rather than having to repeat this data structure definition multiple times, it would be useful to define it once in the document and then reference to it. Models do not work for this, because they require that you define a path, which doesn't really make much sense (as a data structure is independent of its resource path, right?).

I've had a read through some other issues which feel related, including #29, #25, #9 and #19, but none of them seem to provide any solution or firm outcome.

Could someone please clarify the correct way of achieving the above goal?

@pksunkara
Copy link
Contributor

I think you are looking for MSON with which you can do the above.

@foxx
Copy link
Author

foxx commented Jul 22, 2015

MSON could potentially help, but I don't want to use MSON in this particular situation :) Although that being said, it's unclear how MSON would have actually helped, so any links would be appreciated

@pksunkara
Copy link
Contributor

I don't know why you do not want to use MSON, but MSON was designed exactly with this use case in mind. Could you explain more?

@kylef
Copy link
Member

kylef commented Jul 22, 2015

@foxx Just to be clear, @pksunkara is proposing you do something like follows. Where you are defining reusable components you can use in multiple different resources/actions.

## Say hello [POST /say/hello]
+ Response 400 (application/json)
    + Attributes (Errors)

## Data Structures
### Errors
+ errors (array[Error])

### Error
+ message: some error
+ code: 1 (number)

Which would get expanded into the following JSON example in Apiary:

screen shot 2015-07-22 at 14 49 21

@foxx
Copy link
Author

foxx commented Jul 22, 2015

Oh interesting, actually yes you're quite right this would solve the issue.

I couldn't see any mentioning of this in the examples or documentation, at least not clearly, did I miss something?

@pksunkara
Copy link
Contributor

There are a few examples in the example folder such as, Attributes, Advanced Attributes and Data Structures

@foxx
Copy link
Author

foxx commented Jul 22, 2015

Thanks for the quick reply and additional info, appreciated

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

3 participants