dapla-toolbelt-metadata 0.3.0__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dapla-toolbelt-metadata might be problematic. Click here for more details.

Files changed (69) hide show
  1. dapla_metadata/__init__.py +1 -0
  2. dapla_metadata/_shared/__init__.py +1 -0
  3. dapla_metadata/{datasets → _shared}/config.py +39 -13
  4. dapla_metadata/_shared/enums.py +28 -0
  5. dapla_metadata/{datasets → _shared}/user_info.py +4 -4
  6. dapla_metadata/datasets/core.py +6 -3
  7. dapla_metadata/datasets/utility/enums.py +0 -19
  8. dapla_metadata/datasets/utility/utils.py +1 -1
  9. dapla_metadata/variable_definitions/__init__.py +7 -0
  10. dapla_metadata/variable_definitions/_client.py +30 -0
  11. dapla_metadata/variable_definitions/config.py +49 -0
  12. dapla_metadata/variable_definitions/exceptions.py +66 -0
  13. dapla_metadata/variable_definitions/generated/.openapi-generator/FILES +22 -0
  14. dapla_metadata/variable_definitions/generated/.openapi-generator/VERSION +1 -0
  15. dapla_metadata/variable_definitions/generated/.openapi-generator-ignore +6 -0
  16. dapla_metadata/variable_definitions/generated/README.md +148 -0
  17. dapla_metadata/variable_definitions/generated/__init__.py +0 -0
  18. dapla_metadata/variable_definitions/generated/vardef_client/__init__.py +52 -0
  19. dapla_metadata/variable_definitions/generated/vardef_client/api/__init__.py +9 -0
  20. dapla_metadata/variable_definitions/generated/vardef_client/api/data_migration_api.py +313 -0
  21. dapla_metadata/variable_definitions/generated/vardef_client/api/draft_variable_definitions_api.py +919 -0
  22. dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py +919 -0
  23. dapla_metadata/variable_definitions/generated/vardef_client/api/public_api.py +915 -0
  24. dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py +876 -0
  25. dapla_metadata/variable_definitions/generated/vardef_client/api/variable_definitions_api.py +1205 -0
  26. dapla_metadata/variable_definitions/generated/vardef_client/api_client.py +779 -0
  27. dapla_metadata/variable_definitions/generated/vardef_client/api_response.py +27 -0
  28. dapla_metadata/variable_definitions/generated/vardef_client/configuration.py +474 -0
  29. dapla_metadata/variable_definitions/generated/vardef_client/docs/CompleteResponse.md +51 -0
  30. dapla_metadata/variable_definitions/generated/vardef_client/docs/Contact.md +30 -0
  31. dapla_metadata/variable_definitions/generated/vardef_client/docs/DataMigrationApi.md +90 -0
  32. dapla_metadata/variable_definitions/generated/vardef_client/docs/Draft.md +42 -0
  33. dapla_metadata/variable_definitions/generated/vardef_client/docs/DraftVariableDefinitionsApi.md +259 -0
  34. dapla_metadata/variable_definitions/generated/vardef_client/docs/LanguageStringType.md +31 -0
  35. dapla_metadata/variable_definitions/generated/vardef_client/docs/Owner.md +31 -0
  36. dapla_metadata/variable_definitions/generated/vardef_client/docs/Patch.md +43 -0
  37. dapla_metadata/variable_definitions/generated/vardef_client/docs/PatchesApi.md +249 -0
  38. dapla_metadata/variable_definitions/generated/vardef_client/docs/PublicApi.md +218 -0
  39. dapla_metadata/variable_definitions/generated/vardef_client/docs/SupportedLanguages.md +15 -0
  40. dapla_metadata/variable_definitions/generated/vardef_client/docs/UpdateDraft.md +44 -0
  41. dapla_metadata/variable_definitions/generated/vardef_client/docs/ValidityPeriod.md +42 -0
  42. dapla_metadata/variable_definitions/generated/vardef_client/docs/ValidityPeriodsApi.md +236 -0
  43. dapla_metadata/variable_definitions/generated/vardef_client/docs/VariableDefinitionsApi.md +304 -0
  44. dapla_metadata/variable_definitions/generated/vardef_client/docs/VariableStatus.md +17 -0
  45. dapla_metadata/variable_definitions/generated/vardef_client/exceptions.py +193 -0
  46. dapla_metadata/variable_definitions/generated/vardef_client/models/__init__.py +30 -0
  47. dapla_metadata/variable_definitions/generated/vardef_client/models/complete_response.py +284 -0
  48. dapla_metadata/variable_definitions/generated/vardef_client/models/contact.py +94 -0
  49. dapla_metadata/variable_definitions/generated/vardef_client/models/draft.py +243 -0
  50. dapla_metadata/variable_definitions/generated/vardef_client/models/klass_reference.py +99 -0
  51. dapla_metadata/variable_definitions/generated/vardef_client/models/language_string_type.py +104 -0
  52. dapla_metadata/variable_definitions/generated/vardef_client/models/owner.py +90 -0
  53. dapla_metadata/variable_definitions/generated/vardef_client/models/patch.py +289 -0
  54. dapla_metadata/variable_definitions/generated/vardef_client/models/problem.py +118 -0
  55. dapla_metadata/variable_definitions/generated/vardef_client/models/rendered_contact.py +92 -0
  56. dapla_metadata/variable_definitions/generated/vardef_client/models/rendered_variable_definition.py +235 -0
  57. dapla_metadata/variable_definitions/generated/vardef_client/models/supported_languages.py +33 -0
  58. dapla_metadata/variable_definitions/generated/vardef_client/models/update_draft.py +307 -0
  59. dapla_metadata/variable_definitions/generated/vardef_client/models/validity_period.py +259 -0
  60. dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py +33 -0
  61. dapla_metadata/variable_definitions/generated/vardef_client/py.typed +0 -0
  62. dapla_metadata/variable_definitions/generated/vardef_client/rest.py +249 -0
  63. dapla_metadata/variable_definitions/vardef.py +173 -0
  64. dapla_metadata/variable_definitions/variable_definition.py +212 -0
  65. {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/METADATA +1 -1
  66. dapla_toolbelt_metadata-0.4.1.dist-info/RECORD +80 -0
  67. dapla_toolbelt_metadata-0.3.0.dist-info/RECORD +0 -22
  68. {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/LICENSE +0 -0
  69. {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,99 @@
1
+ """Variable Definitions
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Any
18
+ from typing import ClassVar
19
+
20
+ from pydantic import BaseModel
21
+ from pydantic import ConfigDict
22
+ from pydantic import StrictStr
23
+ from typing_extensions import Self
24
+
25
+
26
+ class KlassReference(BaseModel):
27
+ """KlassReference"""
28
+
29
+ reference_uri: StrictStr
30
+ code: StrictStr | None = None
31
+ title: StrictStr | None = None
32
+ __properties: ClassVar[list[str]] = ["reference_uri", "code", "title"]
33
+
34
+ model_config = ConfigDict(
35
+ populate_by_name=True,
36
+ validate_assignment=True,
37
+ protected_namespaces=(),
38
+ )
39
+
40
+ def to_str(self) -> str:
41
+ """Returns the string representation of the model using alias"""
42
+ return pprint.pformat(self.model_dump(by_alias=True))
43
+
44
+ def to_json(self) -> str:
45
+ """Returns the JSON representation of the model using alias"""
46
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47
+ return json.dumps(self.to_dict())
48
+
49
+ @classmethod
50
+ def from_json(cls, json_str: str) -> Self | None:
51
+ """Create an instance of KlassReference from a JSON string"""
52
+ return cls.from_dict(json.loads(json_str))
53
+
54
+ def to_dict(self) -> dict[str, Any]:
55
+ """Return the dictionary representation of the model using alias.
56
+
57
+ This has the following differences from calling pydantic's
58
+ `self.model_dump(by_alias=True)`:
59
+
60
+ * `None` is only added to the output dict for nullable fields that
61
+ were set at model initialization. Other fields with value `None`
62
+ are ignored.
63
+ """
64
+ excluded_fields: set[str] = set([])
65
+
66
+ _dict = self.model_dump(
67
+ by_alias=True,
68
+ exclude=excluded_fields,
69
+ exclude_none=True,
70
+ )
71
+ # set to None if code (nullable) is None
72
+ # and model_fields_set contains the field
73
+ if self.code is None and "code" in self.model_fields_set:
74
+ _dict["code"] = None
75
+
76
+ # set to None if title (nullable) is None
77
+ # and model_fields_set contains the field
78
+ if self.title is None and "title" in self.model_fields_set:
79
+ _dict["title"] = None
80
+
81
+ return _dict
82
+
83
+ @classmethod
84
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
85
+ """Create an instance of KlassReference from a dict"""
86
+ if obj is None:
87
+ return None
88
+
89
+ if not isinstance(obj, dict):
90
+ return cls.model_validate(obj)
91
+
92
+ _obj = cls.model_validate(
93
+ {
94
+ "reference_uri": obj.get("reference_uri"),
95
+ "code": obj.get("code"),
96
+ "title": obj.get("title"),
97
+ }
98
+ )
99
+ return _obj
@@ -0,0 +1,104 @@
1
+ """Variable Definitions
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Any
18
+ from typing import ClassVar
19
+
20
+ from pydantic import BaseModel
21
+ from pydantic import ConfigDict
22
+ from pydantic import StrictStr
23
+ from typing_extensions import Self
24
+
25
+
26
+ class LanguageStringType(BaseModel):
27
+ """LanguageStringType"""
28
+
29
+ nb: StrictStr | None = None
30
+ nn: StrictStr | None = None
31
+ en: StrictStr | None = None
32
+ __properties: ClassVar[list[str]] = ["nb", "nn", "en"]
33
+
34
+ model_config = ConfigDict(
35
+ populate_by_name=True,
36
+ validate_assignment=True,
37
+ protected_namespaces=(),
38
+ )
39
+
40
+ def to_str(self) -> str:
41
+ """Returns the string representation of the model using alias"""
42
+ return pprint.pformat(self.model_dump(by_alias=True))
43
+
44
+ def to_json(self) -> str:
45
+ """Returns the JSON representation of the model using alias"""
46
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47
+ return json.dumps(self.to_dict())
48
+
49
+ @classmethod
50
+ def from_json(cls, json_str: str) -> Self | None:
51
+ """Create an instance of LanguageStringType from a JSON string"""
52
+ return cls.from_dict(json.loads(json_str))
53
+
54
+ def to_dict(self) -> dict[str, Any]:
55
+ """Return the dictionary representation of the model using alias.
56
+
57
+ This has the following differences from calling pydantic's
58
+ `self.model_dump(by_alias=True)`:
59
+
60
+ * `None` is only added to the output dict for nullable fields that
61
+ were set at model initialization. Other fields with value `None`
62
+ are ignored.
63
+ """
64
+ excluded_fields: set[str] = set([])
65
+
66
+ _dict = self.model_dump(
67
+ by_alias=True,
68
+ exclude=excluded_fields,
69
+ exclude_none=True,
70
+ )
71
+ # set to None if nb (nullable) is None
72
+ # and model_fields_set contains the field
73
+ if self.nb is None and "nb" in self.model_fields_set:
74
+ _dict["nb"] = None
75
+
76
+ # set to None if nn (nullable) is None
77
+ # and model_fields_set contains the field
78
+ if self.nn is None and "nn" in self.model_fields_set:
79
+ _dict["nn"] = None
80
+
81
+ # set to None if en (nullable) is None
82
+ # and model_fields_set contains the field
83
+ if self.en is None and "en" in self.model_fields_set:
84
+ _dict["en"] = None
85
+
86
+ return _dict
87
+
88
+ @classmethod
89
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
90
+ """Create an instance of LanguageStringType from a dict"""
91
+ if obj is None:
92
+ return None
93
+
94
+ if not isinstance(obj, dict):
95
+ return cls.model_validate(obj)
96
+
97
+ _obj = cls.model_validate(
98
+ {
99
+ "nb": obj.get("nb"),
100
+ "nn": obj.get("nn"),
101
+ "en": obj.get("en"),
102
+ }
103
+ )
104
+ return _obj
@@ -0,0 +1,90 @@
1
+ """Variable Definitions
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Annotated
18
+ from typing import Any
19
+ from typing import ClassVar
20
+
21
+ from pydantic import BaseModel
22
+ from pydantic import ConfigDict
23
+ from pydantic import Field
24
+ from typing_extensions import Self
25
+
26
+
27
+ class Owner(BaseModel):
28
+ """Owner"""
29
+
30
+ team: Annotated[str, Field(min_length=1, strict=True)]
31
+ groups: Annotated[
32
+ list[Annotated[str, Field(min_length=1, strict=True)]], Field(min_length=1)
33
+ ]
34
+ __properties: ClassVar[list[str]] = ["team", "groups"]
35
+
36
+ model_config = ConfigDict(
37
+ populate_by_name=True,
38
+ validate_assignment=True,
39
+ protected_namespaces=(),
40
+ )
41
+
42
+ def to_str(self) -> str:
43
+ """Returns the string representation of the model using alias"""
44
+ return pprint.pformat(self.model_dump(by_alias=True))
45
+
46
+ def to_json(self) -> str:
47
+ """Returns the JSON representation of the model using alias"""
48
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49
+ return json.dumps(self.to_dict())
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Self | None:
53
+ """Create an instance of Owner from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: set[str] = set([])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ return _dict
74
+
75
+ @classmethod
76
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
77
+ """Create an instance of Owner from a dict"""
78
+ if obj is None:
79
+ return None
80
+
81
+ if not isinstance(obj, dict):
82
+ return cls.model_validate(obj)
83
+
84
+ _obj = cls.model_validate(
85
+ {
86
+ "team": obj.get("team"),
87
+ "groups": obj.get("groups"),
88
+ }
89
+ )
90
+ return _obj
@@ -0,0 +1,289 @@
1
+ """Variable Definitions
2
+
3
+ ## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
4
+
5
+ The version of the OpenAPI document: 0.1
6
+ Contact: metadata@ssb.no
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from datetime import date
18
+ from typing import Any
19
+ from typing import ClassVar
20
+
21
+ from pydantic import BaseModel
22
+ from pydantic import ConfigDict
23
+ from pydantic import Field
24
+ from pydantic import StrictBool
25
+ from pydantic import StrictStr
26
+ from typing_extensions import Self
27
+
28
+ from ..models.contact import Contact
29
+ from ..models.language_string_type import LanguageStringType
30
+ from ..models.owner import Owner
31
+ from ..models.variable_status import VariableStatus
32
+
33
+
34
+ class Patch(BaseModel):
35
+ """Create a new Patch version on a Published Variable Definition."""
36
+
37
+ name: LanguageStringType | None = Field(
38
+ default=None,
39
+ description="Name of the variable. Must be unique for a given Unit Type and Owner combination.",
40
+ )
41
+ definition: LanguageStringType | None = Field(
42
+ default=None, description="Definition of the variable."
43
+ )
44
+ classification_reference: StrictStr | None = Field(
45
+ default=None,
46
+ description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
47
+ )
48
+ unit_types: list[StrictStr] | None = Field(
49
+ default=None,
50
+ description="A list of one or more unit types, e.g. person, vehicle, household. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/702.",
51
+ )
52
+ subject_fields: list[StrictStr] | None = Field(
53
+ default=None,
54
+ description="A list of subject fields that the variable is used in. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/618.",
55
+ )
56
+ contains_special_categories_of_personal_data: StrictBool | None = Field(
57
+ default=None,
58
+ description="True if variable instances contain particularly sensitive information. Applies even if the information or identifiers are pseudonymized. Information within the following categories are regarded as particularly sensitive: Ethnicity, Political alignment, Religion, Philosophical beliefs, Union membership, Genetics, Biometrics, Health, Sexual relations, Sexual orientation",
59
+ )
60
+ variable_status: VariableStatus | None = Field(
61
+ default=None, description="Status of the life cycle of the variable"
62
+ )
63
+ measurement_type: StrictStr | None = Field(
64
+ default=None,
65
+ description="Type of measurement for the variable, e.g. length, volume, currency. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/303",
66
+ )
67
+ valid_until: date | None = Field(
68
+ default=None,
69
+ description="The variable definition is valid until this date inclusive",
70
+ )
71
+ external_reference_uri: StrictStr | None = Field(
72
+ default=None, description="A link (URI) to an external definition/documentation"
73
+ )
74
+ comment: LanguageStringType | None = Field(
75
+ default=None,
76
+ description="Optional comment to explain the definition or communicate potential changes.",
77
+ )
78
+ related_variable_definition_uris: list[StrictStr] | None = Field(
79
+ default=None,
80
+ description="Link(s) to related definitions of variables - a list of one or more definitions. For example for a variable after-tax income it could be relevant to link to definitions of income from work, property income etc.",
81
+ )
82
+ owner: Owner | None = Field(
83
+ default=None,
84
+ description="Owner of the definition, i.e. responsible Dapla team (statistics team) and information about access management groups.",
85
+ )
86
+ contact: Contact | None = Field(default=None, description="Contact details")
87
+ __properties: ClassVar[list[str]] = [
88
+ "name",
89
+ "definition",
90
+ "classification_reference",
91
+ "unit_types",
92
+ "subject_fields",
93
+ "contains_special_categories_of_personal_data",
94
+ "variable_status",
95
+ "measurement_type",
96
+ "valid_until",
97
+ "external_reference_uri",
98
+ "comment",
99
+ "related_variable_definition_uris",
100
+ "owner",
101
+ "contact",
102
+ ]
103
+
104
+ model_config = ConfigDict(
105
+ populate_by_name=True,
106
+ validate_assignment=True,
107
+ protected_namespaces=(),
108
+ )
109
+
110
+ def to_str(self) -> str:
111
+ """Returns the string representation of the model using alias"""
112
+ return pprint.pformat(self.model_dump(by_alias=True))
113
+
114
+ def to_json(self) -> str:
115
+ """Returns the JSON representation of the model using alias"""
116
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
117
+ return json.dumps(self.to_dict())
118
+
119
+ @classmethod
120
+ def from_json(cls, json_str: str) -> Self | None:
121
+ """Create an instance of Patch from a JSON string"""
122
+ return cls.from_dict(json.loads(json_str))
123
+
124
+ def to_dict(self) -> dict[str, Any]:
125
+ """Return the dictionary representation of the model using alias.
126
+
127
+ This has the following differences from calling pydantic's
128
+ `self.model_dump(by_alias=True)`:
129
+
130
+ * `None` is only added to the output dict for nullable fields that
131
+ were set at model initialization. Other fields with value `None`
132
+ are ignored.
133
+ * OpenAPI `readOnly` fields are excluded.
134
+ """
135
+ excluded_fields: set[str] = set(
136
+ [
137
+ "variable_status",
138
+ ]
139
+ )
140
+
141
+ _dict = self.model_dump(
142
+ by_alias=True,
143
+ exclude=excluded_fields,
144
+ exclude_none=True,
145
+ )
146
+ # override the default output from pydantic by calling `to_dict()` of name
147
+ if self.name:
148
+ _dict["name"] = self.name.to_dict()
149
+ # override the default output from pydantic by calling `to_dict()` of definition
150
+ if self.definition:
151
+ _dict["definition"] = self.definition.to_dict()
152
+ # override the default output from pydantic by calling `to_dict()` of comment
153
+ if self.comment:
154
+ _dict["comment"] = self.comment.to_dict()
155
+ # override the default output from pydantic by calling `to_dict()` of owner
156
+ if self.owner:
157
+ _dict["owner"] = self.owner.to_dict()
158
+ # override the default output from pydantic by calling `to_dict()` of contact
159
+ if self.contact:
160
+ _dict["contact"] = self.contact.to_dict()
161
+ # set to None if name (nullable) is None
162
+ # and model_fields_set contains the field
163
+ if self.name is None and "name" in self.model_fields_set:
164
+ _dict["name"] = None
165
+
166
+ # set to None if definition (nullable) is None
167
+ # and model_fields_set contains the field
168
+ if self.definition is None and "definition" in self.model_fields_set:
169
+ _dict["definition"] = None
170
+
171
+ # set to None if classification_reference (nullable) is None
172
+ # and model_fields_set contains the field
173
+ if (
174
+ self.classification_reference is None
175
+ and "classification_reference" in self.model_fields_set
176
+ ):
177
+ _dict["classification_reference"] = None
178
+
179
+ # set to None if unit_types (nullable) is None
180
+ # and model_fields_set contains the field
181
+ if self.unit_types is None and "unit_types" in self.model_fields_set:
182
+ _dict["unit_types"] = None
183
+
184
+ # set to None if subject_fields (nullable) is None
185
+ # and model_fields_set contains the field
186
+ if self.subject_fields is None and "subject_fields" in self.model_fields_set:
187
+ _dict["subject_fields"] = None
188
+
189
+ # set to None if contains_special_categories_of_personal_data (nullable) is None
190
+ # and model_fields_set contains the field
191
+ if (
192
+ self.contains_special_categories_of_personal_data is None
193
+ and "contains_special_categories_of_personal_data" in self.model_fields_set
194
+ ):
195
+ _dict["contains_special_categories_of_personal_data"] = None
196
+
197
+ # set to None if variable_status (nullable) is None
198
+ # and model_fields_set contains the field
199
+ if self.variable_status is None and "variable_status" in self.model_fields_set:
200
+ _dict["variable_status"] = None
201
+
202
+ # set to None if measurement_type (nullable) is None
203
+ # and model_fields_set contains the field
204
+ if (
205
+ self.measurement_type is None
206
+ and "measurement_type" in self.model_fields_set
207
+ ):
208
+ _dict["measurement_type"] = None
209
+
210
+ # set to None if valid_until (nullable) is None
211
+ # and model_fields_set contains the field
212
+ if self.valid_until is None and "valid_until" in self.model_fields_set:
213
+ _dict["valid_until"] = None
214
+
215
+ # set to None if external_reference_uri (nullable) is None
216
+ # and model_fields_set contains the field
217
+ if (
218
+ self.external_reference_uri is None
219
+ and "external_reference_uri" in self.model_fields_set
220
+ ):
221
+ _dict["external_reference_uri"] = None
222
+
223
+ # set to None if comment (nullable) is None
224
+ # and model_fields_set contains the field
225
+ if self.comment is None and "comment" in self.model_fields_set:
226
+ _dict["comment"] = None
227
+
228
+ # set to None if related_variable_definition_uris (nullable) is None
229
+ # and model_fields_set contains the field
230
+ if (
231
+ self.related_variable_definition_uris is None
232
+ and "related_variable_definition_uris" in self.model_fields_set
233
+ ):
234
+ _dict["related_variable_definition_uris"] = None
235
+
236
+ # set to None if owner (nullable) is None
237
+ # and model_fields_set contains the field
238
+ if self.owner is None and "owner" in self.model_fields_set:
239
+ _dict["owner"] = None
240
+
241
+ # set to None if contact (nullable) is None
242
+ # and model_fields_set contains the field
243
+ if self.contact is None and "contact" in self.model_fields_set:
244
+ _dict["contact"] = None
245
+
246
+ return _dict
247
+
248
+ @classmethod
249
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
250
+ """Create an instance of Patch from a dict"""
251
+ if obj is None:
252
+ return None
253
+
254
+ if not isinstance(obj, dict):
255
+ return cls.model_validate(obj)
256
+
257
+ _obj = cls.model_validate(
258
+ {
259
+ "name": LanguageStringType.from_dict(obj["name"])
260
+ if obj.get("name") is not None
261
+ else None,
262
+ "definition": LanguageStringType.from_dict(obj["definition"])
263
+ if obj.get("definition") is not None
264
+ else None,
265
+ "classification_reference": obj.get("classification_reference"),
266
+ "unit_types": obj.get("unit_types"),
267
+ "subject_fields": obj.get("subject_fields"),
268
+ "contains_special_categories_of_personal_data": obj.get(
269
+ "contains_special_categories_of_personal_data"
270
+ ),
271
+ "variable_status": obj.get("variable_status"),
272
+ "measurement_type": obj.get("measurement_type"),
273
+ "valid_until": obj.get("valid_until"),
274
+ "external_reference_uri": obj.get("external_reference_uri"),
275
+ "comment": LanguageStringType.from_dict(obj["comment"])
276
+ if obj.get("comment") is not None
277
+ else None,
278
+ "related_variable_definition_uris": obj.get(
279
+ "related_variable_definition_uris"
280
+ ),
281
+ "owner": Owner.from_dict(obj["owner"])
282
+ if obj.get("owner") is not None
283
+ else None,
284
+ "contact": Contact.from_dict(obj["contact"])
285
+ if obj.get("contact") is not None
286
+ else None,
287
+ }
288
+ )
289
+ return _obj