Skip to content

Commit a8021ac

Browse files
hf-kkleinKonstantin
and
Konstantin
authored
Use format: date-time instead of pattern (.yml) and AwareDatetime (.py) for datetime strings (#7)
* Use `format: date-time` (.yml) and `AwareDatetime` (.py) for datetime strings * Update README.md --------- Co-authored-by: Konstantin <[email protected]>
1 parent 2f7400e commit a8021ac

File tree

3 files changed

+25
-48
lines changed

3 files changed

+25
-48
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Most of the classes are autogenerated from the [`openapi.yml`](openapi/openapi.y
4747
Note that we fixed some errors in the official OpenAPI spec.
4848
Our changes are mentioned at the beginning of the [`openapi.yml`](openapi/openapi.yml) file.
4949

50+
https://github.com/Hochfrequenz/malo-ident-python-models/blob/fe41321c74773336984a3517adc79b3ac4f43349/openapi/openapi.yml#L4-L8
51+
5052
After updating the `openapi.yml` file, use
5153

5254
```bash

openapi/openapi.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# a) It's missing the 'measured' valued which is given as example but not part of the enum members.
66
# b) there is a typo: 'nonActice' should be 'nonActive'
77
# 2. Some yaml parsers fail, because: Multi-line double-quoted strings are not sufficiently indented (can be found with prettier in CI)
8+
# 3. Datetimes are poorly designed. Instead of using the OpenAPI format:date-time, a regex with good intentions is used. This leads to code-generators using type string instead of datetime.
89

910
openapi: 3.0.0
1011
servers:
@@ -230,7 +231,8 @@ components:
230231
example: V567345345
231232

232233
creationDateTime:
233-
pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.[\\d]{1,4})?Z"
234+
# pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.[\\d]{1,4})?Z"
235+
format: date-time # ERROR-3
234236
type: string
235237
description: Zeitpunkt an dem der Aufruf erstellt wurde
236238
example: 2023-08-01T12:30:00.1704Z
@@ -409,12 +411,14 @@ components:
409411
- consumption
410412
- production
411413
executionTimeFrom:
412-
pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\dZ"
414+
# pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\dZ"
415+
format: date-time # ERROR-3
413416
type: string
414417
description: Beginnzeitpunkt, Zeitpunkt zu dem die zugeordneten Marktpartner oder Lokationen zugeordnet werden. Dieser Zeitpunkt muss ein Tagesbeginn 00:00 Uhr gesetzlicher deutscher Zeit sein.
415418
example: 2023-08-01T22:00:00Z
416419
executionTimeUntil:
417-
pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\dZ"
420+
# pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\dZ"
421+
format: date-time # ERROR-3
418422
type: string
419423
description: Endezeitpunkt, Zeitpunkt bis zu dem die zugeordneten Marktpartner oder Lokationen zugeordnet werden. Dieser Zeitpunkt muss ein Tagesbeginn 00:00 Uhr gesetzlicher deutscher Zeit sein.
420424
example: 2023-08-01T22:00:00Z
@@ -454,7 +458,8 @@ components:
454458
description: Angabe der Hausnummernergänzung der Marktlokationsadresse
455459
example: F
456460
identificationDateTime:
457-
pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\dZ"
461+
# pattern: "20(\\d{2}(\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01])|\\-02\\-(0[1-9]|1\\d|2[0-8])|\\-(0[469]|11)\\-(0[1-9]|[12]\\d|30))|([02468][048]|[13579][26])\\-02\\-(29))T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\dZ"
462+
format: date-time
458463
type: string
459464
description: Zeitpunkt zu dem die Identifikation stattfinden soll. Dieser Zeitpunkt muss ein Tagesbeginn 00:00 Uhr gesetzlicher deutscher Zeit sein.
460465
example: 2023-08-02T22:00:00Z
@@ -573,10 +578,10 @@ components:
573578
marketLocationProperty:
574579
type: string
575580
description: Eigenschaft der Marktlokation. nonActive=ruhende Marktlokation, customerFacility=Marktlokation ist eine Kundenanlage, standard=alle "Standard" Marktlokationen die nicht unter die Eigenschaft "ruhende Marktlokation" und "Kundenanlage" fallen.
576-
example: measured # this is probably a copy-paste error
581+
example: measured # ERROR-1a) this is probably a copy-paste error
577582
enum:
578583
- customerFacility
579-
- nonActive # was 'nonActice' before
584+
- nonActive # ERROR-1b) was 'nonActice' before
580585
- standard
581586

582587
marketLocationSupplier:

src/maloident/_autogenerated.py

+12-42
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# generated by datamodel-codegen:
22
# filename: openapi.yml
3-
# timestamp: 2024-09-25T17:15:02+00:00
3+
# timestamp: 2024-10-02T11:39:11+00:00
44

55
from __future__ import annotations
66

77
from enum import Enum
88
from typing import List, Optional
99

10-
from pydantic import BaseModel, Field, RootModel, constr
10+
from pydantic import AwareDatetime, BaseModel, Field, RootModel, constr
1111

1212

1313
class City(RootModel[str]):
@@ -32,16 +32,10 @@ class CustomerNumber(RootModel[str]):
3232
)
3333

3434

35-
class CreationDateTime(
36-
RootModel[
37-
constr(
38-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.[\d]{1,4})?Z"
39-
)
40-
]
41-
):
42-
root: constr(
43-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.[\d]{1,4})?Z"
44-
) = Field(..., description="Zeitpunkt an dem der Aufruf erstellt wurde", examples=["2023-08-01T12:30:00.1704Z"])
35+
class CreationDateTime(RootModel[AwareDatetime]):
36+
root: AwareDatetime = Field(
37+
..., description="Zeitpunkt an dem der Aufruf erstellt wurde", examples=["2023-08-01T12:30:00.1704Z"]
38+
)
4539

4640

4741
class DistrictName(RootModel[str]):
@@ -66,32 +60,16 @@ class EnergyDirection(Enum):
6660
production = "production"
6761

6862

69-
class ExecutionTimeFrom(
70-
RootModel[
71-
constr(
72-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\dZ"
73-
)
74-
]
75-
):
76-
root: constr(
77-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\dZ"
78-
) = Field(
63+
class ExecutionTimeFrom(RootModel[AwareDatetime]):
64+
root: AwareDatetime = Field(
7965
...,
8066
description="Beginnzeitpunkt, Zeitpunkt zu dem die zugeordneten Marktpartner oder Lokationen zugeordnet werden. Dieser Zeitpunkt muss ein Tagesbeginn 00:00 Uhr gesetzlicher deutscher Zeit sein.",
8167
examples=["2023-08-01T22:00:00Z"],
8268
)
8369

8470

85-
class ExecutionTimeUntil(
86-
RootModel[
87-
constr(
88-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\dZ"
89-
)
90-
]
91-
):
92-
root: constr(
93-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\dZ"
94-
) = Field(
71+
class ExecutionTimeUntil(RootModel[AwareDatetime]):
72+
root: AwareDatetime = Field(
9573
...,
9674
description="Endezeitpunkt, Zeitpunkt bis zu dem die zugeordneten Marktpartner oder Lokationen zugeordnet werden. Dieser Zeitpunkt muss ein Tagesbeginn 00:00 Uhr gesetzlicher deutscher Zeit sein.",
9775
examples=["2023-08-01T22:00:00Z"],
@@ -118,16 +96,8 @@ class HouseNumberAddition(RootModel[str]):
11896
root: str = Field(..., description="Angabe der Hausnummernergänzung der Marktlokationsadresse", examples=["F"])
11997

12098

121-
class IdentificationDateTime(
122-
RootModel[
123-
constr(
124-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\dZ"
125-
)
126-
]
127-
):
128-
root: constr(
129-
pattern=r"20(\d{2}(\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01])|\-02\-(0[1-9]|1\d|2[0-8])|\-(0[469]|11)\-(0[1-9]|[12]\d|30))|([02468][048]|[13579][26])\-02\-(29))T([01]\d|2[0-3]):[0-5]\d:[0-5]\dZ"
130-
) = Field(
99+
class IdentificationDateTime(RootModel[AwareDatetime]):
100+
root: AwareDatetime = Field(
131101
...,
132102
description="Zeitpunkt zu dem die Identifikation stattfinden soll. Dieser Zeitpunkt muss ein Tagesbeginn 00:00 Uhr gesetzlicher deutscher Zeit sein.",
133103
examples=["2023-08-02T22:00:00Z"],

0 commit comments

Comments
 (0)