Objects properties in OpenAPI can have writeOnly or readOnly attributes, meaning, they're only valid for requests or responses. At the same time the properties can be required.
In python, as long schema object is modelled as a single pydantic model, it means a field can be both optional and required (required, but only when either the object is used as either a request or a response). Pydantic doesn't allow for a conditional validation of properties.
Ideally, schemas should be modelled as two or three classes - base class with common properties, request class with writeOnly properties, and response class with readOnly.
Since the client might want to re-send an object coming as a response, it would be nice to have a helper method to generate the request variant from the response.
Objects properties in OpenAPI can have
writeOnly
orreadOnly
attributes, meaning, they're only valid for requests or responses. At the same time the properties can be required.In python, as long schema object is modelled as a single pydantic model, it means a field can be both optional and required (required, but only when either the object is used as either a request or a response). Pydantic doesn't allow for a conditional validation of properties.
Ideally, schemas should be modelled as two or three classes - base class with common properties, request class with writeOnly properties, and response class with readOnly.
Since the client might want to re-send an object coming as a response, it would be nice to have a helper method to generate the request variant from the response.