Skip to content

Conversation

nuclearcat
Copy link
Member

Add custom JSON schema generator to handle Beanie's PydanticObjectId validator which was causing schema generation to fail. The custom generator provides a string schema representation for ObjectId fields, allowing the OpenAPI documentation to be generated successfully.

@nuclearcat nuclearcat force-pushed the fix-docs branch 3 times, most recently from aeee1f2 to 5638141 Compare September 2, 2025 08:10
Trying to fix by monkey-patching the PydanticObjectId
class to provide a proper JSON schema

Signed-off-by: Denys Fedoryshchenko <[email protected]>
@nuclearcat
Copy link
Member Author

Tried:

  1. Custom GenerateJsonSchema class: Created a custom schema generator to intercept and handle PydanticObjectId schemas - did not work as the generator wasn't called at the right level.

  2. Monkey-patching JSON schema method: Replaced PydanticObjectId.__get_pydantic_json_schema__ with customimplementation - did not work because Beanie's existing method was still calling the problematic handler.

  3. Monkey-patching both core and JSON schema methods: Replaced both __get_pydantic_core_schema__ and __get_pydantic_json_schema__ with string-based implementations - still not working.

We might get rid of fastapi-users to solve this issue

@nuclearcat nuclearcat closed this Sep 2, 2025
@JenySadadia
Copy link
Collaborator

JenySadadia commented Sep 5, 2025

Hello, out of curiosiry, I checked /docs endpoint on my local setup. It's working.

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

Successfully merging this pull request may close these issues.

2 participants