mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-26 17:37:33 +00:00
feat(ingest): handling for const in json schema (#9694)
Co-authored-by: Harshal Sheth <hsheth2@gmail.com>
This commit is contained in:
parent
c158d2b9ec
commit
c4dec931a3
@ -316,10 +316,12 @@ class JsonSchemaTranslator:
|
||||
|
||||
@staticmethod
|
||||
def _get_description_from_any_schema(schema: Dict) -> str:
|
||||
# we do a redundant `if description in schema` check to guard against the scenario that schema is not a dictionary
|
||||
description = (
|
||||
(schema.get("description") or "") if "description" in schema else ""
|
||||
)
|
||||
description = ""
|
||||
if "description" in schema:
|
||||
description = str(schema.get("description"))
|
||||
elif "const" in schema:
|
||||
schema_const = schema.get("const")
|
||||
description = f"Const value: {schema_const}"
|
||||
if JsonSchemaTranslator._INJECT_DEFAULTS_INTO_DESCRIPTION:
|
||||
default = schema.get("default")
|
||||
if default is not None:
|
||||
|
||||
@ -725,6 +725,19 @@ def test_non_str_enums():
|
||||
assert fields[0].description == 'One of: "baz", 1, null'
|
||||
|
||||
|
||||
def test_const_description_pulled_correctly():
|
||||
schema = {
|
||||
"$id": "test",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {"bar": {"type": "string", "const": "not_defined"}},
|
||||
}
|
||||
|
||||
fields = list(JsonSchemaTranslator.get_fields_from_schema(schema))
|
||||
expected_field_paths: List[str] = ["[version=2.0].[type=object].[type=string].bar"]
|
||||
assert_field_paths_match(fields, expected_field_paths)
|
||||
assert fields[0].description == "Const value: not_defined"
|
||||
|
||||
|
||||
def test_anyof_with_properties():
|
||||
# We expect the event / timestamp fields to be included in both branches of the anyOf.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user