Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested inlines not producing correct output #6

Closed
cole-koester opened this issue Jan 30, 2020 · 1 comment
Closed

Nested inlines not producing correct output #6

cole-koester opened this issue Jan 30, 2020 · 1 comment

Comments

@cole-koester
Copy link

cole-koester commented Jan 30, 2020

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?

@dolmen
Copy link
Member

dolmen commented Dec 11, 2020

Inlining just resolves nodes in place. Without processing anything. Which means once a node is inlined, it will affect how the rest of the document is processed.

So you're right. Deep inlining is not supported.

However, $merge supports deep merging. So not implementing deep inlining is by design: we don't need two tools that would do the same thing (the only difference is how deep overrides are specified).

So the workaround here is to replace all your uses of $inline with $merge because deep merging is safely handled.

@dolmen dolmen closed this as completed Dec 11, 2020
dolmen added a commit that referenced this issue Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants