Skip to content

Commit ea5012e

Browse files
committed
fix: put generated schema in definitions section in core.py
currently only enabled for Characteristics
1 parent 2353e9b commit ea5012e

2 files changed

Lines changed: 15 additions & 24 deletions

File tree

src/osw/core.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,20 @@ def store_entity_(
10241024
},
10251025
)
10261026
schema = json.loads(schema_str)
1027-
page.set_slot_content("jsonschema", schema)
1027+
# put generated schema in definitions section
1028+
# currently only enabled for Characteristics
1029+
if hasattr(model, "MetaCharacteristic") and isinstance(
1030+
entity, model.MetaCharacteristic
1031+
):
1032+
new_schema = {
1033+
"$defs": {"generated": schema},
1034+
"allOf": [{"$ref": "#/$defs/generated"}],
1035+
}
1036+
new_schema["@context"] = schema.pop("@context", None)
1037+
new_schema["title"] = schema.pop("title", "")
1038+
schema["title"] = "Generated" + new_schema["title"]
1039+
schema = new_schema
1040+
page.set_slot_content("jsonschema", new_schema)
10281041
except Exception as e:
10291042
print(
10301043
f"Schema generation from template failed for " f"{entity}: {e}"

tests/integration/store_and_load_test.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
from pathlib import Path
3-
from time import sleep
43

54
import osw.model.entity as model
65
from osw.auth import CredentialManager
@@ -228,35 +227,14 @@ def test_characteristic_creation(wiki_domain, wiki_username, wiki_password):
228227
)
229228
)
230229

231-
osw.site.disable_cache()
232-
pages = osw.site.get_page(
233-
WtSite.GetPageParam(titles=["Category:OSWefad80864a7647cab278f5f944e5754b"])
234-
).pages
235-
osw.site.enable_cache()
236-
cp = pages[0]
237-
schema: dict = cp.get_slot_content("jsonschema")
238-
# if "$defs" in schema and "generated" in schema["$defs"]
239-
new_schema = {
240-
"$defs": {"generated": schema},
241-
"allOf": [{"$ref": "#/$defs/generated"}],
242-
}
243-
new_schema["@context"] = schema.pop("@context")
244-
new_schema["title"] = schema.pop("title")
245-
schema["title"] = "Generated" + new_schema["title"]
246-
cp.set_slot_content("jsonschema", new_schema)
247-
248-
cp.edit()
249-
250230
pages = osw.site.get_page(
251231
WtSite.GetPageParam(titles=["Property:TestPropertyWithSchema"])
252232
).pages
253233
pp = pages[0]
254-
schema: dict = pp.get_slot_content("jsonschema")
234+
# schema: dict = pp.get_slot_content("jsonschema")
255235
new_schema = {"type": "number", "description": "Imported from property schema"}
256236
pp.set_slot_content("jsonschema", new_schema)
257-
258237
pp.edit()
259-
sleep(2) # we need to wait here a little bit before fetching
260238

261239
# load the characteristic as category
262240
osw.fetch_schema(

0 commit comments

Comments
 (0)