redocly-cli
redocly-cli copied to clipboard
Check for incorrect discriminator use
Is your feature request related to a problem? Please describe.
Yes: users need to get feedback about incorrect discriminator use.
Describe the solution you'd like
no-discriminator-property-in-object
Problem message:
The discriminator property
{insert the property name}must exist in schemas {...names}.
Describe alternatives you've considered None.
Additional context Here is a minimal example of a problematic schema:
components:
schemas:
Problematic:
type: object
properties:
data:
discriminator:
propertyName: objectType
oneOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B'
objectType:
type: string
A:
type: object
properties:
message:
type: string
B:
type: object
properties:
message:
type: string
Notice that objectType is defined in the Problematic schema and not in A and B, and this is the problem that it is not defined in A and B.
I tried out the example and it does give an error already:
Example validation errored: discriminator: oneOf subschemas (or referenced schemas) must have "properties/objectType" or match mapping.
23 | application/json:
24 | schema:
25 | $ref: '#/components/schemas/Problematic'
Is that error not exactly like (or sufficiently close enough to) the one requested by this issue?
@TylerRick you probably add example for this schema and this error was generated by the no-invalid-media-type-examples rule. So this is kind of different error.
But thank you that you noticed that, because it can help and simplify implementation of proposed rule in future!
Ah yes, you are right. I've been so focused on examples lately that I didn't notice this issue was not about an example rule... :smile: