Skip to content

Local references not resolved correctly in external files #344

@roee88

Description

@roee88

From https://swagger.io/docs/specification/using-ref/:

Local Reference – $ref: '#/definitions/myElement' # means go to the root of the current document and then find elements definitions and myElement one after one.

However in kin-openapi when the specification includes a Remote Reference to a document with a Local reference, the local references in the document cannot be found.

Example:

ext.json

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "a": {
            "type": "string"
        },
        "b": {
            "type": "object",
            "properties": {
                "name": {
                    "$ref": "#/definitions/a"
                }
            }
        }
    }
}

spec.yaml

openapi: 3.0.1
components:
  schemas:
    Test:
      type: object
      properties:
        test:
          $ref: 'ext.json#/definitions/b'

Loading the spec (package openapi3) raises an error because it can't find definitions when trying to resolve #/definitions/a in ext.json. Code to reproduce is available in https://gist.github.com/roee88/626d93f9e73776c7f1ec3aa59d7db988#file-extref_test-go.

Changing #/definitions/a to ext.json#/definitions/a in the ext.json file bypass the problem but this is not an acceptable solution because often you don't have control of the referenced files (plus I suspect it makes them invalid when used independently but unsure).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions