Skip to content
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

Update alias documentation #3680

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1681-targhs.md
@@ -0,0 +1 @@
Update documentation for schema field customization alias
9 changes: 9 additions & 0 deletions docs/examples/schema_field_customization_alias.py
@@ -0,0 +1,9 @@
from pydantic import BaseModel, Field


class Foo(BaseModel):
private_name: int = Field(0, alias='public_name')


foo = Foo(public_name=1)
foo.private_name # returns 1
7 changes: 6 additions & 1 deletion docs/usage/schema.md
Expand Up @@ -61,7 +61,12 @@ It has the following arguments:
* `default_factory`: a zero-argument callable that will be called when a default value is needed for this field.
Among other purposes, this can be used to set dynamic default values.
It is forbidden to set both `default` and `default_factory`.
* `alias`: the public name of the field
* `alias`: the public name of the field. The name maps to a field during initialization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break the bullet points, we should add a whole new section (probably not in schema.py) to document alias.


```py
{!.tmp_examples/schema_field_customization_alias.py!}
```

* `title`: if omitted, `field_name.title()` is used
* `description`: if omitted and the annotation is a sub-model,
the docstring of the sub-model will be used
Expand Down