python-ddd
python-ddd copied to clipboard
Breaking swagger
Access path /docs with raise exception from pydantic
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'>>})
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.
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 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