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,118 @@
|
|
|
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 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 pydantic import StrictStr
|
|
25
|
+
from typing_extensions import Self
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Problem(BaseModel):
|
|
29
|
+
"""Problem"""
|
|
30
|
+
|
|
31
|
+
type: StrictStr | None = Field(
|
|
32
|
+
default="about:blank",
|
|
33
|
+
description="A URI reference that uniquely identifies the problem type only in the context of the provided API. Opposed to the specification in RFC-9457, it is neither recommended to be dereferenceable and point to a human-readable documentation nor globally unique for the problem type. ",
|
|
34
|
+
)
|
|
35
|
+
title: StrictStr | None = Field(
|
|
36
|
+
default=None,
|
|
37
|
+
description="A short summary of the problem type. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized. ",
|
|
38
|
+
)
|
|
39
|
+
status: Annotated[int, Field(lt=600, strict=True, ge=100)] | None = Field(
|
|
40
|
+
default=None,
|
|
41
|
+
description="The HTTP status code generated by the origin server for this occurrence of the problem. ",
|
|
42
|
+
)
|
|
43
|
+
detail: StrictStr | None = Field(
|
|
44
|
+
default=None,
|
|
45
|
+
description="A human readable explanation specific to this occurrence of the problem that is helpful to locate the problem and give advice on how to proceed. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized. ",
|
|
46
|
+
)
|
|
47
|
+
instance: StrictStr | None = Field(
|
|
48
|
+
default=None,
|
|
49
|
+
description="A URI reference that identifies the specific occurrence of the problem, e.g. by adding a fragment identifier or sub-path to the problem type. May be used to locate the root of this problem in the source code. ",
|
|
50
|
+
)
|
|
51
|
+
__properties: ClassVar[list[str]] = [
|
|
52
|
+
"type",
|
|
53
|
+
"title",
|
|
54
|
+
"status",
|
|
55
|
+
"detail",
|
|
56
|
+
"instance",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
model_config = ConfigDict(
|
|
60
|
+
populate_by_name=True,
|
|
61
|
+
validate_assignment=True,
|
|
62
|
+
protected_namespaces=(),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def to_str(self) -> str:
|
|
66
|
+
"""Returns the string representation of the model using alias"""
|
|
67
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
68
|
+
|
|
69
|
+
def to_json(self) -> str:
|
|
70
|
+
"""Returns the JSON representation of the model using alias"""
|
|
71
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
72
|
+
return json.dumps(self.to_dict())
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
76
|
+
"""Create an instance of Problem from a JSON string"""
|
|
77
|
+
return cls.from_dict(json.loads(json_str))
|
|
78
|
+
|
|
79
|
+
def to_dict(self) -> dict[str, Any]:
|
|
80
|
+
"""Return the dictionary representation of the model using alias.
|
|
81
|
+
|
|
82
|
+
This has the following differences from calling pydantic's
|
|
83
|
+
`self.model_dump(by_alias=True)`:
|
|
84
|
+
|
|
85
|
+
* `None` is only added to the output dict for nullable fields that
|
|
86
|
+
were set at model initialization. Other fields with value `None`
|
|
87
|
+
are ignored.
|
|
88
|
+
"""
|
|
89
|
+
excluded_fields: set[str] = set([])
|
|
90
|
+
|
|
91
|
+
_dict = self.model_dump(
|
|
92
|
+
by_alias=True,
|
|
93
|
+
exclude=excluded_fields,
|
|
94
|
+
exclude_none=True,
|
|
95
|
+
)
|
|
96
|
+
return _dict
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
100
|
+
"""Create an instance of Problem from a dict"""
|
|
101
|
+
if obj is None:
|
|
102
|
+
return None
|
|
103
|
+
|
|
104
|
+
if not isinstance(obj, dict):
|
|
105
|
+
return cls.model_validate(obj)
|
|
106
|
+
|
|
107
|
+
_obj = cls.model_validate(
|
|
108
|
+
{
|
|
109
|
+
"type": obj.get("type")
|
|
110
|
+
if obj.get("type") is not None
|
|
111
|
+
else "about:blank",
|
|
112
|
+
"title": obj.get("title"),
|
|
113
|
+
"status": obj.get("status"),
|
|
114
|
+
"detail": obj.get("detail"),
|
|
115
|
+
"instance": obj.get("instance"),
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
return _obj
|
|
@@ -0,0 +1,274 @@
|
|
|
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
|
+
from ..models.owner import Owner
|
|
33
|
+
from ..models.variable_status import VariableStatus
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class UpdateDraft(BaseModel):
|
|
37
|
+
"""Update variable definition Data structure with all fields optional for updating a Draft Variable Definition."""
|
|
38
|
+
|
|
39
|
+
name: LanguageStringType | None = None
|
|
40
|
+
short_name: Annotated[str, Field(strict=True)] | None = Field(
|
|
41
|
+
default=None,
|
|
42
|
+
description="Recommended short name. Must be unique within an organization.",
|
|
43
|
+
)
|
|
44
|
+
definition: LanguageStringType | None = None
|
|
45
|
+
classification_reference: StrictStr | None = Field(
|
|
46
|
+
default=None,
|
|
47
|
+
description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
|
|
48
|
+
)
|
|
49
|
+
unit_types: list[Annotated[str, Field(min_length=1, strict=True)]] | None = Field(
|
|
50
|
+
default=None,
|
|
51
|
+
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.",
|
|
52
|
+
)
|
|
53
|
+
subject_fields: list[Annotated[str, Field(min_length=1, strict=True)]] | None = (
|
|
54
|
+
Field(
|
|
55
|
+
default=None,
|
|
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
|
+
)
|
|
59
|
+
contains_special_categories_of_personal_data: StrictBool | None = Field(
|
|
60
|
+
default=None,
|
|
61
|
+
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",
|
|
62
|
+
)
|
|
63
|
+
variable_status: VariableStatus | None = None
|
|
64
|
+
measurement_type: StrictStr | None = Field(
|
|
65
|
+
default=None,
|
|
66
|
+
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",
|
|
67
|
+
)
|
|
68
|
+
valid_from: date | None = Field(
|
|
69
|
+
default=None,
|
|
70
|
+
description="The variable definition is valid from this date inclusive",
|
|
71
|
+
)
|
|
72
|
+
valid_until: date | None = None
|
|
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 | None = None
|
|
82
|
+
contact: Contact | None = None
|
|
83
|
+
__properties: ClassVar[list[str]] = [
|
|
84
|
+
"name",
|
|
85
|
+
"short_name",
|
|
86
|
+
"definition",
|
|
87
|
+
"classification_reference",
|
|
88
|
+
"unit_types",
|
|
89
|
+
"subject_fields",
|
|
90
|
+
"contains_special_categories_of_personal_data",
|
|
91
|
+
"variable_status",
|
|
92
|
+
"measurement_type",
|
|
93
|
+
"valid_from",
|
|
94
|
+
"valid_until",
|
|
95
|
+
"external_reference_uri",
|
|
96
|
+
"comment",
|
|
97
|
+
"related_variable_definition_uris",
|
|
98
|
+
"owner",
|
|
99
|
+
"contact",
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
@field_validator("short_name")
|
|
103
|
+
def short_name_validate_regular_expression(cls, value):
|
|
104
|
+
"""Validates the regular expression"""
|
|
105
|
+
if value is None:
|
|
106
|
+
return value
|
|
107
|
+
|
|
108
|
+
if not re.match(r"^[a-z0-9_]{2,}$", value):
|
|
109
|
+
raise ValueError(r"must validate the regular expression /^[a-z0-9_]{2,}$/")
|
|
110
|
+
return value
|
|
111
|
+
|
|
112
|
+
model_config = ConfigDict(
|
|
113
|
+
populate_by_name=True,
|
|
114
|
+
validate_assignment=True,
|
|
115
|
+
protected_namespaces=(),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
def to_str(self) -> str:
|
|
119
|
+
"""Returns the string representation of the model using alias"""
|
|
120
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
121
|
+
|
|
122
|
+
def to_json(self) -> str:
|
|
123
|
+
"""Returns the JSON representation of the model using alias"""
|
|
124
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
125
|
+
return json.dumps(self.to_dict())
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
129
|
+
"""Create an instance of UpdateDraft from a JSON string"""
|
|
130
|
+
return cls.from_dict(json.loads(json_str))
|
|
131
|
+
|
|
132
|
+
def to_dict(self) -> dict[str, Any]:
|
|
133
|
+
"""Return the dictionary representation of the model using alias.
|
|
134
|
+
|
|
135
|
+
This has the following differences from calling pydantic's
|
|
136
|
+
`self.model_dump(by_alias=True)`:
|
|
137
|
+
|
|
138
|
+
* `None` is only added to the output dict for nullable fields that
|
|
139
|
+
were set at model initialization. Other fields with value `None`
|
|
140
|
+
are ignored.
|
|
141
|
+
"""
|
|
142
|
+
excluded_fields: set[str] = set([])
|
|
143
|
+
|
|
144
|
+
_dict = self.model_dump(
|
|
145
|
+
by_alias=True,
|
|
146
|
+
exclude=excluded_fields,
|
|
147
|
+
exclude_none=True,
|
|
148
|
+
)
|
|
149
|
+
# override the default output from pydantic by calling `to_dict()` of name
|
|
150
|
+
if self.name:
|
|
151
|
+
_dict["name"] = self.name.to_dict()
|
|
152
|
+
# override the default output from pydantic by calling `to_dict()` of definition
|
|
153
|
+
if self.definition:
|
|
154
|
+
_dict["definition"] = self.definition.to_dict()
|
|
155
|
+
# override the default output from pydantic by calling `to_dict()` of comment
|
|
156
|
+
if self.comment:
|
|
157
|
+
_dict["comment"] = self.comment.to_dict()
|
|
158
|
+
# override the default output from pydantic by calling `to_dict()` of owner
|
|
159
|
+
if self.owner:
|
|
160
|
+
_dict["owner"] = self.owner.to_dict()
|
|
161
|
+
# override the default output from pydantic by calling `to_dict()` of contact
|
|
162
|
+
if self.contact:
|
|
163
|
+
_dict["contact"] = self.contact.to_dict()
|
|
164
|
+
# set to None if short_name (nullable) is None
|
|
165
|
+
# and model_fields_set contains the field
|
|
166
|
+
if self.short_name is None and "short_name" in self.model_fields_set:
|
|
167
|
+
_dict["short_name"] = None
|
|
168
|
+
|
|
169
|
+
# set to None if classification_reference (nullable) is None
|
|
170
|
+
# and model_fields_set contains the field
|
|
171
|
+
if (
|
|
172
|
+
self.classification_reference is None
|
|
173
|
+
and "classification_reference" in self.model_fields_set
|
|
174
|
+
):
|
|
175
|
+
_dict["classification_reference"] = None
|
|
176
|
+
|
|
177
|
+
# set to None if unit_types (nullable) is None
|
|
178
|
+
# and model_fields_set contains the field
|
|
179
|
+
if self.unit_types is None and "unit_types" in self.model_fields_set:
|
|
180
|
+
_dict["unit_types"] = None
|
|
181
|
+
|
|
182
|
+
# set to None if subject_fields (nullable) is None
|
|
183
|
+
# and model_fields_set contains the field
|
|
184
|
+
if self.subject_fields is None and "subject_fields" in self.model_fields_set:
|
|
185
|
+
_dict["subject_fields"] = None
|
|
186
|
+
|
|
187
|
+
# set to None if contains_special_categories_of_personal_data (nullable) is None
|
|
188
|
+
# and model_fields_set contains the field
|
|
189
|
+
if (
|
|
190
|
+
self.contains_special_categories_of_personal_data is None
|
|
191
|
+
and "contains_special_categories_of_personal_data" in self.model_fields_set
|
|
192
|
+
):
|
|
193
|
+
_dict["contains_special_categories_of_personal_data"] = None
|
|
194
|
+
|
|
195
|
+
# set to None if measurement_type (nullable) is None
|
|
196
|
+
# and model_fields_set contains the field
|
|
197
|
+
if (
|
|
198
|
+
self.measurement_type is None
|
|
199
|
+
and "measurement_type" in self.model_fields_set
|
|
200
|
+
):
|
|
201
|
+
_dict["measurement_type"] = None
|
|
202
|
+
|
|
203
|
+
# set to None if valid_from (nullable) is None
|
|
204
|
+
# and model_fields_set contains the field
|
|
205
|
+
if self.valid_from is None and "valid_from" in self.model_fields_set:
|
|
206
|
+
_dict["valid_from"] = None
|
|
207
|
+
|
|
208
|
+
# set to None if valid_until (nullable) is None
|
|
209
|
+
# and model_fields_set contains the field
|
|
210
|
+
if self.valid_until is None and "valid_until" in self.model_fields_set:
|
|
211
|
+
_dict["valid_until"] = None
|
|
212
|
+
|
|
213
|
+
# set to None if external_reference_uri (nullable) is None
|
|
214
|
+
# and model_fields_set contains the field
|
|
215
|
+
if (
|
|
216
|
+
self.external_reference_uri is None
|
|
217
|
+
and "external_reference_uri" in self.model_fields_set
|
|
218
|
+
):
|
|
219
|
+
_dict["external_reference_uri"] = None
|
|
220
|
+
|
|
221
|
+
# set to None if related_variable_definition_uris (nullable) is None
|
|
222
|
+
# and model_fields_set contains the field
|
|
223
|
+
if (
|
|
224
|
+
self.related_variable_definition_uris is None
|
|
225
|
+
and "related_variable_definition_uris" in self.model_fields_set
|
|
226
|
+
):
|
|
227
|
+
_dict["related_variable_definition_uris"] = None
|
|
228
|
+
|
|
229
|
+
return _dict
|
|
230
|
+
|
|
231
|
+
@classmethod
|
|
232
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
233
|
+
"""Create an instance of UpdateDraft from a dict"""
|
|
234
|
+
if obj is None:
|
|
235
|
+
return None
|
|
236
|
+
|
|
237
|
+
if not isinstance(obj, dict):
|
|
238
|
+
return cls.model_validate(obj)
|
|
239
|
+
|
|
240
|
+
_obj = cls.model_validate(
|
|
241
|
+
{
|
|
242
|
+
"name": LanguageStringType.from_dict(obj["name"])
|
|
243
|
+
if obj.get("name") is not None
|
|
244
|
+
else None,
|
|
245
|
+
"short_name": obj.get("short_name"),
|
|
246
|
+
"definition": LanguageStringType.from_dict(obj["definition"])
|
|
247
|
+
if obj.get("definition") is not None
|
|
248
|
+
else None,
|
|
249
|
+
"classification_reference": obj.get("classification_reference"),
|
|
250
|
+
"unit_types": obj.get("unit_types"),
|
|
251
|
+
"subject_fields": obj.get("subject_fields"),
|
|
252
|
+
"contains_special_categories_of_personal_data": obj.get(
|
|
253
|
+
"contains_special_categories_of_personal_data"
|
|
254
|
+
),
|
|
255
|
+
"variable_status": obj.get("variable_status"),
|
|
256
|
+
"measurement_type": obj.get("measurement_type"),
|
|
257
|
+
"valid_from": obj.get("valid_from"),
|
|
258
|
+
"valid_until": obj.get("valid_until"),
|
|
259
|
+
"external_reference_uri": obj.get("external_reference_uri"),
|
|
260
|
+
"comment": LanguageStringType.from_dict(obj["comment"])
|
|
261
|
+
if obj.get("comment") is not None
|
|
262
|
+
else None,
|
|
263
|
+
"related_variable_definition_uris": obj.get(
|
|
264
|
+
"related_variable_definition_uris"
|
|
265
|
+
),
|
|
266
|
+
"owner": Owner.from_dict(obj["owner"])
|
|
267
|
+
if obj.get("owner") is not None
|
|
268
|
+
else None,
|
|
269
|
+
"contact": Contact.from_dict(obj["contact"])
|
|
270
|
+
if obj.get("contact") is not None
|
|
271
|
+
else None,
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
return _obj
|
|
@@ -0,0 +1,225 @@
|
|
|
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 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 typing_extensions import Self
|
|
28
|
+
|
|
29
|
+
from ..models.contact import Contact
|
|
30
|
+
from ..models.language_string_type import LanguageStringType
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ValidityPeriod(BaseModel):
|
|
34
|
+
"""Create a new Validity Period on a Published Variable Definition."""
|
|
35
|
+
|
|
36
|
+
name: LanguageStringType | None = None
|
|
37
|
+
definition: LanguageStringType
|
|
38
|
+
classification_reference: StrictStr | None = Field(
|
|
39
|
+
default=None,
|
|
40
|
+
description="ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable.",
|
|
41
|
+
)
|
|
42
|
+
unit_types: list[Annotated[str, Field(min_length=1, strict=True)]] | None = Field(
|
|
43
|
+
default=None,
|
|
44
|
+
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.",
|
|
45
|
+
)
|
|
46
|
+
subject_fields: list[Annotated[str, Field(min_length=1, strict=True)]] | None = (
|
|
47
|
+
Field(
|
|
48
|
+
default=None,
|
|
49
|
+
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.",
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
contains_special_categories_of_personal_data: StrictBool | None = Field(
|
|
53
|
+
default=None,
|
|
54
|
+
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",
|
|
55
|
+
)
|
|
56
|
+
measurement_type: StrictStr | None = Field(
|
|
57
|
+
default=None,
|
|
58
|
+
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",
|
|
59
|
+
)
|
|
60
|
+
valid_from: date = Field(
|
|
61
|
+
description="The variable definition is valid from this date inclusive"
|
|
62
|
+
)
|
|
63
|
+
external_reference_uri: StrictStr | None = Field(
|
|
64
|
+
default=None, description="A link (URI) to an external definition/documentation"
|
|
65
|
+
)
|
|
66
|
+
comment: LanguageStringType | None = None
|
|
67
|
+
related_variable_definition_uris: list[StrictStr] | None = Field(
|
|
68
|
+
default=None,
|
|
69
|
+
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.",
|
|
70
|
+
)
|
|
71
|
+
contact: Contact | None = None
|
|
72
|
+
__properties: ClassVar[list[str]] = [
|
|
73
|
+
"name",
|
|
74
|
+
"definition",
|
|
75
|
+
"classification_reference",
|
|
76
|
+
"unit_types",
|
|
77
|
+
"subject_fields",
|
|
78
|
+
"contains_special_categories_of_personal_data",
|
|
79
|
+
"measurement_type",
|
|
80
|
+
"valid_from",
|
|
81
|
+
"external_reference_uri",
|
|
82
|
+
"comment",
|
|
83
|
+
"related_variable_definition_uris",
|
|
84
|
+
"contact",
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
model_config = ConfigDict(
|
|
88
|
+
populate_by_name=True,
|
|
89
|
+
validate_assignment=True,
|
|
90
|
+
protected_namespaces=(),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def to_str(self) -> str:
|
|
94
|
+
"""Returns the string representation of the model using alias"""
|
|
95
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
96
|
+
|
|
97
|
+
def to_json(self) -> str:
|
|
98
|
+
"""Returns the JSON representation of the model using alias"""
|
|
99
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
100
|
+
return json.dumps(self.to_dict())
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
104
|
+
"""Create an instance of ValidityPeriod from a JSON string"""
|
|
105
|
+
return cls.from_dict(json.loads(json_str))
|
|
106
|
+
|
|
107
|
+
def to_dict(self) -> dict[str, Any]:
|
|
108
|
+
"""Return the dictionary representation of the model using alias.
|
|
109
|
+
|
|
110
|
+
This has the following differences from calling pydantic's
|
|
111
|
+
`self.model_dump(by_alias=True)`:
|
|
112
|
+
|
|
113
|
+
* `None` is only added to the output dict for nullable fields that
|
|
114
|
+
were set at model initialization. Other fields with value `None`
|
|
115
|
+
are ignored.
|
|
116
|
+
"""
|
|
117
|
+
excluded_fields: set[str] = set([])
|
|
118
|
+
|
|
119
|
+
_dict = self.model_dump(
|
|
120
|
+
by_alias=True,
|
|
121
|
+
exclude=excluded_fields,
|
|
122
|
+
exclude_none=True,
|
|
123
|
+
)
|
|
124
|
+
# override the default output from pydantic by calling `to_dict()` of name
|
|
125
|
+
if self.name:
|
|
126
|
+
_dict["name"] = self.name.to_dict()
|
|
127
|
+
# override the default output from pydantic by calling `to_dict()` of definition
|
|
128
|
+
if self.definition:
|
|
129
|
+
_dict["definition"] = self.definition.to_dict()
|
|
130
|
+
# override the default output from pydantic by calling `to_dict()` of comment
|
|
131
|
+
if self.comment:
|
|
132
|
+
_dict["comment"] = self.comment.to_dict()
|
|
133
|
+
# override the default output from pydantic by calling `to_dict()` of contact
|
|
134
|
+
if self.contact:
|
|
135
|
+
_dict["contact"] = self.contact.to_dict()
|
|
136
|
+
# set to None if classification_reference (nullable) is None
|
|
137
|
+
# and model_fields_set contains the field
|
|
138
|
+
if (
|
|
139
|
+
self.classification_reference is None
|
|
140
|
+
and "classification_reference" in self.model_fields_set
|
|
141
|
+
):
|
|
142
|
+
_dict["classification_reference"] = None
|
|
143
|
+
|
|
144
|
+
# set to None if unit_types (nullable) is None
|
|
145
|
+
# and model_fields_set contains the field
|
|
146
|
+
if self.unit_types is None and "unit_types" in self.model_fields_set:
|
|
147
|
+
_dict["unit_types"] = None
|
|
148
|
+
|
|
149
|
+
# set to None if subject_fields (nullable) is None
|
|
150
|
+
# and model_fields_set contains the field
|
|
151
|
+
if self.subject_fields is None and "subject_fields" in self.model_fields_set:
|
|
152
|
+
_dict["subject_fields"] = None
|
|
153
|
+
|
|
154
|
+
# set to None if contains_special_categories_of_personal_data (nullable) is None
|
|
155
|
+
# and model_fields_set contains the field
|
|
156
|
+
if (
|
|
157
|
+
self.contains_special_categories_of_personal_data is None
|
|
158
|
+
and "contains_special_categories_of_personal_data" in self.model_fields_set
|
|
159
|
+
):
|
|
160
|
+
_dict["contains_special_categories_of_personal_data"] = None
|
|
161
|
+
|
|
162
|
+
# set to None if measurement_type (nullable) is None
|
|
163
|
+
# and model_fields_set contains the field
|
|
164
|
+
if (
|
|
165
|
+
self.measurement_type is None
|
|
166
|
+
and "measurement_type" in self.model_fields_set
|
|
167
|
+
):
|
|
168
|
+
_dict["measurement_type"] = None
|
|
169
|
+
|
|
170
|
+
# set to None if external_reference_uri (nullable) is None
|
|
171
|
+
# and model_fields_set contains the field
|
|
172
|
+
if (
|
|
173
|
+
self.external_reference_uri is None
|
|
174
|
+
and "external_reference_uri" in self.model_fields_set
|
|
175
|
+
):
|
|
176
|
+
_dict["external_reference_uri"] = None
|
|
177
|
+
|
|
178
|
+
# set to None if related_variable_definition_uris (nullable) is None
|
|
179
|
+
# and model_fields_set contains the field
|
|
180
|
+
if (
|
|
181
|
+
self.related_variable_definition_uris is None
|
|
182
|
+
and "related_variable_definition_uris" in self.model_fields_set
|
|
183
|
+
):
|
|
184
|
+
_dict["related_variable_definition_uris"] = None
|
|
185
|
+
|
|
186
|
+
return _dict
|
|
187
|
+
|
|
188
|
+
@classmethod
|
|
189
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
190
|
+
"""Create an instance of ValidityPeriod from a dict"""
|
|
191
|
+
if obj is None:
|
|
192
|
+
return None
|
|
193
|
+
|
|
194
|
+
if not isinstance(obj, dict):
|
|
195
|
+
return cls.model_validate(obj)
|
|
196
|
+
|
|
197
|
+
_obj = cls.model_validate(
|
|
198
|
+
{
|
|
199
|
+
"name": LanguageStringType.from_dict(obj["name"])
|
|
200
|
+
if obj.get("name") is not None
|
|
201
|
+
else None,
|
|
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
|
+
"measurement_type": obj.get("measurement_type"),
|
|
212
|
+
"valid_from": obj.get("valid_from"),
|
|
213
|
+
"external_reference_uri": obj.get("external_reference_uri"),
|
|
214
|
+
"comment": LanguageStringType.from_dict(obj["comment"])
|
|
215
|
+
if obj.get("comment") is not None
|
|
216
|
+
else None,
|
|
217
|
+
"related_variable_definition_uris": obj.get(
|
|
218
|
+
"related_variable_definition_uris"
|
|
219
|
+
),
|
|
220
|
+
"contact": Contact.from_dict(obj["contact"])
|
|
221
|
+
if obj.get("contact") is not None
|
|
222
|
+
else None,
|
|
223
|
+
}
|
|
224
|
+
)
|
|
225
|
+
return _obj
|