Skip to content

Data Model Extension

This part of the project documentation focuses on an information-oriented approach. Use it as a reference for the technical implementation of the pact_methodology project code.

DataModelExtension

Data Model Extension class.

Attributes:

Name Type Description
spec_version str

The version of the Data Model Extension specification. Must be a string in the format major.minor.patch as defined in Semantic Versioning 2.0.0. Must be 2.0.0 when referencing this specification.

data_schema str

The URL to the publicly accessible Extension Schema File. Must be a string representing a URL with the HTTPS schema.

data dict

A JSON Object that conforms to the extension schema file referenced by the dataSchema property.

documentation str

The URL to the publicly accessible Extension Documentation. Must be a string representing a URL with the HTTPS schema.

Source code in pact_methodology/data_model_extension/data_model_extension.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class DataModelExtension:
    """
    Data Model Extension class.

    Attributes:
        spec_version (str): The version of the Data Model Extension specification.
            Must be a string in the format major.minor.patch as defined in Semantic Versioning 2.0.0.
            Must be 2.0.0 when referencing this specification.
        data_schema (str): The URL to the publicly accessible Extension Schema File.
            Must be a string representing a URL with the HTTPS schema.
        data (dict): A JSON Object that conforms to the extension schema file referenced by the dataSchema property.
        documentation (str): The URL to the publicly accessible Extension Documentation.
            Must be a string representing a URL with the HTTPS schema.

    """

    def __init__(
        self, spec_version: str, data_schema: str, data: dict, documentation: str = None
    ):
        """
        Initializes a DataModelExtension object.

        Args:
            spec_version (str): The version of the Data Model Extension specification.
            data_schema (str): The URL to the publicly accessible Extension Schema File.
            data (dict): A JSON Object that conforms to the extension schema file referenced by the dataSchema property.
            documentation (str, optional): The URL to the publicly accessible Extension Documentation.

        Raises:
            ValueError: If the spec_version is not in the format major.minor.patch or is not 2.0.0.
            ValueError: If the data_schema is not a string representing a URL with the HTTPS schema.
            ValueError: If the data is not a dictionary or cannot be serialized to a JSON object.
            ValueError: If the documentation is not a string representing a URL with the HTTPS schema.

        """
        try:
            semvar_version = Version(spec_version)
            if (
                semvar_version.major != 2
                or semvar_version.minor != 0
                or semvar_version.micro != 0
            ):
                raise ValueError("Invalid spec version")
        except InvalidVersion:
            raise ValueError("Invalid spec version")

        parsed_url = urlparse(data_schema)
        if parsed_url.scheme != "https":
            raise ValueError("Invalid data schema URL scheme")
        if not parsed_url.netloc:
            raise ValueError("Invalid data schema URL")

        if not isinstance(data, dict):
            raise ValueError("Invalid data type")
        try:
            json.dumps(data)
        except TypeError:
            raise ValueError("Invalid data format")

        if documentation is not None:
            parsed_url = urlparse(documentation)
            if parsed_url.scheme != "https":
                raise ValueError("Invalid documentation URL scheme")
            if not parsed_url.netloc:
                raise ValueError("Invalid documentation URL")

        self.spec_version = spec_version
        self.data_schema = data_schema
        self.data = data
        self.documentation = documentation

    def __eq__(self, other):
        """
        Returns True if the other object is a DataModelExtension with the same attributes.

        Args:
            other (object): The object to compare with.

        Returns:
            bool: True if the objects are equal, False otherwise.
        """
        if not isinstance(other, DataModelExtension):
            return False
        return (
            self.spec_version == other.spec_version
            and self.data_schema == other.data_schema
            and self.data == other.data
            and self.documentation == other.documentation
        )

    def __repr__(self):
        """
        Returns a string representation of the DataModelExtension object.

        Returns:
            str: A string representation of the DataModelExtension object.
        """
        return f"DataModelExtension(spec_version={self.spec_version}, data_schema={self.data_schema}, data={self.data}, documentation={self.documentation})"

