Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom Base Model #36

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/generate-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
--input-file-type jsonschema
--input src/metadata-container-json-schema.json
--output-model-type pydantic_v2.BaseModel
--base-class "datadoc_model.datadoc_base_model.DatadocBaseModel"
--use-default
--use-one-literal-as-default
--force-optional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import ConfigDict, BaseModel


class DatadocBaseModel(BaseModel):
"""Defines configuration which applies to all Models in this package."""

model_config = ConfigDict(validate_assignment=True, use_enum_values=True)
22 changes: 12 additions & 10 deletions generated/python/datadoc_model/datadoc_model/model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# generated by datamodel-codegen:
# filename: metadata-container-json-schema.json
# timestamp: 2024-01-04T14:47:13+00:00
# timestamp: 2024-01-05T12:58:00+00:00

from __future__ import annotations

from enum import Enum
from typing import Any, Literal, Optional
from uuid import UUID

from pydantic import AnyUrl, AwareDatetime, BaseModel, Field
from pydantic import AnyUrl, AwareDatetime, Field

from datadoc_model.datadoc_base_model import DatadocBaseModel


class Assessment(str, Enum):
Expand Down Expand Up @@ -48,7 +50,7 @@ class VariableRole(str, Enum):
ATTRIBUTE = "ATTRIBUTE"


class LanguageStringType(BaseModel):
class LanguageStringType(DatadocBaseModel):
en: Optional[str] = None
nn: Optional[str] = None
nb: Optional[str] = None
Expand Down Expand Up @@ -85,7 +87,7 @@ class TemporalityTypeType(str, Enum):
EVENT = "EVENT"


class PseudoDataset(BaseModel):
class PseudoDataset(DatadocBaseModel):
dataset_pseudo_time: Optional[AwareDatetime] = Field(
None,
description="Time at which the dataset was pseudonymized. In ISO 8601 format.",
Expand All @@ -105,7 +107,7 @@ class SourceVariableDatatype(str, Enum):
DATETIME = "DATETIME"


class PseudoVariable(BaseModel):
class PseudoVariable(DatadocBaseModel):
short_name: Optional[str] = Field(
None,
description="Physical name of the variable in the dataset. Should match the recommended short name.",
Expand Down Expand Up @@ -156,13 +158,13 @@ class PseudoVariable(BaseModel):
)


class PseudonymizationJsonSchema(BaseModel):
class PseudonymizationJsonSchema(DatadocBaseModel):
document_version: Literal["0.1.0"] = "0.1.0"
pseudo_dataset: Optional[PseudoDataset] = None
pseudo_variables: Optional[list[PseudoVariable]] = None


class Dataset(BaseModel):
class Dataset(DatadocBaseModel):
short_name: Optional[str] = Field(
None,
description="Name of (physical) data file, data table or dataset",
Expand Down Expand Up @@ -274,7 +276,7 @@ class Dataset(BaseModel):
)


class Variable(BaseModel):
class Variable(DatadocBaseModel):
short_name: Optional[str] = Field(
None,
description="Physical name of the variable in the dataset. Should match the recommended short name.",
Expand Down Expand Up @@ -363,7 +365,7 @@ class Variable(BaseModel):
)


class DatadocJsonSchema(BaseModel):
class DatadocJsonSchema(DatadocBaseModel):
percentage_complete: Optional[int] = Field(
None, description="Percentage of obligatory metadata fields populated."
)
Expand All @@ -374,7 +376,7 @@ class DatadocJsonSchema(BaseModel):
variables: Optional[list[Variable]] = None


class MetadataContainer(BaseModel):
class MetadataContainer(DatadocBaseModel):
document_version: Literal["0.0.1"] = "0.0.1"
datadoc: Optional[DatadocJsonSchema] = None
pseudonymization: Optional[PseudonymizationJsonSchema] = None
Loading