python-ddd icon indicating copy to clipboard operation
python-ddd copied to clipboard

Breaking swagger

Open lekhanhtoan37 opened this issue 1 year ago • 3 comments

Access path /docs with raise exception from pydantic image

  File "/Users/toanlk/Library/Caches/pypoetry/virtualenvs/python-ddd-PovSJyMx-py3.11/lib/python3.11/site-packages/pydantic/json_schema.py", line 2152, in handle_invalid_for_json_schema
    raise PydanticInvalidForJsonSchema(f'Cannot generate a JsonSchema for {error_info}')
pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'with-info', 'function': <bound method GenericUUID.validate of <class 'seedwork.domain.value_objects.GenericUUID'>>})

lekhanhtoan37 avatar Apr 25 '24 09:04 lekhanhtoan37

Hello @lekhanhtoan37

It seems there is an issue because the GenericUUID being not serializable wherever it is used. for testing I have Annotated it differently and it worked.

like Annotated[str, GenericUUID].

I am not sure of the proper solution as still I am checking the entire code base and trying to understand each portion of it. FastAPI - Swagger UI

parthjoshi90 avatar Aug 25 '24 14:08 parthjoshi90

you can also add method to GenericUUID

@classmethod
def __get_pydantic_core_schema__(cls, source_type: Any, handler: GetCoreSchemaHandler):
    return handler.generate_schema(uuid.UUID)

andrei-samofalov avatar Dec 10 '24 16:12 andrei-samofalov

@andrei-samofalov thanks for the fix, your solution is now part of https://github.com/pgorecki/python-ddd/blob/31d1db3af69d2c3237513ce5c4722c87e6b01a52/src/seedwork/domain/value_objects.py#L17

pgorecki avatar Jan 03 '25 10:01 pgorecki