jsonschema check: allow for .values to be missing

see #16
This commit is contained in:
Klaas van Schelven
2024-12-16 11:23:55 +01:00
parent b597d91af7
commit ed9ffa248d
7 changed files with 5745 additions and 1112 deletions

View File

@@ -1,4 +1,4 @@
This licence applies to the file: event.schema.json
This licence applies to the files: event.schema.json (and its derivatives)
The source of this file is: https://raw.githubusercontent.com/getsentry/sentry-data-schemas/main/LICENSE
Copyright (c) 2020 Sentry (https://sentry.io) and individual contributors.

View File

@@ -40,12 +40,3 @@ In short, the more reasons to just use the "upstream" API.
Said in another way: we act more as the "relay" than as "getsentry/sentry", because we do ingest straight in the main
process. So we should adhere to the relay's spec.
### Notes on use:
Bugsink, as it stands, doesn't use event.schema.json much.
* We have `--valid-only` as a param on `send_json`, but I appear to have used that only sporadically (back in nov 2023)
* We _could_ at some point in the future [offer the option to] throw events through a validator before proceeding with
digesting. At that point we'll re-vendor event.schema.json (from the sentry-data-schemas repo)
* Reading this file is useful, but we can do that straight from the source.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -8,6 +8,20 @@ from django.conf import settings
from django.core.management.base import BaseCommand
def alter_schema(schema):
# alter the schema to make it fit what the actual documentation says; see issues/utils.py' get_values() for details
for key in ['exception', 'threads', 'breadcrumbs']:
# no idea why that anyOf[0] is there (since there's no anyOf[1]), but it's there.
definition = schema['anyOf'][0]['properties'][key]
schema['anyOf'][0]['properties'][key] = {
"anyOf": [
definition,
definition['properties']['values'],
]
}
class Command(BaseCommand):
help = "Fetches the event schema JSON from the API and saves it to disk. Used during development."
@@ -26,7 +40,7 @@ class Command(BaseCommand):
license_result.raise_for_status()
with open(settings.BASE_DIR / "api/LICENSE", "w") as f:
f.write("""This licence applies to the file: event.schema.json
f.write("""This licence applies to the files: event.schema.json (and its derivatives)
The source of this file is: %s
""" % license_url)
@@ -35,13 +49,17 @@ The source of this file is: %s
# Generate fastjsonschema code from the schema and save it to disk
schema = json.loads(json_result.text)
alter_schema(schema)
with open(settings.BASE_DIR / "api/event.schema.altered.json", "w") as f:
json.dump(schema, f, indent=2)
# use_formats=False for "uint64", see https://github.com/horejsek/python-fastjsonschema/issues/108
# use_default=False to avoid fastjsonschema adding default values to the data it validates (bwegh)
code = fastjsonschema.compile_to_code(schema, use_formats=False, use_default=False, detailed_exceptions=False)
with open(settings.BASE_DIR / "bugsink/event_schema.py", "w") as f:
f.write("""# This file is generated by fetch_event_schema_json.py
# it is based on api/event.schema.json
# it is based on api/event.schema.altered.json
# the following license applies:
""")
f.write("\n".join("# " + line for line in license_result.text.splitlines()) + "\n\n")

View File

@@ -41,7 +41,7 @@ class Command(BaseCommand):
del data["_meta"]
try:
schema_filename = settings.BASE_DIR / 'api/event.schema.json'
schema_filename = settings.BASE_DIR / 'api/event.schema.altered.json'
with open(schema_filename, 'r') as f:
schema = json.loads(f.read())

View File

@@ -134,7 +134,7 @@ class BaseIngestAPIView(View):
# exceptions, so you'd have that cost-of-rollback anyway.
def get_schema():
schema_filename = settings.BASE_DIR / 'api/event.schema.json'
schema_filename = settings.BASE_DIR / 'api/event.schema.altered.json'
with open(schema_filename, 'r') as f:
return json.loads(f.read())