From a39ea4732c1d8c7d97a6a31bb38826ab3c4e8637 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Mon, 20 May 2024 21:42:30 +0300 Subject: [PATCH] docs: fix schema.json --- rendercv/data_models.py | 23 ++++++++++------------- schema.json | 18 +++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/rendercv/data_models.py b/rendercv/data_models.py index c2614c6..9901d57 100644 --- a/rendercv/data_models.py +++ b/rendercv/data_models.py @@ -1663,17 +1663,14 @@ def generate_json_schema() -> dict[str, Any]: field["oneOf"] = field["anyOf"] del field["anyOf"] - # In date field, we both accept normal strings and Date objects. They - # are both strings, therefore, if user provides a Date object, then - # JSON schema will complain that it matches two different types. - # Remember that all of the anyOfs are changed to oneOfs. Only one of - # the types can be matched. Therefore, we remove the first type, which - # is the string with the YYYY-MM-DD format. - if ( - "date" in value["properties"] - and "oneOf" in value["properties"]["date"] - ): - del value["properties"]["date"]["oneOf"][0] + # In date field, we both allow string and RenderCVDate type. Since we + # use "oneOf", matching both RenderCVDate and string is a problem + # for the JSON schema. So, we remove the RenderCVDate type from the + # "oneOf" list. + if "date" in value["properties"]: + for i, one_of in enumerate(value["properties"]["date"]["oneOf"]): + if "pattern" in one_of: + del value["properties"]["date"]["oneOf"][i] return json_schema @@ -1691,5 +1688,5 @@ def generate_json_schema_file(json_schema_path: pathlib.Path): json_schema_path (pathlib.Path): The path to save the JSON schema. """ schema = generate_json_schema() - schema_json = json.dumps(schema, indent=2) - json_schema_path.write_text(schema_json) + schema_json = json.dumps(schema, indent=2, ensure_ascii=False) + json_schema_path.write_text(schema_json, encoding="utf-8") diff --git a/schema.json b/schema.json index 5de36e8..4367d63 100644 --- a/schema.json +++ b/schema.json @@ -360,8 +360,7 @@ "title": "Date", "oneOf": [ { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" + "type": "integer" }, { "type": "string" @@ -375,7 +374,7 @@ "default": null, "description": "The location of the event.", "examples": [ - "Istanbul, T\u00fcrkiye" + "Istanbul, Türkiye" ], "title": "Location", "oneOf": [ @@ -725,8 +724,7 @@ "title": "Date", "oneOf": [ { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" + "type": "integer" }, { "type": "string" @@ -740,7 +738,7 @@ "default": null, "description": "The location of the event.", "examples": [ - "Istanbul, T\u00fcrkiye" + "Istanbul, Türkiye" ], "title": "Location", "oneOf": [ @@ -1422,8 +1420,7 @@ "title": "Date", "oneOf": [ { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" + "type": "integer" }, { "type": "string" @@ -1437,7 +1434,7 @@ "default": null, "description": "The location of the event.", "examples": [ - "Istanbul, T\u00fcrkiye" + "Istanbul, Türkiye" ], "title": "Location", "oneOf": [ @@ -1626,8 +1623,7 @@ "title": "Date", "oneOf": [ { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" + "type": "integer" }, { "type": "string"