OAI / OAI/OpenAPI-Specification

Add support for templatedRef in Reference Object

Open
#2,453 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
31.2k
Forks
9.2k
Avg merge
6h 37m
Merged PRs (30d)
27

Description

Proposing to add support for "$templatedRef" to Reference Objects supporting templated references, allowing referencing dynamic schemas that could be retrieved by substituting the template variables by the selected value for earlier path parameters
so that later path parameters can be defined differently based on earlier path parameters.

Example:

  "parameters" :
   {
      "collection-styleId" :
      {
         "name" : "styleId",
         "schema" :
         {
            "$templatedRef" : "./api/collections-styles/{collectionId}"`
         }         
      }
   }

As it was initially suggested that this would require to first extend JSON schema, an initial discussion took place in https://github.com/json-schema-org/json-schema-vocabularies/issues/36 . However reading on https://swagger.io/specification/ that the Reference Object is defined by the JSON Reference, rather than by JSON Schema, it seems that this could rather simply be extended with$templatedRef, following https://tools.ietf.org/html/rfc6570 (or a simpler subset of it).

The {collectionId} template would be replaced by a selected value like collection1.
(e.g. in this example, this "$templatedRef" is used to define the valid values for {styleId} in a path /collections/{collectionId}/styles/{styleId}).

The {collectionId} would have previously been validated against another potentially dynamic list like "$ref" : "./api/collections".

./api/collections would return something like:

{
   "type" : "string",
   "enum" : [
      "collection1",
      "collection2",
      "collection3"
   ]
}

and ./api/collection-styles/collection1 would return something like

{
   "type" : "string",
   "enum" : [
      "style234",
      "style235",
      "style236"
   ]
}

while ./api/collection-styles/collection2 would return something like

{
   "type" : "string",
   "enum" : [
      "style454",
      "style455",
      "style456"
   ]
}

The context being that available/compatibles styles depend on the selected collection.

Such a capability would allow to define much more interoperable APIs, where the specifics of a particular instance / deployment would be left to the templated references. In turn this would allow to automatically generate clients from an API definition that will work with multiple instances of the same templatable API, therefore extending the usability of clients automatically generated from OpenAPI definitions beyond on-the-fly client generation, more suitable for compiled programming languages.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Reference Object definition, the JSON Reference material, RFC 6570, and the linked JSON Schema vocabularies discussion. The work is done when the semantics and scope of $templatedRef are agreed and specified clearly enough to support the collection and style examples.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.