__eq__(other)

Returns True if the other object is a DataModelExtension with the same attributes.

Parameters:

Name Type Description Default
other object

The object to compare with.

required

Returns:

Name Type Description
bool

True if the objects are equal, False otherwise.

Source code in pact_methodology/data_model_extension/data_model_extension.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __eq__(self, other):
    """
    Returns True if the other object is a DataModelExtension with the same attributes.

    Args:
        other (object): The object to compare with.

    Returns:
        bool: True if the objects are equal, False otherwise.
    """
    if not isinstance(other, DataModelExtension):
        return False
    return (
        self.spec_version == other.spec_version
        and self.data_schema == other.data_schema
        and self.data == other.data
        and self.documentation == other.documentation
    )

__init__(spec_version, data_schema, data, documentation=None)

Initializes a DataModelExtension object.

Parameters:

Name Type Description Default
spec_version str

The version of the Data Model Extension specification.

required
data_schema str

The URL to the publicly accessible Extension Schema File.

required
data dict

A JSON Object that conforms to the extension schema file referenced by the dataSchema property.

required
documentation str

The URL to the publicly accessible Extension Documentation.

None

Raises:

Type Description
ValueError

If the spec_version is not in the format major.minor.patch or is not 2.0.0.

ValueError

If the data_schema is not a string representing a URL with the HTTPS schema.

ValueError

If the data is not a dictionary or cannot be serialized to a JSON object.

ValueError

If the documentation is not a string representing a URL with the HTTPS schema.

Source code in pact_methodology/data_model_extension/data_model_extension.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def __init__(
    self, spec_version: str, data_schema: str, data: dict, documentation: str = None
):
    """
    Initializes a DataModelExtension object.

    Args:
        spec_version (str): The version of the Data Model Extension specification.
        data_schema (str): The URL to the publicly accessible Extension Schema File.
        data (dict): A JSON Object that conforms to the extension schema file referenced by the dataSchema property.
        documentation (str, optional): The URL to the publicly accessible Extension Documentation.

    Raises:
        ValueError: If the spec_version is not in the format major.minor.patch or is not 2.0.0.
        ValueError: If the data_schema is not a string representing a URL with the HTTPS schema.
        ValueError: If the data is not a dictionary or cannot be serialized to a JSON object.
        ValueError: If the documentation is not a string representing a URL with the HTTPS schema.

    """
    try:
        semvar_version = Version(spec_version)
        if (
            semvar_version.major != 2
            or semvar_version.minor != 0
            or semvar_version.micro != 0
        ):
            raise ValueError("Invalid spec version")
    except InvalidVersion:
        raise ValueError("Invalid spec version")

    parsed_url = urlparse(data_schema)
    if parsed_url.scheme != "https":
        raise ValueError("Invalid data schema URL scheme")
    if not parsed_url.netloc:
        raise ValueError("Invalid data schema URL")

    if not isinstance(data, dict):
        raise ValueError("Invalid data type")
    try:
        json.dumps(data)
    except TypeError:
        raise ValueError("Invalid data format")

    if documentation is not None:
        parsed_url = urlparse(documentation)
        if parsed_url.scheme != "https":
            raise ValueError("Invalid documentation URL scheme")
        if not parsed_url.netloc:
            raise ValueError("Invalid documentation URL")

    self.spec_version = spec_version
    self.data_schema = data_schema
    self.data = data
    self.documentation = documentation

__repr__()

Returns a string representation of the DataModelExtension object.

Returns:

Name Type Description
str

A string representation of the DataModelExtension object.

Source code in pact_methodology/data_model_extension/data_model_extension.py
 96
 97
 98
 99
100
101
102
103
def __repr__(self):
    """
    Returns a string representation of the DataModelExtension object.

    Returns:
        str: A string representation of the DataModelExtension object.
    """
    return f"DataModelExtension(spec_version={self.spec_version}, data_schema={self.data_schema}, data={self.data}, documentation={self.documentation})"