-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
"value
property should match exactly one schema in oneOf" message with right example
#1482
Comments
I've moved this over to the spectral repository, which is the validator powering this functionality in Studio. |
Hey @GillesTourreau!
{
"oneOf": [
{ "type": "number" },
{ "type": "integer" }
]
} Now, On the other hand, (using fixed doc (option 1)openapi: 3.0.0
info:
title: Test
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
examples:
'Cat example':
value: # <--- "`value` property should match exactly one schema in oneOf" error display.
hunts: true
age: 15
'Dog example':
value: # <--- "`value` property should match exactly one schema in oneOf" error display.
bark: true
breed: Dingo
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer Now, one may ask why both schemas are actually matched. Let's extract one of the schemas. type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd] Now, if you provide such a schema to any validator, these are, more or less, the steps it'll perform.
This means, that as long as all these steps pass, the value is considered value. {
"foo": {} // this is valid!
} To change it, you can either leverage fixed doc option 2openapi: 3.0.0
info:
title: Test
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
examples:
'Cat example':
value: # <--- "`value` property should match exactly one schema in oneOf" error display.
hunts: true
age: 15
'Dog example':
value: # <--- "`value` property should match exactly one schema in oneOf" error display.
bark: true
breed: Dingo
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
additionalProperties: false
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
additionalProperties: false fixed doc option 3openapi: 3.0.0
info:
title: Test
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
examples:
'Cat example':
value: # <--- "`value` property should match exactly one schema in oneOf" error display.
hunts: true
age: 15
'Dog example':
value: # <--- "`value` property should match exactly one schema in oneOf" error display.
bark: true
breed: Dingo
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
required: [bark, breed]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
required: [hunts, age]
Does that make sense? |
I have the following YAML example which I edit on the Stoplight Studio (Windows version)
Two errors are displayed at the line 19 and 23 which explain that the examples are invalid and does not match the
Dog
orCat
schemas.Can you confirm that it is a bug of the Stoplight studio validator ?
The text was updated successfully, but these errors were encountered: