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]]
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 forUnion[T, dict[str, Any]]
, whereT
is bound toBaseModel
, and replace current types on POST/PUT/PATCH methods with this type.