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

Add MaybeModel[T] type for POST/PUT/PATCH endpoint methods #17

Open
pederhan opened this issue Dec 20, 2022 · 0 comments
Open

Add MaybeModel[T] type for POST/PUT/PATCH endpoint methods #17

pederhan opened this issue Dec 20, 2022 · 0 comments

Comments

@pederhan
Copy link
Member

pederhan commented Dec 20, 2022

Rationale

It is currently possible to pass dicts to methods that create or update resources. This is not explained anywhere, and is basically an implementation detail.

Being able to pass in dicts to these methods is beneficial if the API spec changes in a backwards-incompatible way in the future, as users will be able to pass in custom dicts conforming to the new spec until an official harborapi update is available, after which they can resume using the models.

Implementation

In order to document this (currently implicit) behavior, we should add a new type called MaybeModel[T] that is an alias for Union[T, dict[str, Any]], where T is bound to BaseModel, and replace current types on POST/PUT/PATCH methods with this type.

from typing import TypeVar, Union, Any
from pydantic import BaseModel

T = TypeVar('T', bound=BaseModel)

MaybeModel = Union[T, dict[str, Any]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant