Ejemplo n.º 1
0
def merge_schemas(target: SchemaDefinition,
                  mergee: SchemaDefinition,
                  imported_from: Optional[str] = None,
                  namespaces: Optional[Namespaces] = None) -> None:
    """ Merge mergee into target """
    assert target.name is not None, "Schema name must be supplied"
    if target.license is None:
        target.license = mergee.license

    target.imports += [
        imp for imp in mergee.imports if imp not in target.imports
    ]
    set_from_schema(mergee)

    if namespaces:
        merge_namespaces(target, mergee, namespaces)

    if imported_from is None:
        imported_from_uri = None
    else:
        if imported_from.startswith("http") or ":" not in imported_from:
            imported_from_uri = imported_from
        else:
            imported_from_uri = namespaces.uri_for(imported_from)
    merge_dicts(target.classes, mergee.classes, imported_from,
                imported_from_uri)
    merge_dicts(target.slots, mergee.slots, imported_from, imported_from_uri)
    merge_dicts(target.types, mergee.types, imported_from, imported_from_uri)
    merge_dicts(target.subsets, mergee.subsets, imported_from,
                imported_from_uri)
Ejemplo n.º 2
0
def merge_schemas(target: SchemaDefinition,
                  mergee: SchemaDefinition,
                  imported_from: Optional[str] = None,
                  namespaces: Optional[Namespaces] = None) -> None:
    """ Merge mergee into target """
    assert target.name is not None, "Schema name must be supplied"
    if target.license is None:
        target.license = mergee.license

    target.imports += [
        imp for imp in mergee.imports if imp not in target.imports
    ]
    set_from_schema(mergee)

    if namespaces:
        merge_namespaces(target, mergee, namespaces)

    merge_dicts(target.classes, mergee.classes, imported_from)
    merge_dicts(target.slots, mergee.slots, imported_from)
    merge_dicts(target.types, mergee.types, imported_from)