Replace or remove discriminator #57
Replies: 6 comments 5 replies
-
There's a new keyword called |
Beta Was this translation helpful? Give feedback.
-
Are there uses of the Further, I have found the description of |
Beta Was this translation helpful? Give feedback.
-
There was also a proposed keyword by @handrews way back in OAI/OpenAPI-Specification#2143 (comment) that merely used a JSON pointer to designate which field to use as the discriminating field, without requiring some kind of duplication of the validation functionnality. {
"selectBy": "0/class",
"oneOf": [
{
"if": {"properties": {"class": {"const": "foo"}}},
"then": {...}
},
{
"if": {"properties": {"class": {"const": "bar"}}},
"then": {...}
},
...
} I do realize that it's very late to bring this up given |
Beta Was this translation helpful? Give feedback.
-
For the benefit of others reading this thread that aren't familiar with json-schema-org/json-schema-spec#1082 (lots of discussion here) and here is the PR that adds the keyword: https://github.com/json-schema-org/json-schema-spec/pull/1143/files |
Beta Was this translation helpful? Give feedback.
-
I think Here's an example: components:
schemas:
Pet:
type: object
discriminator: petType
properties:
name:
type: string
required:
- name
oneOf:
- description: A representation of a cat
type: object
properties:
petType:
type: string
const: "cat"
huntingSkill:
type: string
description: The measured skill for hunting
enum:
- clueless
- lazy
- adventurous
- aggressive
required:
- petType
- huntingSkill
- description: A representation of a dog
type: object
properties:
petType:
type: string
const: "dog"
packSize:
type: integer
format: int32
description: the size of the pack the dog is from
default: 0
minimum: 0
required:
- petType
- packSize Note that each of the subschemas in the The I suppose this is not terribly different than |
Beta Was this translation helpful? Give feedback.
-
One more point to raise here -- if we keep the discriminator in some form in Moonwalk -- the 3.x specs say that the discriminator must be a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There are a number of issues with the current definition of
discriminator
(as well as a number of open issues).allOf
/oneOf
/anyOf
keywords$ref
s not full sub-schemasI think we can replace it with either JSON Schema
if
/then
/else
or a compact form such as:Beta Was this translation helpful? Give feedback.
All reactions