-
I have a use-case where I have two objects, Comparison and Composite, that both share an operator property, but Composite has a collection of both itself and Comparisons. To discriminate, I figured I would use the operator property. Both Comparison and Composite have their own set of possible operators. I created a discriminator like this: Any: {}
Condition:
type: object
properties:
operator:
type: string
discriminator:
propertyName: operator
mapping:
eq: "#/components/schemas/Comparison"
neq: "#/components/schemas/Comparison"
gte: "#/components/schemas/Comparison"
lte: "#/components/schemas/Comparison"
gt: "#/components/schemas/Comparison"
lt: "#/components/schemas/Comparison"
in: "#/components/schemas/Comparison"
notIn: "#/components/schemas/Comparison"
or: "#/components/schemas/Composite"
and: "#/components/schemas/Composite"
anyOf:
- "$ref": "#/components/schemas/Comparison"
- "$ref": "#/components/schemas/Composite"
Comparison:
description: Check a property meets some condition
properties:
property:
type: string
argument:
"$ref": "#/components/schemas/Any"
operator:
"$ref": "#/components/schemas/ComparisonOperators"
type: object
Composite:
description: Multiple Conditions
properties:
operator:
"$ref": "#/components/schemas/CompositeOperators"
conditions:
type: array
items:
"$ref": "#/components/schemas/Condition"
type: object
ComparisonOperators:
type: string
enum:
- eq
- neq
- lte
- lt
- gte
- gt
- in
- notIn
CompositeOperators:
type: string
enum:
- andX
- orX And put it in swagger editor. It didn't complain, but I can't find a similar example. Was wondering if the mapping was meant to contain only unique One-To-One entries or if a Many-To-One like this is allowed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Ron Ratovsky answered in slack:
|
Beta Was this translation helpful? Give feedback.
Ron Ratovsky answered in slack: