Describe the bug
When a name collision is produced in a schema, by for example referencing to another schema + adding a property to it, an import as
is then used. However, the alias is wongly used in the code
To Reproduce
In <my-repo>
, dataset.yml
+ datasets.yml
:
---
type: object
title: dataset
properties:
values:
type: array
items:
type: number
---
type: object
title: datasets
properties:
datasets:
type: array
items:
allOf:
- $ref: dataset.yml
properties:
name:
type: string
default: "dataset"
Used commandline:
$ datamodel-codegen --input <my-repo> --output <my-output-repo> --input-file-type jsonschema
This results in the following datasets.py
file:
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel
from .dataset import Dataset as Dataset_1
class Dataset(Dataset_1.Dataset):
name: Optional[str] = 'dataset'
class Datasets(BaseModel):
datasets: Optional[List[Dataset]] = None
This is obviously wrong as Dataset_1
has no attribute Dataset
.
Expected behavior
I would expect the alias to be used properly.
In the example above, I would like to have:
class Dataset(Dataset_1):
name: Optional[str] = 'dataset'
Version:
Additional context
I noticed this behavior is linked with the naming of array items: when a plural (with s
at the end) is used for an array field , then the array item with be the same name without the leading s
. Other names will result in the Item
to be appended.
This smart naming should maybe be dropped to avoid (frequent?) name collision and this alias being wrongly used.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too