mirror of
https://github.com/rendercv/rendercv.git
synced 2026-05-19 14:15:40 -04:00
data: fix schema
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: =====================================================
|
||||
|
||||
Reference in New Issue
Block a user