-
Hi there! I have a question about different types of properties in schemas with Please, see the example below. It seems, there are 3 possible scenarios with different tools I've met:
openapi: 3.0.1
info:
title: example
description: allOf example
version: 0.1.0
servers:
- url: 'https://example.com'
paths:
'/foo':
delete:
responses:
'200':
description: OK
components:
schemas:
Foo:
type: object
properties:
property1:
type: object
Bar:
type: object
properties:
property1:
type: array
items:
type: string
allOf:
- $ref: '#/components/schemas/Foo' I've tried to look for the answer in OpenAPI v3.0.1 Schema Object
Should we validate the object separately against Related: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
It seems I've handled this. I am leaving my findings here. Will be excellent to receive some approval if it is valid. OpenAPI refers JSON Schema which refers JSON.
So I’d say the correct result here is option 2 |
Beta Was this translation helpful? Give feedback.
-
The Schema instance (a value you are validating against a schema) is valid only when it was successfully validated agains all keywords in a schema. Let's say this is a value you are validating against {
"property1": []
} This is how validator will validate the value against your schemas:
As you can see, validation will fail because passed JSON is not valid against the single keyword. Because It's important to note that This repository is mostly about OpenAPI spec. You are welcome to ask questions about JSON Schema in official repository discussions on GitHub 🙂 |
Beta Was this translation helpful? Give feedback.
-
@flaksp Thanks for your explanations! I'd like to clarify
Did you mean here I mostly think that way too, but here I got this one in a different way.
Unfortunately, I'm not familiar with JS. But explanation
Seems valid to me. As I got it should be valid here, because |
Beta Was this translation helpful? Give feedback.
-
This JSON Schema question has been answered, closing. |
Beta Was this translation helpful? Give feedback.
The
Bar
schema is valid. But it won't work as you expect.Schema instance (a value you are validating against a schema) is valid only when it was successfully validated agains all keywords in a schema.
Let's say this is a value you are validating against
Bar
schema:{ "property1": [] }
This is how validator will validate the value against your schemas:
/components/schemas/Bar/type
keyword: is passed value has typeobject
? Yes./components/schemas/Bar/properties
:/components/schemas/Bar/properties/property1/type
keyword: is passed value has typearray
? Yes./components/schemas/Bar/allOf
keyword:/components/schemas/Bar/allOf/0/$ref