Hi all,
First, thank you for the great work provided by the Swagger community. I am heavily relying on it to provide API-design support to my customers, as its tooling is rather complete and user-friendly.
I am currently helping a customer to represent a very complex API through a Swagger specification document. I managed to do a lot with existing 2.0 features, including polymorphism/inheritance and resource composition (using $ref). What I am missing though, is an "official" way of indicating that an attribute/parameter actually represents a resource id. This is useful in order to generate diagrams showing resource relationships, for example.
Assume we have a resource such as :
"cat": {
"foodPreferences": {
"favoriteDrink": "milk",
"favoriteFood": "fish"
},
"ownerId": "110e8400-e29b-11d4-a716-446655440000"
}
In this case, attribute "foodPreferences" is an embedded resource of type "FoodPreferences". Attribute "ownerId" is the id of another resource, not embedded here, of type "Owner".
To indicate the link between the "ownerId" attribute and the "Owner" resource, we use the following Swagger-based specification :
"definitions": {
"Dog": {
"allOf": [
{
"type": "object",
"properties": {
"foodPreferences": {
"description": "Embedded resource",
"$ref": "#/definitions/FoodPreferences"
},
"ownerId": {
"description": "Number representing an id (reference) to another resource",
"type": "number",
"x-identifier-for-schema-ref": "#/definitions/Owner"
}
}
}
As you can see we defined a specific "x-identifier-for-schema-ref" specification field (in red) to indicate this particular link.