Skip to content

OpenAPI 3.1 - contextfull resolution and document boundaries #1337

@char0n

Description

@char0n

This issue is related to #1336.
root.yml

openapi: "3.1.0"
info:
  version: 1.0.0
  title: Swagger Petstore
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    $ref: "./pets/pets.yml"

pets/pets.yml

get:
  operationId: listPets
  responses:
    "200":
      $ref: "./response.yml"

pets/response.yml

content:
  application/json:
    schema:
      $ref: "./def.yml#/components/schemas/Pet"
  application/yaml:
    schema:
      $ref: "./def3.yml#Pet"

pets/def.yml

components:
  schemas:
    Pet:
      $ref: "./def2.yml#/components/schemas/Pet"

pets/def2.yml

components:
  schemas:
    Pet:
      type: number

pets/def3.yml

$defs:
  Pet:
    $anchor: Pet
    type: number

Resolution

After the root document is resolved, it should look like this:

  {
    "openapi": "3.1.0",
    "info": {
      "title": "Swagger Petstore",
      "version": "1.0.0"
    },
    "paths": {
      "/pets": {
        "get": {
          "operationId": "listPets",
          "responses": {
            "200": {
              "content": {
                "application/json": {
                  "schema": {
                    "type": "number"
                  }
                },
                "application/yaml": {
                  "schema": {
                    "$anchor": "Pet",
                    "type": "number"
                  }
                }
              }
            }
          }
        }
      }
    },
    "servers": [
      {
        "url": "http://petstore.swagger.io/v1"
      }
    ]
  }
Resolution - JSON pointer

When there is JSON Schema reference $ref: "./def.yml#/components/schemas/Pet" which contains JSON Pointer, what we do is we parse the def.yml and evaluate the JSON Pointer on parsed generic ApiDOM. The result of evaluation is then refracted to JSON Schema Element and returned.

Resolution - JSON Schema anchor

When there is JSON Schema anchor $ref: "./def3.yml#Pet" which contains anchor, what we do is we parse the def3.yml and refract it whole to semantic ApiDOM (JSON Schema Element). Then we evaluate the anchor on semantic ApiDOM. The result of evaluation is then returned.


The result of the resolution should be refset of 6 documents:

  • root.yml
  • pets/response.yml
  • pets/def.yml
  • pets/def1.yml
  • pets/def2.yml
  • pets/def3.yml

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions