`allOf` singletons for extension objects
Closed this issue · 0 comments
coriolinus commented
The OpenAPI schema does not perfectly map to the behavior we always want. For example, we might want to define a newtype which sometimes is read-only, or write-only. Because the readability and writeability are properties of a schema in OpenAPI, we can't directly express that.
Instead, we work around this with an allOf
singleton pattern:
components:
schemas:
Id:
type: string
format: uuid
x-newtype:
pub: true
Thing:
type: object
properties:
id:
readOnly: true
allOf:
- $ref: "#/components/schemas/Id"
required:
- id
WriteableThing:
type: object
properties:
id:
$ref: "#/components/schemas/Id"
required:
- id
This should produce output like this:
pub struct Id(pub Uuid);
pub struct Thing {
#[serde(skip_deserializing)]
id: Id,
}
pub struct WriteableThing {
id: Id,
}
- determine precisely what overrides we support in an
allOf
singleton - documentation
- test case
- implementation