question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid schema causes "should have required property '$ref'" error

See original GitHub issue

Describe the bug When an OpenAPI v3 Response Object contains a schema which has invalid schemas, an error is thrown saying: should have a required $ref property.

This is probably coming from better-ajv-errors, which is deduping errors which are saying “should be a valid sub schema, or should be a $ref” and its just showing the $ref bit.

To Reproduce

  1. Given this OpenAPI document
openapi: 3.0.1
info:
  title: Example $ref error
  version: 1.0.0
paths:
  /user:
    get:
      operationId: getUser
      responses:
        "200":
          description: An Example
          content:
            application/json:
              schema:
                type: object
                properties:
                  user_id: 12345
  1. Run this CLI command spectral lint openapi.yml

  2. See error

Expected behavior

Show a more appropriate validation error. In this instance, other validators return this error:

Structural error at paths./user.get.responses.200.content.application/json.schema.properties.user_id should be object

Environment:

  • Library version: 4.0.1
  • OS: Mac OS 10.14.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:19
  • Comments:24 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
moltarcommented, Dec 20, 2019

This also happens for path params:

  '/modules/{module_id}/sections':
    parameters:
      - type: string
        name: module_id
        in: path
        required: true
        schema:
          type: string
        description: Module ID
    get:
/paths//modules/{module_id}/sections/parameters/0 should have required property '$ref'
4reactions
philsturgeoncommented, Mar 23, 2020

We’ve not forgotten about this issue. We are solving problems a few levels down, with supporting multiple JSON Schema and OpenAPI dialects and vocabularies, which will get us to reevaluate some of the dependencies we’ve built features like schema-based validation on top of. If we’re continuing to use schema-based validation it’ll likely be switching to DJV, and we need to work on some functionality there to make it support better errors. Otherwise maybe Sway, but we’ll have to see what happens as this work progresses.

For now invalid schema messages are a bit funky and I’m sorry about that. We’ll get there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI 3: Missing property "$ref" - Stack Overflow
It works pretty well until today - suddenly my document is filled with errors on "properties" within all schema declarations. The error goes:...
Read more >
Invalid schema causes "should have required property '$ref'" error
When an OpenAPI v3 Response Object contains a schema which has invalid schemas, an error is thrown saying: should have a required $ref...
Read more >
Using $ref - Swagger
OAS 3 This guide is for OpenAPI 3.0. Using $ref. When you document an API, it is common to have some features which...
Read more >
Schema validation reference for object types
The schema of the object type defines properties such as type , title , description , and properties at an incorrect level.
Read more >
Common Problems Found in RAML 1.0 API Specifications
#%RAML 1.0 title: Incorrect API with schema and schemas schemas: User: type: ... To resolve the problem, you would need to use a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found