data: fix schema

This commit is contained in:
Sina Atalay
2024-07-23 18:14:08 +03:00
parent 42dd88c025
commit 009875ef23
3 changed files with 26 additions and 4 deletions

View File

@@ -156,6 +156,21 @@ def generate_json_schema() -> dict:
field["oneOf"] = field["anyOf"]
del field["anyOf"]
# Currently, YAML extension in VS Code doesn't work properly with the
# `ListOfEntries` objects. For the best user experience, we will update
# the JSON Schema. If YAML extension in VS Code starts to work properly,
# then we should remove the following code for the correct JSON Schema.
ListOfEntriesForJsonSchema = list[models.Entry]
list_of_entries_json_schema = pydantic.TypeAdapter(
ListOfEntriesForJsonSchema
).json_schema()
del list_of_entries_json_schema["$defs"]
# Update the JSON Schema:
json_schema["$defs"]["CurriculumVitae"]["properties"]["sections"]["oneOf"][
0
]["additionalProperties"] = list_of_entries_json_schema
return json_schema
schema = models.RenderCVDataModel.model_json_schema(

View File

@@ -270,14 +270,11 @@ def validate_a_social_network_username(username: str, network: str) -> str:
# Create custom types: =================================================================
# ======================================================================================
# Create a custom type named ListOfEntries:
ListOfEntries = list[entry_types.Entry]
# Create a custom type named SectionContents, which is a list of entries. The entries
# can be any of the available entry types. The section is validated with the
# `validate_a_section` function.
SectionContents = Annotated[
pydantic.json_schema.SkipJsonSchema[Any] | ListOfEntries,
pydantic.json_schema.SkipJsonSchema[Any] | entry_types.ListOfEntries,
pydantic.BeforeValidator(
lambda entries: validate_a_section(
entries, entry_types=entry_types.available_entry_models

View File

@@ -472,6 +472,16 @@ Entry = (
| str
)
# Create a custom type named ListOfEntries:
ListOfEntries = (
list[OneLineEntry]
| list[NormalEntry]
| list[ExperienceEntry]
| list[EducationEntry]
| list[PublicationEntry]
| list[BulletEntry]
| list[str]
)
# ======================================================================================
# Store the available entry types: =====================================================