python-lapidary / lapidary-render

Web API client generator
https://lapidary.dev
GNU Affero General Public License v3.0
2 stars 0 forks source link

Generate a factory method for schema models that skips read-only properties #7

Closed rafalkrupinski closed 4 months ago

rafalkrupinski commented 8 months ago

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.

rafalkrupinski commented 4 months ago

Closing as I don't want to focus so much on data validation. read/writeOnly properties are now made Optional