Skip to content

Commit 402f7a0

Browse files
authored
Do not use model order (#3)
* do not use model order * use user version
1 parent ac58906 commit 402f7a0

File tree

24 files changed

+11635
-11643
lines changed

24 files changed

+11635
-11643
lines changed

gen_models.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def process_specs(self):
9494
for spec_file in core_dir.glob("**/*.json"):
9595
api_name = "core"
9696
# core api has a v0.0.1 in the spec but that will change
97-
# for now use v1alpha1
98-
api_version = "v1alpha1"
97+
# for now use the version provided by a user from the cmd
98+
api_version = self.version
9999
logger.debug(f"API name: {api_name}, API version: {api_version}")
100100
self.sanitize_schema_objects(spec_file, api_name, api_version)
101101
self.generate_classes_for_spec(spec_file, api_name, api_version)
@@ -142,7 +142,9 @@ def generate_classes_for_spec(
142142
"--collapse-root-models",
143143
"--disable-timestamp",
144144
"--reuse-model",
145-
"--keep-model-order",
145+
# can't use model order, since Topologies are defined before Topology
146+
# maybe worth fixing the order in the model
147+
# "--keep-model-order",
146148
"--use-schema-description",
147149
"--enum-field-as-literal",
148150
"all",
@@ -184,16 +186,6 @@ def sanitize_schema_objects(self, spec_file: Path, api_name: str, api_version: s
184186
# when flipped to true it means we need to write the in-mem file to disk in the output dir
185187
modified = False
186188

187-
# Check and fix the info.title field if it has a trailing dot
188-
# if "info" in spec_data and "title" in spec_data["info"]:
189-
# title = spec_data["info"]["title"]
190-
# if title.endswith("."):
191-
# spec_data["info"]["title"] = title.rstrip(".")
192-
# logger.debug(
193-
# f"Removed trailing dot from title: {title} -> {spec_data['info']['title']}"
194-
# )
195-
# modified = True
196-
197189
schemas = spec_data["components"]["schemas"]
198190
new_schemas = {}
199191

pydantic_eda/apps/aaa/v1alpha1/models.py

Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
from pydantic import BaseModel, Field, RootModel
77

88

9-
class AppGroup(BaseModel):
10-
apiVersion: Optional[str] = None
11-
kind: Optional[str] = None
12-
name: Optional[str] = None
13-
preferredVersion: Optional[AppGroupVersion] = None
14-
versions: Optional[List[AppGroupVersion]] = None
15-
16-
179
class AppGroupVersion(BaseModel):
1810
groupVersion: Optional[str] = None
1911
version: Optional[str] = None
@@ -83,60 +75,80 @@ class K8SPatchOp(BaseModel):
8375
x_permissive: Annotated[Optional[bool], Field(alias="x-permissive")] = None
8476

8577

86-
class NodeGroup(BaseModel):
87-
"""
88-
NodeGroup is the Schema for the nodegroups API
89-
"""
78+
class Patch(RootModel[List[K8SPatchOp]]):
79+
root: List[K8SPatchOp]
9080

91-
apiVersion: str
92-
kind: str
93-
metadata: NodeGroupMetadata
94-
spec: Annotated[
95-
NodeGroupSpec,
96-
Field(
97-
description="NodeGroup is a representation of a group on a node, including the services it has access to, any RBAC, and TACACS configuration.\nNodeGroups are deployed to nodes by NodeUser or other permission-consuming resources.",
98-
title="Specification",
99-
),
100-
]
101-
status: Annotated[
102-
Optional[NodeGroupStatus],
103-
Field(description="Deployment status of this NodeGroup.", title="Status"),
104-
] = None
10581

82+
class Resource(BaseModel):
83+
kind: Optional[str] = None
84+
name: Optional[str] = None
85+
namespaced: Optional[bool] = None
86+
readOnly: Optional[bool] = None
87+
singularName: Optional[str] = None
88+
uiCategory: Optional[str] = None
10689

107-
class NodeGroupDeletedResourceEntry(BaseModel):
90+
91+
class ResourceHistoryEntry(BaseModel):
92+
author: Optional[str] = None
93+
changeType: Optional[str] = None
10894
commitTime: Optional[str] = None
10995
hash: Optional[str] = None
110-
name: Optional[str] = None
111-
namespace: Optional[str] = None
96+
message: Optional[str] = None
11297
transactionId: Optional[int] = None
11398

11499

115-
class NodeGroupDeletedResources(RootModel[List[NodeGroupDeletedResourceEntry]]):
116-
root: List[NodeGroupDeletedResourceEntry]
100+
class ResourceList(BaseModel):
101+
apiVersion: Optional[str] = None
102+
groupVersion: Optional[str] = None
103+
kind: Optional[str] = None
104+
resources: Optional[List[Resource]] = None
117105

118106

119-
class NodeGroupList(BaseModel):
120-
"""
121-
NodeGroupList is a list of nodegroups
122-
"""
107+
class StatusDetails(BaseModel):
108+
group: Optional[str] = None
109+
kind: Optional[str] = None
110+
name: Optional[str] = None
123111

124-
apiVersion: str
125-
items: Optional[List[NodeGroup]] = None
126-
kind: str
112+
113+
class UIResult(RootModel[str]):
114+
root: str
127115

128116

129-
class NodeGroupMetadata(BaseModel):
130-
annotations: Optional[Dict[str, str]] = None
131-
labels: Optional[Dict[str, str]] = None
132-
name: Annotated[
133-
str,
117+
class NodeGroupSpecRule(BaseModel):
118+
action: Annotated[
119+
Literal["Deny", "ReadWrite", "Read"],
120+
Field(description="Set the action for this entry.", title="Action"),
121+
]
122+
match: Annotated[
123+
Optional[str],
134124
Field(
135-
max_length=253,
136-
pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$",
125+
description='Set the match for this entry. This is a string to match input against - for example "interface" for srl or "configure port" for sros.\nRules here should be specified in the target specific format.',
126+
title="Match",
127+
),
128+
] = None
129+
operatingSystem: Annotated[
130+
Literal["srl", "sros"],
131+
Field(
132+
description="Operating system to match against for this rule.\nOperating system to deploy this rule to.",
133+
title="Operating System",
137134
),
138135
]
139-
namespace: str
136+
137+
138+
class NodeGroupSpecTacacs(BaseModel):
139+
"""
140+
TACACS configuration.
141+
"""
142+
143+
privilegeLevel: Annotated[
144+
Optional[int],
145+
Field(
146+
description="Set the privilege level for this group.",
147+
ge=0,
148+
le=15,
149+
title="Privilege Level",
150+
),
151+
] = None
140152

141153

142154
class NodeGroupSpec(BaseModel):
@@ -182,43 +194,6 @@ class NodeGroupSpec(BaseModel):
182194
] = None
183195

184196

185-
class NodeGroupSpecRule(BaseModel):
186-
action: Annotated[
187-
Literal["Deny", "ReadWrite", "Read"],
188-
Field(description="Set the action for this entry.", title="Action"),
189-
]
190-
match: Annotated[
191-
Optional[str],
192-
Field(
193-
description='Set the match for this entry. This is a string to match input against - for example "interface" for srl or "configure port" for sros.\nRules here should be specified in the target specific format.',
194-
title="Match",
195-
),
196-
] = None
197-
operatingSystem: Annotated[
198-
Literal["srl", "sros"],
199-
Field(
200-
description="Operating system to match against for this rule.\nOperating system to deploy this rule to.",
201-
title="Operating System",
202-
),
203-
]
204-
205-
206-
class NodeGroupSpecTacacs(BaseModel):
207-
"""
208-
TACACS configuration.
209-
"""
210-
211-
privilegeLevel: Annotated[
212-
Optional[int],
213-
Field(
214-
description="Set the privilege level for this group.",
215-
ge=0,
216-
le=15,
217-
title="Privilege Level",
218-
),
219-
] = None
220-
221-
222197
class NodeGroupStatus(BaseModel):
223198
"""
224199
Deployment status of this NodeGroup.
@@ -232,37 +207,41 @@ class NodeGroupStatus(BaseModel):
232207
] = None
233208

234209

235-
class Patch(RootModel[List[K8SPatchOp]]):
236-
root: List[K8SPatchOp]
237-
238-
239-
class Resource(BaseModel):
240-
kind: Optional[str] = None
210+
class NodeGroupDeletedResourceEntry(BaseModel):
211+
commitTime: Optional[str] = None
212+
hash: Optional[str] = None
241213
name: Optional[str] = None
242-
namespaced: Optional[bool] = None
243-
readOnly: Optional[bool] = None
244-
singularName: Optional[str] = None
245-
uiCategory: Optional[str] = None
214+
namespace: Optional[str] = None
215+
transactionId: Optional[int] = None
246216

247217

248-
class ResourceHistory(RootModel[List[ResourceHistoryEntry]]):
249-
root: List[ResourceHistoryEntry]
218+
class NodeGroupDeletedResources(RootModel[List[NodeGroupDeletedResourceEntry]]):
219+
root: List[NodeGroupDeletedResourceEntry]
250220

251221

252-
class ResourceHistoryEntry(BaseModel):
253-
author: Optional[str] = None
254-
changeType: Optional[str] = None
255-
commitTime: Optional[str] = None
256-
hash: Optional[str] = None
257-
message: Optional[str] = None
258-
transactionId: Optional[int] = None
222+
class NodeGroupMetadata(BaseModel):
223+
annotations: Optional[Dict[str, str]] = None
224+
labels: Optional[Dict[str, str]] = None
225+
name: Annotated[
226+
str,
227+
Field(
228+
max_length=253,
229+
pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$",
230+
),
231+
]
232+
namespace: str
259233

260234

261-
class ResourceList(BaseModel):
235+
class AppGroup(BaseModel):
262236
apiVersion: Optional[str] = None
263-
groupVersion: Optional[str] = None
264237
kind: Optional[str] = None
265-
resources: Optional[List[Resource]] = None
238+
name: Optional[str] = None
239+
preferredVersion: Optional[AppGroupVersion] = None
240+
versions: Optional[List[AppGroupVersion]] = None
241+
242+
243+
class ResourceHistory(RootModel[List[ResourceHistoryEntry]]):
244+
root: List[ResourceHistoryEntry]
266245

267246

268247
class Status(BaseModel):
@@ -272,11 +251,32 @@ class Status(BaseModel):
272251
string: Optional[str] = None
273252

274253

275-
class StatusDetails(BaseModel):
276-
group: Optional[str] = None
277-
kind: Optional[str] = None
278-
name: Optional[str] = None
254+
class NodeGroup(BaseModel):
255+
"""
256+
NodeGroup is the Schema for the nodegroups API
257+
"""
279258

259+
apiVersion: str
260+
kind: str
261+
metadata: NodeGroupMetadata
262+
spec: Annotated[
263+
NodeGroupSpec,
264+
Field(
265+
description="NodeGroup is a representation of a group on a node, including the services it has access to, any RBAC, and TACACS configuration.\nNodeGroups are deployed to nodes by NodeUser or other permission-consuming resources.",
266+
title="Specification",
267+
),
268+
]
269+
status: Annotated[
270+
Optional[NodeGroupStatus],
271+
Field(description="Deployment status of this NodeGroup.", title="Status"),
272+
] = None
280273

281-
class UIResult(RootModel[str]):
282-
root: str
274+
275+
class NodeGroupList(BaseModel):
276+
"""
277+
NodeGroupList is a list of nodegroups
278+
"""
279+
280+
apiVersion: str
281+
items: Optional[List[NodeGroup]] = None
282+
kind: str

0 commit comments

Comments
 (0)