How to reuse objects in a BluePrint API Schema?

I created an API that provides a resource called "Thumbnail" (/ thumbnails)

{ "name": "toto", "uri": "http://xxx" } 

In the other hand, I have several resources that include this Thumbnail resource (e.g. / articles, / videos ...):

 { "name": "playlist", "thumbnail": { "name": "toto", "uri": "http://xxx" } } 

When I write the diagrams of these web services in the BluePrint markdown, I would like to be able to reuse the diagram I created for the Thumbnail diagram so as not to repeat the code in the diagrams. I have the Trait function trait ( https://github.com/apiaryio/api-blueprint/issues/47 ), but I don’t know if it meets my needs and if it works with aglio and dredd.

Do you know what is best to do in my case?

+6
source share
3 answers

You can use MSON in the Attributes section of the Blueprint API to define reusable objects.

Below are examples here and here .

+8
source

So, I updated my dredd and tested MSON. It is cool and effective. I only have a problem with this md:

 # Data Structures ## Video (object) Definition of a video + id: 11111 (number) - The unique key + description: "my video" (string) - Free text of video + truc: "ffff" (string) # Group VideosTest ## Videos List [/videos] List of videos ### List of videos [GET] + Response 200 (application/json) + Attributes (array[Video]) 

The test will not work, but I do not have truc attributes in my real API, and I have an attribute URL. Therefore, I expected the test to fail. Am I mistaken?

0
source

I will give an example:

My md:

 # Data Structures ## Video (object) Definition of a video + id: 11111 (number, required) - The unique key + description: "my video" (string, required) - Free text of video + truc: "ffff" (string, required) ## A video [/videos/{id}] See a video + Parameters + id (required, string, `a-la-decouverte-des-metiers-projection-du-film`) ... L'id ou le slug de la video ### Select a video [GET] + Response 200 (application/json) + Attributes (Video) 

And my API:

 { "id": "1111", "description": "description of the video", "uri": "http://" } 

The test is fine, but I need a dredd error !!!

0
source

All Articles