Skip to content

Support/standardize semantic linking of input parameters with their output objects #728

@KiaraGrouwstra

Description

@KiaraGrouwstra

PR 654 enabled using schema (and therefore $ref) in non-body parameters, allowing one to $reference 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 the Person definition's id property also $refing 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 a User 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 $refs, 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions