INNER CODE UNIT · Python

reduce_schema

jupyterhub/zero-to-jupyterhub-k8s · tools/compare-values-schema-content.py:25

def reduce_schema(d):
    """
    Takes a jsonschema loaded as a dictionary and return a reduced structure
    ignoring everything apart from the structure it describes.

    If additionalProperties or patternProperties is set, a "*" key will be added
    instead of whats listed under "properties".
    """
    r = {}
    if "properties" in d:
        for k, v in d["properties"].items():
            r[k] = None
            if isinstance(v, MutableMapping):
                if v.get("additionalProperties") or v.get("patternProperties"):
                    r[k] = {"*": None}
                # Exception: The schema describes conditional properties based
                #            on a condition in an "if" key. Then assume we want
                #            the properties found in the "then" key.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…