Forum Discussion

DeadCat's avatar
DeadCat
New Contributor
11 days ago

Polymorphism in Examples

Hi,

   I have responses that are much the same, but with a value field that needs to be different.

e.g. and object such as:

...
schema
type: object
properties:
requestId:
type: string
message:
type: string
    result:
type: object....


Now my object is the same structure, but the examples need to be different for the message - although the complex object can be the same.

such as:

example:
requestId: 12345678-1234-1234-1234-123456789abc
message: this action has been successfully done
result:
... complex object.

So; I don't want to copy and paste the complex object example every where, but I do want different results for the message.

Example allows referencing (exmple: $ref: ...), but it doesn't appear to allow polymorphism.

e.g. something like the below (which I commonly use for schemas):

example:
allOf:
- requestId: 12345678-1234-1234-1234-123456789abc
message: this action has been successfully done
- $ref: '#/components/examples/mycomplexobjectexample'

won't work; it just renders the $ref as a field

This is a tad annoying, as at the moment my only choice appears to be to copy and paste the complex object everywhere, and then have the small differences of the messages.
Is there at all a way round this.
No RepliesBe the first to reply