I didn't see anything specifically pertaining to this in the OpenAPI Reference, so I wanted to ask here for confirmation.
Let's say I have a reference with the following data:
components:
schemas:
Foobar:
type: object
properties:
timestamp:
type: number
uid:
type: number
username:
type: string
location:
type: string
Is it possible to reference this component but only take specific properties from within, such as uid
and username
, and exclude the rest? e.g.
$ref: '#/components/schemas/Foobar(uid,username)'
My use case is that I have a library call that returns records from the database, adding (or removing) additional records as necessary based on user input. So we could have myCall(['username']);
returning just the username, and myCall(['username', 'location']);
returning username and location.
If I wanted to properly document its various usages within my API, I would currently have to manually maintain all of the different variants of the output.
I was hoping I could make some "flexible" component I could reference, and have it still validate within the OpenAPI spec.
The closest I could find would be to wrap all of the properties under anyOf
:
components:
schemas:
Foobar:
anyOf:
- type: object
properties:
timestamp:
type: number
uid:
type: number
username:
type: string
location:
type: string
... but if parsed by something like ReDoc, it would just show that the output would be any of the listed properties, when I actually need the ability to declare that "out of any of these properties, the following will be output".
I'm guessing my use case is a little esoteric, but I am hoping to be proven wrong :)