data_models: fix JSON Schema

This commit is contained in:
Sina Atalay 2024-05-29 02:47:18 +03:00
parent f9d674d37e
commit 46a2902218
2 changed files with 870 additions and 929 deletions

View File

@ -641,15 +641,15 @@ Entry = (
| BulletEntry | BulletEntry
| str | str
) )
ListOfEntries = ( ListOfEntries = list[
list[OneLineEntry] OneLineEntry
| list[NormalEntry] | NormalEntry
| list[ExperienceEntry] | ExperienceEntry
| list[EducationEntry] | EducationEntry
| list[PublicationEntry] | PublicationEntry
| list[BulletEntry] | BulletEntry
| list[str] | str
) ]
entry_types = Entry.__args__[:-1] # a tuple of all the entry types except str entry_types = Entry.__args__[:-1] # a tuple of all the entry types except str
entry_type_names = [entry_type.__name__ for entry_type in entry_types] + ["TextEntry"] entry_type_names = [entry_type.__name__ for entry_type in entry_types] + ["TextEntry"]
@ -1767,27 +1767,16 @@ def generate_json_schema() -> dict[str, Any]:
# already have the required field. Moreover, we would like to warn # already have the required field. Moreover, we would like to warn
# users if they provide null values. They can remove the fields if they # users if they provide null values. They can remove the fields if they
# don't want to provide them. # don't want to provide them.
null_type_dict = {} null_type_dict = {
null_type_dict["type"] = "null" "type": "null",
}
for field_name, field in value["properties"].items(): for field_name, field in value["properties"].items():
if "anyOf" in field: if "anyOf" in field:
if ( if null_type_dict in field["anyOf"]:
len(field["anyOf"]) == 2 field["anyOf"].remove(null_type_dict)
and null_type_dict in field["anyOf"]
):
field["oneOf"] = [field["anyOf"][0]]
del field["anyOf"]
# for sections field of CurriculumVitae: field["oneOf"] = field["anyOf"]
if "additionalProperties" in field["oneOf"][0]: del field["anyOf"]
field["oneOf"][0]["additionalProperties"]["oneOf"] = (
field["oneOf"][0]["additionalProperties"]["anyOf"]
)
del field["oneOf"][0]["additionalProperties"]["anyOf"]
else:
field["oneOf"] = field["anyOf"]
del field["anyOf"]
return json_schema return json_schema

File diff suppressed because it is too large Load Diff