Skip to content

Nested inlines not producing correct output #6

@cole-koester

Description

@cole-koester

Consider the following OAS yaml

openapi: 3.0.2
info:
  title: Hello
  version: 1.0.0
components:
  schemas:
    String1:
      type: string
      default: Hello1
      minLength: 22
      $inline: "#/components/schemas/String2"
    Array1:
      type: array
      items: 
        type: string
      nullable: True
    String2:
      type: string
      title: String2000
      default: Hello2
      $inline: '#/components/schemas/String3'
    String3:
      default: Hello3
      description: 'My name is string1.raml'
      $inline: '#/components/schemas/String4'
    String4:
      default: Hello4
      enum: 
      - Hello
      - World
      - Why
paths:
  /pets:
    get:
      description: Returns all pets from the system that the user has access to
      responses:
        '200':
          description: A list of pets.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/String1'
  /cats2:
    get:
      description: Returns all pets from the system that the user has access to
      responses:
        '200':
          description: A list of pets.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/String2'
  /cats3:
    get:
      description: Returns all pets from the system that the user has access to
      responses:
        '200':
          description: A list of pets.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/String3'
  /cats4:
    get:
      description: Returns all pets from the system that the user has access to
      responses:
        '200':
          description: A list of pets.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/String4'

When ran with the preprocessor, here is the output.

{
  "components": {
    "schemas": {
      "String1": {
        "$inline": "#/components/schemas/String3",
        "default": "Hello1",
        "minLength": 22,
        "title": "String2000",
        "type": "string"
      },
      "String2": {
        "default": "Hello2",
        "description": "My name is string1.raml",
        "enum": [
          "Hello",
          "World",
          "Why"
        ],
        "title": "String2000",
        "type": "string"
      },
      "String3": {
        "default": "Hello3",
        "description": "My name is string1.raml",
        "enum": [
          "Hello",
          "World",
          "Why"
        ]
      },
      "String4": {
        "default": "Hello4",
        "enum": [
          "Hello",
          "World",
          "Why"
        ]
      }
    }
  },
  "info": {
    "title": "Hello",
    "version": "1.0.0"
  },
  "openapi": "3.0.2",
  "paths": {
    "/cats2": {
      "get": {
        "description": "Returns all pets from the system that the user has access to",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/String2"
                }
              }
            },
            "description": "A list of pets."
          }
        }
      }
    },
    "/cats3": {
      "get": {
        "description": "Returns all pets from the system that the user has access to",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/String3"
                }
              }
            },
            "description": "A list of pets."
          }
        }
      }
    },
    "/cats4": {
      "get": {
        "description": "Returns all pets from the system that the user has access to",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/String4"
                }
              }
            },
            "description": "A list of pets."
          }
        }
      }
    },
    "/pets": {
      "get": {
        "description": "Returns all pets from the system that the user has access to",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/String1"
                }
              }
            },
            "description": "A list of pets."
          }
        }
      }
    }
  }
}

Notice that in the schema with name String1, the inline reference to String3 was not resolved. This is curious, because it seemed to work appropriately for String2. Perhaps your code only handles nested inlines when not on the first layer?

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