-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: serialize on alias #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
562d83e
822815d
1b7ddd8
5d7e92d
b897521
1480ca7
a45482b
2c4b3c9
50b4a86
15a5d9e
33c5b5e
86d934d
ecba26a
789600c
06a8e8f
4dc1db1
f0678e7
0ac76bb
dc535b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,4 +49,3 @@ hide: | |
| ``` | ||
|
|
||
| /// | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,16 @@ def _process_attribute(obj: Any, attr: Attribute, cls: Class, *, processed: set[ | |||||
| if (value := getattr(obj, constraint, None)) is not None: | ||||||
| constraints[constraint] = value | ||||||
| attr.extra[common._self_namespace]["constraints"] = constraints | ||||||
| attr.extra[common._mkdocstrings_namespace]["template"] = "pydantic_field.html.jinja" | ||||||
|
|
||||||
| # Store validation/serialization aliases if defined. | ||||||
| if obj.alias: | ||||||
| attr.extra[common._self_namespace]["validation_alias"] = obj.alias | ||||||
| attr.extra[common._self_namespace]["serialization_alias"] = obj.alias | ||||||
| elif obj.validation_alias: | ||||||
| attr.extra[common._self_namespace]["validation_alias"] = obj.validation_alias | ||||||
| elif obj.serialization_alias: | ||||||
| attr.extra[common._self_namespace]["serialization_alias"] = obj.serialization_alias | ||||||
|
|
||||||
| # Populate docstring from the field's `description` argument. | ||||||
| if not attr.docstring and (docstring := obj.description): | ||||||
|
|
@@ -71,3 +81,16 @@ def _process_class(obj: type, cls: Class, *, processed: set[str], schema: bool = | |||||
| _process_attribute(getattr(obj, member.name), member, cls, processed=processed) # ty: ignore[invalid-argument-type] | ||||||
| elif kind is Kind.FUNCTION: | ||||||
| _process_function(getattr(obj, member.name), member, cls, processed=processed) # ty: ignore[invalid-argument-type] | ||||||
|
|
||||||
| # Process model fields that may not have been discovered by Griffe. | ||||||
| if hasattr(obj, "model_fields") and isinstance(obj.model_fields, dict): | ||||||
| for field_name, field_info in obj.model_fields.items(): | ||||||
| if field_name not in cls.all_members: | ||||||
| # Create an Attribute object for this field | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| attr = Attribute( | ||||||
| name=field_name, | ||||||
| lineno=0, | ||||||
| endlineno=0, | ||||||
| ) | ||||||
|
Comment on lines
+90
to
+94
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we set a docstring as well? To me this whole snippet shows that there's an issue with how we collect fields dynamically, and we should probably first fix that in another PR. |
||||||
| cls.members[field_name] = attr # ty: ignore[invalid-assignment] | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| _process_attribute(field_info, attr, cls, processed=processed) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| {% extends "_base/attribute.html.jinja" %} | ||
|
|
||
| {% block contents scoped %} | ||
| {% if attribute.extra.griffe_pydantic.validation_alias or attribute.extra.griffe_pydantic.serialization_alias %} | ||
| <ul> | ||
| {% if attribute.extra.griffe_pydantic.validation_alias == attribute.extra.griffe_pydantic.serialization_alias %} | ||
| <li>Alias: <code>{{ attribute.extra.griffe_pydantic.validation_alias }}</code></li> | ||
| {% else %} | ||
| {% if attribute.extra.griffe_pydantic.validation_alias %} | ||
| <li>Input / Validation alias: <code>{{ attribute.extra.griffe_pydantic.validation_alias }}</code></li> | ||
| {% endif %} | ||
| {% if attribute.extra.griffe_pydantic.serialization_alias %} | ||
| <li>Output / Serialization alias: <code>{{ attribute.extra.griffe_pydantic.serialization_alias }}</code></li> | ||
| {% endif %} | ||
| {% endif %} | ||
| </ul> | ||
| {% endif %} | ||
| {{ super() }} | ||
| {% endblock contents %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {% extends "_base/pydantic_field.html.jinja" %} |
Uh oh!
There was an error while loading. Please reload this page.