def _flatten_object_type()

in src/rpdk/core/jsonutils/flattener.py [0:0]


    def _flatten_object_type(self, sub_schema, path):
        # we only care about allOf, anyOf, oneOf for object types
        sub_schema = self._flatten_combiners(sub_schema, path)

        # if "additionalProperties" is truthy (e.g. a non-empty object), then fail
        if sub_schema.get("additionalProperties"):
            raise ConstraintError("Object at '{path}' has 'additionalProperties'", path)

        # don't allow these together
        if "properties" in sub_schema and "patternProperties" in sub_schema:
            msg = (
                "Object at '{path}' has mutually exclusive "
                "'properties' and 'patternProperties'"
            )
            raise ConstraintError(msg, path)

        # if "properties" are defined, resolve each property
        try:
            properties = sub_schema["properties"]
        except KeyError:
            pass
        else:
            # resolve each property schema
            new_properties = {}
            for prop_name, prop_schema in properties.items():
                new_properties[prop_name] = self._walk(
                    prop_schema, path + ("properties", prop_name)
                )

            # replace properties with resolved properties
            sub_schema["properties"] = new_properties
            self._schema_map[path] = sub_schema
            return {"$ref": path}

        # if "patternProperties" are defined, resolve each property
        try:
            pattern_properties = sub_schema["patternProperties"]
        except KeyError:
            pass
        else:
            new_pattern_properties = {}
            for pattern, prop_schema in pattern_properties.items():
                new_pattern_properties[pattern] = self._walk(
                    prop_schema, path + ("patternProperties", pattern)
                )
            sub_schema["patternProperties"] = new_pattern_properties

        return sub_schema