dapla-toolbelt-metadata 0.2.1__py3-none-any.whl → 0.9.11__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.
- dapla_metadata/__init__.py +11 -1
- dapla_metadata/_shared/__init__.py +1 -0
- dapla_metadata/_shared/config.py +109 -0
- dapla_metadata/_shared/enums.py +27 -0
- dapla_metadata/_shared/py.typed +0 -0
- dapla_metadata/dapla/__init__.py +4 -0
- dapla_metadata/dapla/user_info.py +138 -0
- dapla_metadata/datasets/__init__.py +1 -1
- dapla_metadata/datasets/_merge.py +333 -0
- dapla_metadata/datasets/code_list.py +5 -6
- dapla_metadata/datasets/compatibility/__init__.py +10 -0
- dapla_metadata/datasets/compatibility/_handlers.py +363 -0
- dapla_metadata/datasets/compatibility/_utils.py +259 -0
- dapla_metadata/datasets/compatibility/model_backwards_compatibility.py +135 -0
- dapla_metadata/datasets/core.py +136 -182
- dapla_metadata/datasets/dapla_dataset_path_info.py +145 -19
- dapla_metadata/datasets/dataset_parser.py +41 -28
- dapla_metadata/datasets/model_validation.py +29 -20
- dapla_metadata/datasets/statistic_subject_mapping.py +5 -1
- dapla_metadata/datasets/utility/constants.py +22 -15
- dapla_metadata/datasets/utility/enums.py +8 -20
- dapla_metadata/datasets/utility/urn.py +234 -0
- dapla_metadata/datasets/utility/utils.py +183 -111
- dapla_metadata/standards/__init__.py +4 -0
- dapla_metadata/standards/name_validator.py +250 -0
- dapla_metadata/standards/standard_validators.py +98 -0
- dapla_metadata/standards/utils/__init__.py +1 -0
- dapla_metadata/standards/utils/constants.py +49 -0
- dapla_metadata/variable_definitions/__init__.py +11 -0
- dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES +20 -0
- dapla_metadata/variable_definitions/_generated/.openapi-generator/VERSION +1 -0
- dapla_metadata/variable_definitions/_generated/.openapi-generator-ignore +6 -0
- dapla_metadata/variable_definitions/_generated/README.md +148 -0
- dapla_metadata/variable_definitions/_generated/__init__.py +0 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py +47 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/__init__.py +8 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py +766 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/draft_variable_definitions_api.py +888 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/patches_api.py +888 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/validity_periods_api.py +583 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/variable_definitions_api.py +613 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api_client.py +779 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api_response.py +27 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/configuration.py +474 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/CompleteResponse.md +51 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/Contact.md +30 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/DataMigrationApi.md +90 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/Draft.md +42 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/DraftVariableDefinitionsApi.md +259 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/LanguageStringType.md +31 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/Owner.md +31 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/Patch.md +43 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/PatchesApi.md +249 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/PublicApi.md +218 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/SupportedLanguages.md +15 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/UpdateDraft.md +44 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/ValidityPeriod.md +42 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/ValidityPeriodsApi.md +236 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/VariableDefinitionsApi.md +304 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/docs/VariableStatus.md +17 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/exceptions.py +193 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py +31 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/complete_response.py +260 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/contact.py +94 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/draft.py +228 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py +158 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/language_string_type.py +101 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/owner.py +87 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/patch.py +244 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/problem.py +118 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/update_draft.py +274 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/validity_period.py +225 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_id_response.py +81 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_vardef_id_pair_response.py +84 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/variable_status.py +33 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/py.typed +0 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/rest.py +249 -0
- dapla_metadata/variable_definitions/_utils/__init__.py +1 -0
- dapla_metadata/variable_definitions/_utils/_client.py +32 -0
- dapla_metadata/variable_definitions/_utils/config.py +54 -0
- dapla_metadata/variable_definitions/_utils/constants.py +80 -0
- dapla_metadata/variable_definitions/_utils/files.py +309 -0
- dapla_metadata/variable_definitions/_utils/template_files.py +99 -0
- dapla_metadata/variable_definitions/_utils/variable_definition_files.py +143 -0
- dapla_metadata/variable_definitions/exceptions.py +255 -0
- dapla_metadata/variable_definitions/vardef.py +372 -0
- dapla_metadata/variable_definitions/vardok_id.py +48 -0
- dapla_metadata/variable_definitions/vardok_vardef_id_pair.py +47 -0
- dapla_metadata/variable_definitions/variable_definition.py +422 -0
- {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/METADATA +34 -36
- dapla_toolbelt_metadata-0.9.11.dist-info/RECORD +97 -0
- {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/WHEEL +1 -1
- dapla_metadata/datasets/config.py +0 -80
- dapla_metadata/datasets/model_backwards_compatibility.py +0 -520
- dapla_metadata/datasets/user_info.py +0 -88
- dapla_toolbelt_metadata-0.2.1.dist-info/RECORD +0 -22
- {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"""Internal Variable Definitions Administration API
|
|
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 datetime import datetime
|
|
19
|
+
from typing import Any
|
|
20
|
+
from typing import ClassVar
|
|
21
|
+
|
|
22
|
+
from pydantic import BaseModel
|
|
23
|
+
from pydantic import ConfigDict
|
|
24
|
+
from pydantic import Field
|
|
25
|
+
from pydantic import StrictBool
|
|
26
|
+
from pydantic import StrictInt
|
|
27
|
+
from pydantic import StrictStr
|
|
28
|
+
from typing_extensions import Self
|
|
29
|
+
|
|
30
|
+
from ..models.contact import Contact
|
|
31
|
+
from ..models.language_string_type import LanguageStringType
|
|
32
|
+
from ..models.owner import Owner
|
|
33
|
+
from ..models.variable_status import VariableStatus
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class CompleteResponse(BaseModel):
|
|
37
|
+
"""Complete response For internal users who need all details while maintaining variable definitions."""
|
|
38
|
+
|
|
39
|
+
id: StrictStr = Field(description="Unique identifier for the variable definition.")
|
|
40
|
+
patch_id: StrictInt = Field(
|
|
41
|
+
description="Integer identifying a patch of a variable definition."
|
|
42
|
+
)
|
|
43
|
+
name: LanguageStringType
|
|
44
|
+
short_name: StrictStr = Field(
|
|
45
|
+
description="Recommended short name. Must be unique within an organization."
|
|
46
|
+
)
|
|
47
|
+
definition: LanguageStringType
|
|
48
|
+
classification_reference: StrictStr | None = Field(
|
|
49
|
+
default=None,
|
|
50
|
+
description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
|
|
51
|
+
)
|
|
52
|
+
unit_types: list[StrictStr] = Field(
|
|
53
|
+
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."
|
|
54
|
+
)
|
|
55
|
+
subject_fields: list[StrictStr] = Field(
|
|
56
|
+
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."
|
|
57
|
+
)
|
|
58
|
+
contains_special_categories_of_personal_data: StrictBool = Field(
|
|
59
|
+
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"
|
|
60
|
+
)
|
|
61
|
+
variable_status: VariableStatus | None = None
|
|
62
|
+
measurement_type: StrictStr | None = Field(
|
|
63
|
+
default=None,
|
|
64
|
+
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",
|
|
65
|
+
)
|
|
66
|
+
valid_from: date = Field(
|
|
67
|
+
description="The variable definition is valid from this date inclusive"
|
|
68
|
+
)
|
|
69
|
+
valid_until: date | None = Field(
|
|
70
|
+
default=None,
|
|
71
|
+
description="The variable definition is valid until this date inclusive",
|
|
72
|
+
)
|
|
73
|
+
external_reference_uri: StrictStr | None = Field(
|
|
74
|
+
default=None, description="A link (URI) to an external definition/documentation"
|
|
75
|
+
)
|
|
76
|
+
comment: LanguageStringType | None = None
|
|
77
|
+
related_variable_definition_uris: list[StrictStr] | None = Field(
|
|
78
|
+
default=None,
|
|
79
|
+
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.",
|
|
80
|
+
)
|
|
81
|
+
owner: Owner
|
|
82
|
+
contact: Contact
|
|
83
|
+
created_at: datetime = Field(
|
|
84
|
+
description="The timestamp at which this variable definition was first created."
|
|
85
|
+
)
|
|
86
|
+
created_by: StrictStr = Field(
|
|
87
|
+
description="The user who created this variable definition."
|
|
88
|
+
)
|
|
89
|
+
last_updated_at: datetime = Field(
|
|
90
|
+
description="The timestamp at which this variable definition was last modified."
|
|
91
|
+
)
|
|
92
|
+
last_updated_by: StrictStr = Field(
|
|
93
|
+
description="The user who last modified this variable definition."
|
|
94
|
+
)
|
|
95
|
+
__properties: ClassVar[list[str]] = [
|
|
96
|
+
"id",
|
|
97
|
+
"patch_id",
|
|
98
|
+
"name",
|
|
99
|
+
"short_name",
|
|
100
|
+
"definition",
|
|
101
|
+
"classification_reference",
|
|
102
|
+
"unit_types",
|
|
103
|
+
"subject_fields",
|
|
104
|
+
"contains_special_categories_of_personal_data",
|
|
105
|
+
"variable_status",
|
|
106
|
+
"measurement_type",
|
|
107
|
+
"valid_from",
|
|
108
|
+
"valid_until",
|
|
109
|
+
"external_reference_uri",
|
|
110
|
+
"comment",
|
|
111
|
+
"related_variable_definition_uris",
|
|
112
|
+
"owner",
|
|
113
|
+
"contact",
|
|
114
|
+
"created_at",
|
|
115
|
+
"created_by",
|
|
116
|
+
"last_updated_at",
|
|
117
|
+
"last_updated_by",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
model_config = ConfigDict(
|
|
121
|
+
populate_by_name=True,
|
|
122
|
+
validate_assignment=True,
|
|
123
|
+
protected_namespaces=(),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def to_str(self) -> str:
|
|
127
|
+
"""Returns the string representation of the model using alias"""
|
|
128
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
129
|
+
|
|
130
|
+
def to_json(self) -> str:
|
|
131
|
+
"""Returns the JSON representation of the model using alias"""
|
|
132
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
133
|
+
return json.dumps(self.to_dict())
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
137
|
+
"""Create an instance of CompleteResponse from a JSON string"""
|
|
138
|
+
return cls.from_dict(json.loads(json_str))
|
|
139
|
+
|
|
140
|
+
def to_dict(self) -> dict[str, Any]:
|
|
141
|
+
"""Return the dictionary representation of the model using alias.
|
|
142
|
+
|
|
143
|
+
This has the following differences from calling pydantic's
|
|
144
|
+
`self.model_dump(by_alias=True)`:
|
|
145
|
+
|
|
146
|
+
* `None` is only added to the output dict for nullable fields that
|
|
147
|
+
were set at model initialization. Other fields with value `None`
|
|
148
|
+
are ignored.
|
|
149
|
+
"""
|
|
150
|
+
excluded_fields: set[str] = set([])
|
|
151
|
+
|
|
152
|
+
_dict = self.model_dump(
|
|
153
|
+
by_alias=True,
|
|
154
|
+
exclude=excluded_fields,
|
|
155
|
+
exclude_none=True,
|
|
156
|
+
)
|
|
157
|
+
# override the default output from pydantic by calling `to_dict()` of name
|
|
158
|
+
if self.name:
|
|
159
|
+
_dict["name"] = self.name.to_dict()
|
|
160
|
+
# override the default output from pydantic by calling `to_dict()` of definition
|
|
161
|
+
if self.definition:
|
|
162
|
+
_dict["definition"] = self.definition.to_dict()
|
|
163
|
+
# override the default output from pydantic by calling `to_dict()` of comment
|
|
164
|
+
if self.comment:
|
|
165
|
+
_dict["comment"] = self.comment.to_dict()
|
|
166
|
+
# override the default output from pydantic by calling `to_dict()` of owner
|
|
167
|
+
if self.owner:
|
|
168
|
+
_dict["owner"] = self.owner.to_dict()
|
|
169
|
+
# override the default output from pydantic by calling `to_dict()` of contact
|
|
170
|
+
if self.contact:
|
|
171
|
+
_dict["contact"] = self.contact.to_dict()
|
|
172
|
+
# set to None if classification_reference (nullable) is None
|
|
173
|
+
# and model_fields_set contains the field
|
|
174
|
+
if (
|
|
175
|
+
self.classification_reference is None
|
|
176
|
+
and "classification_reference" in self.model_fields_set
|
|
177
|
+
):
|
|
178
|
+
_dict["classification_reference"] = None
|
|
179
|
+
|
|
180
|
+
# set to None if measurement_type (nullable) is None
|
|
181
|
+
# and model_fields_set contains the field
|
|
182
|
+
if (
|
|
183
|
+
self.measurement_type is None
|
|
184
|
+
and "measurement_type" in self.model_fields_set
|
|
185
|
+
):
|
|
186
|
+
_dict["measurement_type"] = None
|
|
187
|
+
|
|
188
|
+
# set to None if valid_until (nullable) is None
|
|
189
|
+
# and model_fields_set contains the field
|
|
190
|
+
if self.valid_until is None and "valid_until" in self.model_fields_set:
|
|
191
|
+
_dict["valid_until"] = None
|
|
192
|
+
|
|
193
|
+
# set to None if external_reference_uri (nullable) is None
|
|
194
|
+
# and model_fields_set contains the field
|
|
195
|
+
if (
|
|
196
|
+
self.external_reference_uri is None
|
|
197
|
+
and "external_reference_uri" in self.model_fields_set
|
|
198
|
+
):
|
|
199
|
+
_dict["external_reference_uri"] = None
|
|
200
|
+
|
|
201
|
+
# set to None if related_variable_definition_uris (nullable) is None
|
|
202
|
+
# and model_fields_set contains the field
|
|
203
|
+
if (
|
|
204
|
+
self.related_variable_definition_uris is None
|
|
205
|
+
and "related_variable_definition_uris" in self.model_fields_set
|
|
206
|
+
):
|
|
207
|
+
_dict["related_variable_definition_uris"] = None
|
|
208
|
+
|
|
209
|
+
return _dict
|
|
210
|
+
|
|
211
|
+
@classmethod
|
|
212
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
213
|
+
"""Create an instance of CompleteResponse from a dict"""
|
|
214
|
+
if obj is None:
|
|
215
|
+
return None
|
|
216
|
+
|
|
217
|
+
if not isinstance(obj, dict):
|
|
218
|
+
return cls.model_validate(obj)
|
|
219
|
+
|
|
220
|
+
_obj = cls.model_validate(
|
|
221
|
+
{
|
|
222
|
+
"id": obj.get("id"),
|
|
223
|
+
"patch_id": obj.get("patch_id"),
|
|
224
|
+
"name": LanguageStringType.from_dict(obj["name"])
|
|
225
|
+
if obj.get("name") is not None
|
|
226
|
+
else None,
|
|
227
|
+
"short_name": obj.get("short_name"),
|
|
228
|
+
"definition": LanguageStringType.from_dict(obj["definition"])
|
|
229
|
+
if obj.get("definition") is not None
|
|
230
|
+
else None,
|
|
231
|
+
"classification_reference": obj.get("classification_reference"),
|
|
232
|
+
"unit_types": obj.get("unit_types"),
|
|
233
|
+
"subject_fields": obj.get("subject_fields"),
|
|
234
|
+
"contains_special_categories_of_personal_data": obj.get(
|
|
235
|
+
"contains_special_categories_of_personal_data"
|
|
236
|
+
),
|
|
237
|
+
"variable_status": obj.get("variable_status"),
|
|
238
|
+
"measurement_type": obj.get("measurement_type"),
|
|
239
|
+
"valid_from": obj.get("valid_from"),
|
|
240
|
+
"valid_until": obj.get("valid_until"),
|
|
241
|
+
"external_reference_uri": obj.get("external_reference_uri"),
|
|
242
|
+
"comment": LanguageStringType.from_dict(obj["comment"])
|
|
243
|
+
if obj.get("comment") is not None
|
|
244
|
+
else None,
|
|
245
|
+
"related_variable_definition_uris": obj.get(
|
|
246
|
+
"related_variable_definition_uris"
|
|
247
|
+
),
|
|
248
|
+
"owner": Owner.from_dict(obj["owner"])
|
|
249
|
+
if obj.get("owner") is not None
|
|
250
|
+
else None,
|
|
251
|
+
"contact": Contact.from_dict(obj["contact"])
|
|
252
|
+
if obj.get("contact") is not None
|
|
253
|
+
else None,
|
|
254
|
+
"created_at": obj.get("created_at"),
|
|
255
|
+
"created_by": obj.get("created_by"),
|
|
256
|
+
"last_updated_at": obj.get("last_updated_at"),
|
|
257
|
+
"last_updated_by": obj.get("last_updated_by"),
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
return _obj
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Internal Variable Definitions Administration API
|
|
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
|
+
from ..models.language_string_type import LanguageStringType
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Contact(BaseModel):
|
|
29
|
+
"""Contact"""
|
|
30
|
+
|
|
31
|
+
title: LanguageStringType
|
|
32
|
+
email: StrictStr
|
|
33
|
+
__properties: ClassVar[list[str]] = ["title", "email"]
|
|
34
|
+
|
|
35
|
+
model_config = ConfigDict(
|
|
36
|
+
populate_by_name=True,
|
|
37
|
+
validate_assignment=True,
|
|
38
|
+
protected_namespaces=(),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def to_str(self) -> str:
|
|
42
|
+
"""Returns the string representation of the model using alias"""
|
|
43
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
44
|
+
|
|
45
|
+
def to_json(self) -> str:
|
|
46
|
+
"""Returns the JSON representation of the model using alias"""
|
|
47
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
48
|
+
return json.dumps(self.to_dict())
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
52
|
+
"""Create an instance of Contact from a JSON string"""
|
|
53
|
+
return cls.from_dict(json.loads(json_str))
|
|
54
|
+
|
|
55
|
+
def to_dict(self) -> dict[str, Any]:
|
|
56
|
+
"""Return the dictionary representation of the model using alias.
|
|
57
|
+
|
|
58
|
+
This has the following differences from calling pydantic's
|
|
59
|
+
`self.model_dump(by_alias=True)`:
|
|
60
|
+
|
|
61
|
+
* `None` is only added to the output dict for nullable fields that
|
|
62
|
+
were set at model initialization. Other fields with value `None`
|
|
63
|
+
are ignored.
|
|
64
|
+
"""
|
|
65
|
+
excluded_fields: set[str] = set([])
|
|
66
|
+
|
|
67
|
+
_dict = self.model_dump(
|
|
68
|
+
by_alias=True,
|
|
69
|
+
exclude=excluded_fields,
|
|
70
|
+
exclude_none=True,
|
|
71
|
+
)
|
|
72
|
+
# override the default output from pydantic by calling `to_dict()` of title
|
|
73
|
+
if self.title:
|
|
74
|
+
_dict["title"] = self.title.to_dict()
|
|
75
|
+
return _dict
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
79
|
+
"""Create an instance of Contact from a dict"""
|
|
80
|
+
if obj is None:
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
if not isinstance(obj, dict):
|
|
84
|
+
return cls.model_validate(obj)
|
|
85
|
+
|
|
86
|
+
_obj = cls.model_validate(
|
|
87
|
+
{
|
|
88
|
+
"title": LanguageStringType.from_dict(obj["title"])
|
|
89
|
+
if obj.get("title") is not None
|
|
90
|
+
else None,
|
|
91
|
+
"email": obj.get("email"),
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
return _obj
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Internal Variable Definitions Administration API
|
|
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
|
|
17
|
+
from datetime import date
|
|
18
|
+
from typing import Annotated
|
|
19
|
+
from typing import Any
|
|
20
|
+
from typing import ClassVar
|
|
21
|
+
|
|
22
|
+
from pydantic import BaseModel
|
|
23
|
+
from pydantic import ConfigDict
|
|
24
|
+
from pydantic import Field
|
|
25
|
+
from pydantic import StrictBool
|
|
26
|
+
from pydantic import StrictStr
|
|
27
|
+
from pydantic import field_validator
|
|
28
|
+
from typing_extensions import Self
|
|
29
|
+
|
|
30
|
+
from ..models.contact import Contact
|
|
31
|
+
from ..models.language_string_type import LanguageStringType
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Draft(BaseModel):
|
|
35
|
+
"""Create a Draft Variable Definition"""
|
|
36
|
+
|
|
37
|
+
name: LanguageStringType
|
|
38
|
+
short_name: Annotated[str, Field(strict=True)] = Field(
|
|
39
|
+
description="Recommended short name. Must be unique within an organization."
|
|
40
|
+
)
|
|
41
|
+
definition: LanguageStringType
|
|
42
|
+
classification_reference: StrictStr | None = Field(
|
|
43
|
+
default=None,
|
|
44
|
+
description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
|
|
45
|
+
)
|
|
46
|
+
unit_types: list[Annotated[str, Field(min_length=1, strict=True)]] = Field(
|
|
47
|
+
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."
|
|
48
|
+
)
|
|
49
|
+
subject_fields: list[Annotated[str, Field(min_length=1, strict=True)]] = Field(
|
|
50
|
+
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."
|
|
51
|
+
)
|
|
52
|
+
contains_special_categories_of_personal_data: StrictBool = Field(
|
|
53
|
+
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"
|
|
54
|
+
)
|
|
55
|
+
measurement_type: StrictStr | None = Field(
|
|
56
|
+
default=None,
|
|
57
|
+
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",
|
|
58
|
+
)
|
|
59
|
+
valid_from: date = Field(
|
|
60
|
+
description="The variable definition is valid from this date inclusive"
|
|
61
|
+
)
|
|
62
|
+
valid_until: date | None = Field(
|
|
63
|
+
default=None,
|
|
64
|
+
description="The variable definition is valid until this date inclusive",
|
|
65
|
+
)
|
|
66
|
+
external_reference_uri: StrictStr | None = Field(
|
|
67
|
+
default=None, description="A link (URI) to an external definition/documentation"
|
|
68
|
+
)
|
|
69
|
+
comment: LanguageStringType | None = None
|
|
70
|
+
related_variable_definition_uris: list[StrictStr] | None = Field(
|
|
71
|
+
default=None,
|
|
72
|
+
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.",
|
|
73
|
+
)
|
|
74
|
+
contact: Contact
|
|
75
|
+
__properties: ClassVar[list[str]] = [
|
|
76
|
+
"name",
|
|
77
|
+
"short_name",
|
|
78
|
+
"definition",
|
|
79
|
+
"classification_reference",
|
|
80
|
+
"unit_types",
|
|
81
|
+
"subject_fields",
|
|
82
|
+
"contains_special_categories_of_personal_data",
|
|
83
|
+
"measurement_type",
|
|
84
|
+
"valid_from",
|
|
85
|
+
"valid_until",
|
|
86
|
+
"external_reference_uri",
|
|
87
|
+
"comment",
|
|
88
|
+
"related_variable_definition_uris",
|
|
89
|
+
"contact",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
@field_validator("short_name")
|
|
93
|
+
def short_name_validate_regular_expression(cls, value):
|
|
94
|
+
"""Validates the regular expression"""
|
|
95
|
+
if not re.match(r"^[a-z0-9_]{2,}$", value):
|
|
96
|
+
raise ValueError(r"must validate the regular expression /^[a-z0-9_]{2,}$/")
|
|
97
|
+
return value
|
|
98
|
+
|
|
99
|
+
model_config = ConfigDict(
|
|
100
|
+
populate_by_name=True,
|
|
101
|
+
validate_assignment=True,
|
|
102
|
+
protected_namespaces=(),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def to_str(self) -> str:
|
|
106
|
+
"""Returns the string representation of the model using alias"""
|
|
107
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
108
|
+
|
|
109
|
+
def to_json(self) -> str:
|
|
110
|
+
"""Returns the JSON representation of the model using alias"""
|
|
111
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
112
|
+
return json.dumps(self.to_dict())
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
116
|
+
"""Create an instance of Draft from a JSON string"""
|
|
117
|
+
return cls.from_dict(json.loads(json_str))
|
|
118
|
+
|
|
119
|
+
def to_dict(self) -> dict[str, Any]:
|
|
120
|
+
"""Return the dictionary representation of the model using alias.
|
|
121
|
+
|
|
122
|
+
This has the following differences from calling pydantic's
|
|
123
|
+
`self.model_dump(by_alias=True)`:
|
|
124
|
+
|
|
125
|
+
* `None` is only added to the output dict for nullable fields that
|
|
126
|
+
were set at model initialization. Other fields with value `None`
|
|
127
|
+
are ignored.
|
|
128
|
+
"""
|
|
129
|
+
excluded_fields: set[str] = set([])
|
|
130
|
+
|
|
131
|
+
_dict = self.model_dump(
|
|
132
|
+
by_alias=True,
|
|
133
|
+
exclude=excluded_fields,
|
|
134
|
+
exclude_none=True,
|
|
135
|
+
)
|
|
136
|
+
# override the default output from pydantic by calling `to_dict()` of name
|
|
137
|
+
if self.name:
|
|
138
|
+
_dict["name"] = self.name.to_dict()
|
|
139
|
+
# override the default output from pydantic by calling `to_dict()` of definition
|
|
140
|
+
if self.definition:
|
|
141
|
+
_dict["definition"] = self.definition.to_dict()
|
|
142
|
+
# override the default output from pydantic by calling `to_dict()` of comment
|
|
143
|
+
if self.comment:
|
|
144
|
+
_dict["comment"] = self.comment.to_dict()
|
|
145
|
+
# override the default output from pydantic by calling `to_dict()` of contact
|
|
146
|
+
if self.contact:
|
|
147
|
+
_dict["contact"] = self.contact.to_dict()
|
|
148
|
+
# set to None if classification_reference (nullable) is None
|
|
149
|
+
# and model_fields_set contains the field
|
|
150
|
+
if (
|
|
151
|
+
self.classification_reference is None
|
|
152
|
+
and "classification_reference" in self.model_fields_set
|
|
153
|
+
):
|
|
154
|
+
_dict["classification_reference"] = None
|
|
155
|
+
|
|
156
|
+
# set to None if measurement_type (nullable) is None
|
|
157
|
+
# and model_fields_set contains the field
|
|
158
|
+
if (
|
|
159
|
+
self.measurement_type is None
|
|
160
|
+
and "measurement_type" in self.model_fields_set
|
|
161
|
+
):
|
|
162
|
+
_dict["measurement_type"] = None
|
|
163
|
+
|
|
164
|
+
# set to None if valid_until (nullable) is None
|
|
165
|
+
# and model_fields_set contains the field
|
|
166
|
+
if self.valid_until is None and "valid_until" in self.model_fields_set:
|
|
167
|
+
_dict["valid_until"] = None
|
|
168
|
+
|
|
169
|
+
# set to None if external_reference_uri (nullable) is None
|
|
170
|
+
# and model_fields_set contains the field
|
|
171
|
+
if (
|
|
172
|
+
self.external_reference_uri is None
|
|
173
|
+
and "external_reference_uri" in self.model_fields_set
|
|
174
|
+
):
|
|
175
|
+
_dict["external_reference_uri"] = None
|
|
176
|
+
|
|
177
|
+
# set to None if related_variable_definition_uris (nullable) is None
|
|
178
|
+
# and model_fields_set contains the field
|
|
179
|
+
if (
|
|
180
|
+
self.related_variable_definition_uris is None
|
|
181
|
+
and "related_variable_definition_uris" in self.model_fields_set
|
|
182
|
+
):
|
|
183
|
+
_dict["related_variable_definition_uris"] = None
|
|
184
|
+
|
|
185
|
+
return _dict
|
|
186
|
+
|
|
187
|
+
@classmethod
|
|
188
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
189
|
+
"""Create an instance of Draft from a dict"""
|
|
190
|
+
if obj is None:
|
|
191
|
+
return None
|
|
192
|
+
|
|
193
|
+
if not isinstance(obj, dict):
|
|
194
|
+
return cls.model_validate(obj)
|
|
195
|
+
|
|
196
|
+
_obj = cls.model_validate(
|
|
197
|
+
{
|
|
198
|
+
"name": LanguageStringType.from_dict(obj["name"])
|
|
199
|
+
if obj.get("name") is not None
|
|
200
|
+
else None,
|
|
201
|
+
"short_name": obj.get("short_name"),
|
|
202
|
+
"definition": LanguageStringType.from_dict(obj["definition"])
|
|
203
|
+
if obj.get("definition") is not None
|
|
204
|
+
else None,
|
|
205
|
+
"classification_reference": obj.get("classification_reference"),
|
|
206
|
+
"unit_types": obj.get("unit_types"),
|
|
207
|
+
"subject_fields": obj.get("subject_fields"),
|
|
208
|
+
"contains_special_categories_of_personal_data": obj.get(
|
|
209
|
+
"contains_special_categories_of_personal_data"
|
|
210
|
+
)
|
|
211
|
+
if obj.get("contains_special_categories_of_personal_data") is not None
|
|
212
|
+
else False,
|
|
213
|
+
"measurement_type": obj.get("measurement_type"),
|
|
214
|
+
"valid_from": obj.get("valid_from"),
|
|
215
|
+
"valid_until": obj.get("valid_until"),
|
|
216
|
+
"external_reference_uri": obj.get("external_reference_uri"),
|
|
217
|
+
"comment": LanguageStringType.from_dict(obj["comment"])
|
|
218
|
+
if obj.get("comment") is not None
|
|
219
|
+
else None,
|
|
220
|
+
"related_variable_definition_uris": obj.get(
|
|
221
|
+
"related_variable_definition_uris"
|
|
222
|
+
),
|
|
223
|
+
"contact": Contact.from_dict(obj["contact"])
|
|
224
|
+
if obj.get("contact") is not None
|
|
225
|
+
else None,
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
return _obj
|