Describe the bug
I would like to set a field passed from a $ref (let's say A) as required
. If I simply put it in the required
on my schema (let's say B), then I get some import errors.
If I follow another syntax, like here, I get no import error but the field is simply not required
To Reproduce
Create a simple folder <my-folder>
and place these two files:
---
type: object
title: A
properties:
a_field:
type: string
enum: [base_schema]
default: base_schema
---
type: object
title: B
allOf:
- A
required:
- a_field
Of course, here I could simply set a_field
as required directly in A
but this is just a basic example.
Or this one with the other syntax tried:
---
type: object
title: B
allOf:
- A
required:
- a_field
Command to generate models
Run:
datamodel-codegen --input-file-type jsonschema --input <my-folder> --output <output-folder>
For some reason, I cannot make it work with yaml
as input-file-type ...
Expected behavior
I expect the B
model to be generated like this (or something alike):
from __future__ import annotations
from enum import Enum
class AField(Enum):
base_schema = 'base_schema'
class B():
a_field: AField = 'base_schema'
We could also imagine importing AField
from file A
Instead I either get this (with the import errors):
from __future__ import annotations
from .a import A
class B(A):
a_field: AField
Or this one with the field not required:
from __future__ import annotations
from .a import A
class B(A):
pass
Version:
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