drivendataorg / drivendataorg/erdantic

Support pydantic field's alias

Open
#80 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
419
Forks
30
PR merge metrics
No merged PRs in 30d

Description

I suggest to support `pydantic.Field.alias` field. Currently erdantic ignores it.

That's an example with simple `Gift` class:
```python3
from pydantic import BaseModel, Field

class Gift(BaseModel):
for_: str = Field(alias="for")
```

erdantic produces:

![image](https://github.com/drivendataorg/erdantic/assets/28492051/b73d4857-4da9-4268-8c44-fb92ded61922)

Although, pydantic displays a field as `for`:

```python3
>>> Gift.schema()
{'title': 'Gift', 'type': 'object', 'properties': {'for': {'title': 'For', 'type': 'string'}},
'required': ['for']}
```

Libraries like FastAPI use that schema in Swagger generations.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided Gift model and compare erdantic's diagram with Pydantic's Gift.schema() output, focusing on Field(alias="for"). Then locate the part of the repository that reads Pydantic model fields and determine how to make the diagram use the alias while preserving a passing test for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.