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

Expose information about extended Refs #70

Closed
GabrielCastro opened this issue Jan 31, 2018 · 4 comments
Closed

Expose information about extended Refs #70

GabrielCastro opened this issue Jan 31, 2018 · 4 comments

Comments

@GabrielCastro
Copy link
Contributor

When resolving references it would be useful to know when there is a schema that was an extended ref. Ie.

given the following schema

{
    type: 'object',
    required: ['a'],
    properties: {
        a: {
            $ref: '#/definitions/typeA',
            description: 'a in obj as a'
        },
        b: {
            $ref: '#/definitions/typeA',
            description: 'a in obj as b'
        }
    },
    definitions: {
        typeA: {
            type: 'number',
            description: 'a in defs'
        }
    }
}

it produces the following dereferenced output.

{
    type: 'object',
    required: ['a'],
    properties: {
        a: {
            description: 'a in obj as a',
            type: 'number'
        },
        b: {
            description: 'a in obj as b',
            type: 'number'
        }
    },
    definitions: {
        typeA: {
            type: 'number',
            description: 'a in defs'
        }
    }
}

There is no way for the consumer to know that properties a and b were once the same pointer

@JamesMessinger
Copy link
Member

What would you propose as a solution?

Keep in mind that a and b aren't the same object. They both simply get some of their properties from the same object.

@ErikWittern
Copy link

@Alan-Cha and I are actually interested in the same thing. We would like to keep track of the original references in the resulting dereferenced object.

What if the user could provide an option to retain the original $ref property in addition to the dereferenced value? A consideration with this idea is that the resulting value may trigger additional, superfluous dereferencing in future processing.

Alternatively, what if the user could provide the name of a field to add to a and b that holds the original reference? E.g., if the user states that field to be original-$ref, the resulting data would be:

{
    type: 'object',
    required: ['a'],
    properties: {
        a: {
            description: 'a in obj as a',
            type: 'number',
            original-$ref: '#/definitions/typeA'
        },
        b: {
            description: 'a in obj as b',
            type: 'number',
            original-$ref: '#/definitions/typeA'
        }
    },
    definitions: {
        typeA: {
            type: 'number',
            description: 'a in defs'
        }
    }
}

luma added a commit to luma/json-schema-ref-parser that referenced this issue Sep 14, 2019
When dereferencing this adds a `$originalRef` property
indicating where it was referenced from.

* It only does this for objects, not of strings, numbers and
  other types.
* Some objects will get referenced from multiple places, so
  `$originalRef` is actually an array.

The original idea was proposed here:
  APIDevTools#70
@theogravity
Copy link

theogravity commented Jan 5, 2020

@luma 's commit in his fork seems to be what I'm looking for - is it possible to include that in mainline?

@luma
Copy link

luma commented Jan 27, 2020 via email

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

6 participants