Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rafalkrupinski opened this issue Oct 1, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@rafalkrupinski
Copy link
Contributor

No description provided.

@rafalkrupinski rafalkrupinski added the enhancement New feature or request label Oct 1, 2022
@rafalkrupinski rafalkrupinski transferred this issue from python-lapidary/lapidary Jan 11, 2024
@rafalkrupinski
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant