docs: fix schema.json

This commit is contained in:
Sina Atalay 2024-05-20 21:42:30 +03:00
parent 6891dc4c85
commit a39ea4732c
2 changed files with 17 additions and 24 deletions

View File

@ -1663,17 +1663,14 @@ def generate_json_schema() -> dict[str, Any]:
field["oneOf"] = field["anyOf"] field["oneOf"] = field["anyOf"]
del field["anyOf"] del field["anyOf"]
# In date field, we both accept normal strings and Date objects. They # In date field, we both allow string and RenderCVDate type. Since we
# are both strings, therefore, if user provides a Date object, then # use "oneOf", matching both RenderCVDate and string is a problem
# JSON schema will complain that it matches two different types. # for the JSON schema. So, we remove the RenderCVDate type from the
# Remember that all of the anyOfs are changed to oneOfs. Only one of # "oneOf" list.
# the types can be matched. Therefore, we remove the first type, which if "date" in value["properties"]:
# is the string with the YYYY-MM-DD format. for i, one_of in enumerate(value["properties"]["date"]["oneOf"]):
if ( if "pattern" in one_of:
"date" in value["properties"] del value["properties"]["date"]["oneOf"][i]
and "oneOf" in value["properties"]["date"]
):
del value["properties"]["date"]["oneOf"][0]
return json_schema 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. json_schema_path (pathlib.Path): The path to save the JSON schema.
""" """
schema = generate_json_schema() schema = generate_json_schema()
schema_json = json.dumps(schema, indent=2) schema_json = json.dumps(schema, indent=2, ensure_ascii=False)
json_schema_path.write_text(schema_json) json_schema_path.write_text(schema_json, encoding="utf-8")

View File

@ -360,8 +360,7 @@
"title": "Date", "title": "Date",
"oneOf": [ "oneOf": [
{ {
"pattern": "\\d{4}-\\d{2}(-\\d{2})?", "type": "integer"
"type": "string"
}, },
{ {
"type": "string" "type": "string"
@ -375,7 +374,7 @@
"default": null, "default": null,
"description": "The location of the event.", "description": "The location of the event.",
"examples": [ "examples": [
"Istanbul, T\u00fcrkiye" "Istanbul, Türkiye"
], ],
"title": "Location", "title": "Location",
"oneOf": [ "oneOf": [
@ -725,8 +724,7 @@
"title": "Date", "title": "Date",
"oneOf": [ "oneOf": [
{ {
"pattern": "\\d{4}-\\d{2}(-\\d{2})?", "type": "integer"
"type": "string"
}, },
{ {
"type": "string" "type": "string"
@ -740,7 +738,7 @@
"default": null, "default": null,
"description": "The location of the event.", "description": "The location of the event.",
"examples": [ "examples": [
"Istanbul, T\u00fcrkiye" "Istanbul, Türkiye"
], ],
"title": "Location", "title": "Location",
"oneOf": [ "oneOf": [
@ -1422,8 +1420,7 @@
"title": "Date", "title": "Date",
"oneOf": [ "oneOf": [
{ {
"pattern": "\\d{4}-\\d{2}(-\\d{2})?", "type": "integer"
"type": "string"
}, },
{ {
"type": "string" "type": "string"
@ -1437,7 +1434,7 @@
"default": null, "default": null,
"description": "The location of the event.", "description": "The location of the event.",
"examples": [ "examples": [
"Istanbul, T\u00fcrkiye" "Istanbul, Türkiye"
], ],
"title": "Location", "title": "Location",
"oneOf": [ "oneOf": [
@ -1626,8 +1623,7 @@
"title": "Date", "title": "Date",
"oneOf": [ "oneOf": [
{ {
"pattern": "\\d{4}-\\d{2}(-\\d{2})?", "type": "integer"
"type": "string"
}, },
{ {
"type": "string" "type": "string"