Skip to content

Commit 0d32f4c

Browse files
Bump datamodel-codegen to 0.25.2 (#33)
* Bump datamodel-codegen to 0.25.2 * [GENERATE] Pydantic models from JSON Schema * Python with double quotes for Black compatibility * [GENERATE] Pydantic models from JSON Schema * Bump ssb_datadoc_model to 4.1.0 --------- Co-authored-by: dapla-bot[bot] <143391972+dapla-bot[bot]@users.noreply.github.com>
1 parent e00cc20 commit 0d32f4c

File tree

3 files changed

+71
-64
lines changed

3 files changed

+71
-64
lines changed

.github/workflows/generate-python.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Install datamodel-codegen
4747
run: |
48-
python -m pipx install datamodel-code-generator==0.24.2
48+
python -m pipx install datamodel-code-generator==0.25.2
4949
5050
- name: Generate Python
5151
run: >
@@ -55,8 +55,10 @@ jobs:
5555
--output-model-type pydantic_v2.BaseModel
5656
--use-default
5757
--use-one-literal-as-default
58+
--force-optional
5859
--use-subclass-enum
5960
--use-standard-collections
61+
--use-double-quotes
6062
--target-python-version 3.10
6163
--output generated/python/datadoc_model/datadoc_model/model.py
6264

generated/python/datadoc_model/datadoc_model/model.py

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# generated by datamodel-codegen:
22
# filename: metadata-container-json-schema.json
3-
# timestamp: 2023-12-06T10:21:06+00:00
3+
# timestamp: 2024-01-04T07:49:11+00:00
44

55
from __future__ import annotations
66

7-
from datetime import datetime
87
from enum import Enum
98
from typing import Any, Literal, Optional
109
from uuid import UUID
1110

12-
from pydantic import AnyUrl, BaseModel, Field
11+
from pydantic import AnyUrl, AwareDatetime, BaseModel, Field
1312

1413

1514
class Assessment(str, Enum):
@@ -51,7 +50,7 @@ class VariableRole(str, Enum):
5150
class LanguageStringType(BaseModel):
5251
en: Optional[str] = None
5352
nn: Optional[str] = None
54-
nb: str
53+
nb: Optional[str] = None
5554

5655

5756
class UnitType(str, Enum):
@@ -86,8 +85,8 @@ class TemporalityTypeType(str, Enum):
8685

8786

8887
class PseudoDataset(BaseModel):
89-
dataset_pseudo_time: datetime = Field(
90-
...,
88+
dataset_pseudo_time: Optional[AwareDatetime] = Field(
89+
None,
9190
description="Time at which the dataset was pseudonymized. In ISO 8601 format.",
9291
title="Dataset pseudo time",
9392
)
@@ -106,8 +105,8 @@ class SourceVariableDatatype(str, Enum):
106105

107106

108107
class PseudoVariable(BaseModel):
109-
short_name: str = Field(
110-
...,
108+
short_name: Optional[str] = Field(
109+
None,
111110
description="Physical name of the variable in the dataset. Should match the recommended short name.",
112111
title="Short name",
113112
)
@@ -131,13 +130,13 @@ class PseudoVariable(BaseModel):
131130
description="Version of stable identifier the variable was mapped to prior to pseudonymization.",
132131
title="Stable identifier version",
133132
)
134-
encryption_algorithm: str = Field(
135-
...,
133+
encryption_algorithm: Optional[str] = Field(
134+
None,
136135
description="The encryption algorithm used to pseudonymize the variable.",
137136
title="Encryption algorithm",
138137
)
139-
encryption_key_reference: str = Field(
140-
...,
138+
encryption_key_reference: Optional[str] = Field(
139+
None,
141140
description="Name of or reference to the encryption key used to pseudonymize the variable.",
142141
title="Encryption key reference",
143142
)
@@ -158,30 +157,32 @@ class PseudoVariable(BaseModel):
158157

159158
class PseudonymizationJsonSchema(BaseModel):
160159
document_version: Literal["0.1.0"] = "0.1.0"
161-
pseudo_dataset: PseudoDataset
162-
pseudo_variables: list[PseudoVariable]
160+
pseudo_dataset: Optional[PseudoDataset] = None
161+
pseudo_variables: Optional[list[PseudoVariable]] = None
163162

164163

165164
class Dataset(BaseModel):
166-
short_name: str = Field(
167-
...,
165+
short_name: Optional[str] = Field(
166+
None,
168167
description="Name of (physical) data file, data table or dataset",
169168
title="Short name",
170169
)
171-
assessment: Assessment = Field(
172-
...,
170+
assessment: Optional[Assessment] = Field(
171+
None,
173172
description="Value assessment (sensitivity classification) for the data set",
174173
title="Assessment",
175174
)
176-
dataset_status: DatasetStatus = Field(
177-
..., description="Life cycle for data set", title="Data set status"
175+
dataset_status: Optional[DatasetStatus] = Field(
176+
None, description="Life cycle for data set", title="Data set status"
178177
)
179-
dataset_state: DatasetState = Field(
180-
..., description="Steady state of data", title="Data set state"
178+
dataset_state: Optional[DatasetState] = Field(
179+
None, description="Steady state of data", title="Data set state"
181180
)
182-
name: LanguageStringType = Field(..., description="Name of data set", title="Name")
183-
description: LanguageStringType = Field(
184-
..., description="Free text description of the data set", title="Description"
181+
name: Optional[LanguageStringType] = Field(
182+
None, description="Name of data set", title="Name"
183+
)
184+
description: Optional[LanguageStringType] = Field(
185+
None, description="Free text description of the data set", title="Description"
185186
)
186187
data_source: Optional[LanguageStringType] = Field(
187188
None,
@@ -191,19 +192,21 @@ class Dataset(BaseModel):
191192
register_uri: Optional[LanguageStringType] = Field(
192193
None, description="Link to register", title="Register"
193194
)
194-
population_description: LanguageStringType = Field(
195-
...,
195+
population_description: Optional[LanguageStringType] = Field(
196+
None,
196197
description="Description of the population covered in the data set. Includes unit type, spatial coverage and period of time.",
197198
title="Description of population",
198199
)
199-
version: str = Field(..., description="Version of data set", title="Version")
200+
version: Optional[str] = Field(
201+
None, description="Version of data set", title="Version"
202+
)
200203
version_description: Optional[LanguageStringType] = Field(
201204
None,
202205
description="Dataset version information in the form of descriptive text",
203206
title="Version description",
204207
)
205-
unit_type: UnitType = Field(
206-
...,
208+
unit_type: Optional[UnitType] = Field(
209+
None,
207210
description="Unit Type for data file, table or data set. See Definitions of Unit Types https://www.ssb.no/en/metadata/definisjoner-av-statistiske-enheter",
208211
title="Unit type",
209212
)
@@ -212,8 +215,8 @@ class Dataset(BaseModel):
212215
description="Temporality type. Either for the instance variable or the data set",
213216
title="Temporality type",
214217
)
215-
subject_field: LanguageStringType = Field(
216-
...,
218+
subject_field: Optional[LanguageStringType] = Field(
219+
None,
217220
description="Primary area of statistics in which the data set is included",
218221
title="Subject field",
219222
)
@@ -227,34 +230,34 @@ class Dataset(BaseModel):
227230
description="Description of the data set's spatial coverage",
228231
title="Spatial coverage description",
229232
)
230-
id: UUID = Field(
231-
..., description="Unique identifier for the data set", title="Identifier"
233+
id: Optional[UUID] = Field(
234+
None, description="Unique identifier for the data set", title="Identifier"
232235
)
233-
owner: LanguageStringType = Field(
234-
...,
236+
owner: Optional[LanguageStringType] = Field(
237+
None,
235238
description="Owner of the data set (responsible division in Statistics Norway). See also Classification of organisational units https://www.ssb.no/en/klass/klassifikasjoner/83",
236239
title="Owner",
237240
)
238-
file_path: str = Field(
239-
...,
241+
file_path: Optional[str] = Field(
242+
None,
240243
description="The file path contains the data set's name and the path to where it is stored",
241244
title="File path",
242245
)
243-
metadata_created_date: datetime = Field(
244-
...,
246+
metadata_created_date: Optional[AwareDatetime] = Field(
247+
None,
245248
description="Created date for metadata about the data set",
246249
title="Metadata created date",
247250
)
248-
metadata_created_by: str = Field(
249-
..., description="Created by identifiable person.", title="Metadata created by"
251+
metadata_created_by: Optional[str] = Field(
252+
None, description="Created by identifiable person.", title="Metadata created by"
250253
)
251-
metadata_last_updated_date: datetime = Field(
252-
...,
254+
metadata_last_updated_date: Optional[AwareDatetime] = Field(
255+
None,
253256
description="Last updated date for metadata about the dataset",
254257
title="Metadata last updated date",
255258
)
256-
metadata_last_updated_by: str = Field(
257-
...,
259+
metadata_last_updated_by: Optional[str] = Field(
260+
None,
258261
description="Last change made by identifiable person. ",
259262
title="Metadata last updated by",
260263
)
@@ -271,19 +274,21 @@ class Dataset(BaseModel):
271274

272275

273276
class Variable(BaseModel):
274-
short_name: str = Field(
275-
...,
277+
short_name: Optional[str] = Field(
278+
None,
276279
description="Physical name of the variable in the dataset. Should match the recommended short name.",
277280
title="Short name",
278281
)
279-
name: LanguageStringType = Field(
280-
...,
282+
name: Optional[LanguageStringType] = Field(
283+
None,
281284
description="Variable names can be inherited from VarDef, but can also be documented/changed here",
282285
title="Name",
283286
)
284-
data_type: DataType = Field(..., description="Data type", title="Data type")
285-
variable_role: VariableRole = Field(
286-
...,
287+
data_type: Optional[DataType] = Field(
288+
None, description="Data type", title="Data type"
289+
)
290+
variable_role: Optional[VariableRole] = Field(
291+
None,
287292
description="Role of the instance variable in the data set",
288293
title="Variable role",
289294
)
@@ -292,8 +297,8 @@ class Variable(BaseModel):
292297
description="A link (URI) to the variable's definition in Vardok/VarDef",
293298
title="Definition URI",
294299
)
295-
direct_person_identifying: bool = Field(
296-
...,
300+
direct_person_identifying: Optional[bool] = Field(
301+
None,
297302
description="Direct Person identifying Information (DPI). Some of the values \u200b\u200bin an instance variable kan be DPI, others not. In this case, DPI is set equal to true. For example, the variable exporter where some of the values \u200b\u200bcan be organization number, others social security numbers (sole proprietorships).",
298303
title="Direct Person identifying Information (DPI)",
299304
)
@@ -340,17 +345,17 @@ class Variable(BaseModel):
340345
description="Invalid value(s) description used in addition (or as an alternative) to standard sentinel values.",
341346
title="Invalid value(s) description",
342347
)
343-
id: UUID = Field(
344-
...,
348+
id: Optional[UUID] = Field(
349+
None,
345350
description="Unique SSB identifier for the instance variable in the data set",
346351
title="Identifier",
347352
)
348-
contains_data_from: Optional[datetime] = Field(
353+
contains_data_from: Optional[AwareDatetime] = Field(
349354
None,
350355
description="The instance variable in the data set contains data from and including this date. This can be useful information for data sets that contain many instance variables in addition to data for many periods/years. In many cases, it will then be the case that some variables only contain data for the most recent periods/years, e.g. if the entire data set contains data from 1970 to 2020, while some instance variables only contain data from 1998 onwards.",
351356
title="Contains data from",
352357
)
353-
contains_data_until: Optional[datetime] = Field(
358+
contains_data_until: Optional[AwareDatetime] = Field(
354359
None,
355360
description="The instance variable in the data set contains data up to and including this date. This can be useful information for data sets that contain many instance variables in addition to data for many periods/years. In many cases, it will then be the case that some of the instance variables in the data set are terminated (no longer updated) after a given point in time.",
356361
title="Contains data up until",
@@ -364,11 +369,11 @@ class DatadocJsonSchema(BaseModel):
364369
document_version: Literal["2.0.0"] = Field(
365370
"2.0.0", description="Version of this model"
366371
)
367-
dataset: Dataset
368-
variables: list[Variable]
372+
dataset: Optional[Dataset] = None
373+
variables: Optional[list[Variable]] = None
369374

370375

371376
class MetadataContainer(BaseModel):
372-
document_version: Literal["0.0.1"] = None
377+
document_version: Literal["0.0.1"] = "0.0.1"
373378
datadoc: Optional[DatadocJsonSchema] = None
374379
pseudonymization: Optional[PseudonymizationJsonSchema] = None

generated/python/datadoc_model/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ssb-datadoc-model"
3-
version = "4.0.2"
3+
version = "4.1.0"
44
description = "Data Model for use in Statistics Norway's Metadata system"
55
authors = ["Statistics Norway <stat-dev@ssb.no>"]
66
license = "MIT"

0 commit comments

Comments
 (0)