Reputation: 43491
I am defining my response as per:
responses:
200:
description: 'An authProvider object'
schema:
type: 'array'
items:
$ref: '#/definitions/AuthProvider'
Is it possible for me to directly attach another field or 2 in the response? I would like to add something that I don't want to put into AuthProvider
Upvotes: 1
Views: 628
Reputation: 14800
Whenever $ref
is used, it's basically using JSON Reference. By definition (see linked spec), anything defined within the same object as the reference itself is ignored. As such, it is not possible to directly add additional properties alongside with the $ref
definition.
That said, you can use composition to 'combine' two objects into one. This is done using the allOf
JSON Schema directive. A simple example for such a definition would look like this:
allOf:
-
$ref: "..."
-
properties:
property1:
type: "string"
property2:
type: "boolean"
Note 1: The various Swagger tools out there may not fully support composition at the moment. Note 2: As always, it's normally better to externalize the definition (even if used only once) rather than being defined inline.
Upvotes: 6