I\'m trying to build a Swagger model for a time interval, using a simple string to store the time (I know that there is also datetime):
definitions:
Time:
$ref
works by replacing itself and all of its sibling elements with the definition it is pointing at. That is why
lowerBound:
$ref: "#/definitions/Time"
description: Lower bound on the time interval.
default: "00:00"
becomes
lowerBound:
type: string
description: Time in 24 hour format "hh:mm".
A possible workaround is to wrap $ref
into allOf
- this can be used to "add" attributes to a $ref
but not override existing attributes.
lowerBound:
allOf:
- $ref: "#/definitions/Time"
description: Lower bound on the time interval.
default: "00:00"
Another way is to use replace the $ref
with an inline definition.
definitions:
TimeInterval:
type: object
properties:
lowerBound:
type: string # <------
description: Lower bound on the time interval, using 24 hour format "hh:mm".
default: "00:00"
upperBound:
type: string # <------
description: Upper bound on the time interval, using 24 hour format "hh:mm".
default: "24:00"
The usability of $ref
is being discussed in the OpenAPI spec repository here and here so maybe this will be improved in one of the future versions.