You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is something I had also reported to FastAPI and it has been fixed.
The issue is that pydantic now has two serialization modes: input and serialization. Since a computed field's input doesn't need to be validated, it is not present in that mode (which seems to be the default).
This causes autodoc_pydantic to not show these fields in the Show JSON Schema section.
So it needs to be added:
model_json_schema(mode='serialization')
The text was updated successfully, but these errors were encountered:
@Galarzaa90 Thanks for reporting this new feature in pydantic v2. This is indeed not supported in autodoc_pydantic yet. Does it make sense to allow the JSON output to be configurable to either choose the input or serialization mode? Or should we aim to simply use the serialization mode as default because it contains the model in its entirety. What is your opinion given your use case?
@Galarzaa90 Thanks for reporting this new feature in pydantic v2. This is indeed not supported in autodoc_pydantic yet. Does it make sense to allow the JSON output to be configurable to either choose the input or serialization mode? Or should we aim to simply use the serialization mode as default because it contains the model in its entirety. What is your opinion given your use case?
I was thinking about the same thing, that is a tough question. I believe that serialization is more suitable for general use. But making it configurable using a directive is not a bad idea. But I believe the default should be serialization.
For example, a calculated's property schema (in serialization mode) is marked with the readOnly attribute, indicating that it is not possible to write to it, possibly communicating that it is not something you would use for input.
"isBattleyeProtected": {
"description": "Whether the server is currently protected with BattlEye or not.",
"readOnly": true,
"type": "boolean"
}
On the other hand, the property would simply be omitted in input mode.
This is something I had also reported to FastAPI and it has been fixed.
The issue is that pydantic now has two serialization modes:
input
andserialization
. Since a computed field's input doesn't need to be validated, it is not present in that mode (which seems to be the default).This causes autodoc_pydantic to not show these fields in the Show JSON Schema section.
So it needs to be added:
The text was updated successfully, but these errors were encountered: