How can I reuse a single example in multiple responses?

27 views
Skip to first unread message

RHo

unread,
Nov 24, 2015, 11:44:49 AM11/24/15
to Swagger
Hi,

I'm trying to use response examples. But I want to avoid repeating the same example multiple times.

I see in the example https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/yaml/api-with-examples.yaml that the same response example is used multiple times.
Instead of pasting it multiple times it would be clearly better to have the example once and then to use $ref to reference that example wherever needed. But I don't know how to get it to work.
Is this possible?

If so, could someone provide an example?

Thanks!

Ron

unread,
Dec 1, 2015, 3:12:36 PM12/1/15
to Swagger
The way you can do it is by defining the whole response under responses and then reference the response itself.
You cannot reference the examples alone.

RH

unread,
Dec 3, 2015, 6:33:29 AM12/3/15
to Swagger
Thanks! This works fine.
Reply all
Reply to author
Forward
0 new messages