chalk-ai / pydantic-scim

Apache License 2.0
2 stars 1 forks source link

Use pydantic discriminated unions in `ListResponse` #6

Closed azmeuk closed 4 months ago

azmeuk commented 4 months ago

Currently ListResponse.Resources is a List of the very generic BaseModel.

https://github.com/chalk-ai/pydantic-scim/blob/2f602a1cd282bbd6328e0b92613b01d5ae934753/pydanticscim/responses.py#L44-L49

When reading a http response from a SCIM endpoint returning a ListResponse this is not really useful, as pydantic cannot guess by itself which Resource type is returned. Fortunately, pydantic implements discriminated unions to solve this issue. With a correctly crafted discriminator, pydantic should be able to read the schemas attribute in the resource payload to guess which model to instantiate.

What do you think?