Invalid schema causes "should have required property '$ref'" error
See original GitHub issueDescribe 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
- 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
-
Run this CLI command
spectral lint openapi.yml
-
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:
- Created 4 years ago
- Reactions:19
- Comments:24 (15 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This also happens for path params:
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.