]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Order keys by schema when validating.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 31 Oct 2021 09:16:13 +0000 (10:16 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 31 Oct 2021 09:16:13 +0000 (10:16 +0100)
bots/json_validate.py

index 9f195bfb0f94ce7fab019aeec48a1288059a5f72..4dbccfdb1472d9ea11f8aa4313226e69492e8c4b 100644 (file)
@@ -23,6 +23,8 @@ from pywikibot.bot import (
     SingleSiteBot,
 )
 
+from wrpylib.json_tools import order_json_keys
+
 docuReplacements = {'&params;': pagegenerators.parameterHelp}
 
 
@@ -43,9 +45,14 @@ class SledrunFromJsonBot(
         content_json = json.loads(self.current_page.text)
         try:
             validate(instance=content_json, schema=self.sledrun_schema)
-            text = json.dumps(content_json, ensure_ascii=False, indent=4)
+
+            content_json_ordered = order_json_keys(content_json, self.sledrun_schema)
+            assert content_json_ordered == content_json
+            text = json.dumps(content_json_ordered, ensure_ascii=False, indent=4)
+
         except jsonschema.exceptions.ValidationError as e:
             text = str(e)
+
         summary = 'JSON Daten aktualisiert.'
         self.put_current(text, summary=summary)