-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
PR 654 enabled using schema
(and therefore $ref
) in non-body parameters, allowing one to $ref
erence definitions to allow sharing them between input parameters and existing definitions for response objects, preventing duplication, as suggested in #301 by @MrTrick and @jasonh-n-austin.
Some ways to do that:
- @MrTrick in Standardize Parameter Models #301 suggested
"schema": { "$ref": "#/definitions/person_id" }
, with thePerson
definition'sid
property also$ref
ing that. - idea 2:
"schema": { "$ref": "#/definitions/Person/properties/id" }
. Clear, but verbose. - 3: have the
person_id
definition itself be a reference to#/definitions/Person/properties/id
so it could function as a shorthand to$ref
to.
I think this in itself is great, and should be encouraged to those upgrading.
And I think especially the clarity of idea 2 would enable an interesting extension: allowing one to semantically link input parameters to such object fields, to allow tools to recognize API endpoint input/output properties as related.
So I'd like to discuss how tooling vendors could reliably (without standardization of $ref
usage) find semantic links between:
- references to definitions in response objects and the definitions they refer to ("this response includes a reference to the
User
definition") - references to definition (fields) in input parameters, and which field of which definition they refer to ("this input parameter would be the
id
field of aUser
instance")
... with the intent of using the above information so as to suggest input information of one API endpoint could be provided by the output of another.
If one considers $ref
purely as a pointer to be resolved, then the above ideas (even 2) contain one piece of information: anything contained at the path it resolves to.
However, this proposed semantic linking essentially requires a bit more information. Note that after resolving $ref
s, this information goes lost:
- "the input parameter correlates to a property of the object at
#/definitions/Person
" - "the input parameter to the property of that structure is at its sub-path
./properties/id
" - ideally: "the structure it is part of should probably be referred to as
Person
". Note Swagger Editor solves this by injecting these titles into the definitions using their keys, which seems like a fair approach.
I'd then wonder if Swagger Editor had solved point 1 as well, so as to relate response objects to their used definitions, which would obviously be similar. From what I can see though, it didn't. (Swagger Editor shows Product
and its fields in the Uber /products
response, but this is a resolved link, rather than also still being aware of the Product
definition it took the fields from.)
Thoughts?