Skip to content

Question: Is there hints for validator how to validate $ref? #1558

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

Closed
KES777 opened this issue Apr 23, 2018 · 3 comments
Closed

Question: Is there hints for validator how to validate $ref? #1558

KES777 opened this issue Apr 23, 2018 · 3 comments

Comments

@KES777
Copy link

KES777 commented Apr 23, 2018

I am trying to implement openapi validator. I am using Tim Burks schema

In my schema I have next definition:

paths:
  /test:
    post:
      parameters:
        - $ref: '#/components/schemas/Test'

OpenAPI schema defines that paramters maybe parameter definition or reference

"parameters": {
  "type": "array",
  "items": {
    "$ref": "#/definitions/parameterOrReference"
  },
  "uniqueItems": true
},
...
"parameterOrReference": {
  "oneOf": [
    {
      "$ref": "#/definitions/parameter"
    },
    {
      "$ref": "#/definitions/reference"
    }
  ]
},

In my schema I use reference and schema is validated. But it should not, because it refer to wrong resource type: schemas but should refer to parameter

In my validator implementation I may hardcode this check: after ref resolution it should refer to parameter.

Is there a way to provide some hints to validator about type for referenced object?

  "oneOf": [
    {
      "$ref": "#/definitions/parameter"
    },
    {
      "$ref": "#/definitions/reference"
      "$type": "#/definitions/parameter"
    }
  ]

Here $type will provide hint that after resolution the schema should be validated against "#/definitions/parameter" schema. Would it be useful to provide such hints?

@KES777
Copy link
Author

KES777 commented Apr 23, 2018

Or maybe this variant?

  "oneOf": [
    {
      "$ref": "#/definitions/parameter"
    },
    {
      "allOf": [
        {
          "$ref": "#/definitions/parameter"
        },
        {
          "$ref": "#/definitions/reference"
        },
      ]
    }
  ]

@handrews
Copy link
Member

handrews commented May 1, 2018

JSON Schema does not have a feature for validating the $ref target.

There is a proposal for such a feature at json-schema-org/json-schema-spec#141 but it's somewhat controversial and unlikely to be considered before draft-09 (the JSON Schema project is currently working on draft-08, and OpenAPI is using draft-04).

@handrews
Copy link
Member

Since OAS 3.1 is adopting the most recent JSON Schema draft, and this more of a JSON Schema thing, I think this is better tracked at json-schema-org/json-schema-spec#141

Additionally, the question of requiring (rather than validating) that $refs point to #/components/ is tracked at #2084

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