Skip to content

Commit 3444319

Browse files
committed
init
1 parent 7acf108 commit 3444319

File tree

12 files changed

+872
-1
lines changed

12 files changed

+872
-1
lines changed

.envrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export VIRTUAL_ENV=.venv
2+
export PATH=$VIRTUAL_ENV/bin:$PATH

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
# openapi-example-python
1+
# openapi-example-python
2+
3+
Install `datamodel-codegen`:
4+
5+
```
6+
uv tool install 'datamodel-code-generator[http]'
7+
```
8+
9+
To generate a mode:
10+
11+
```
12+
datamodel-codegen --url https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json \
13+
--output-model-type pydantic_v2.BaseModel \
14+
--use-annotated \
15+
--enum-field-as-literal all \
16+
--output models
17+
```
18+
19+
See [command options](https://koxudaxi.github.io/datamodel-code-generator/#all-command-options) for more details.

hello.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from models.com.nokia.eda.interfaces.v1alpha1 import Interface, Member, SpecModel, Metadata
2+
3+
def main():
4+
iface = Interface(
5+
apiVersion="interfaces.eda.nokia.com/v1alpha1",
6+
kind="Interface",
7+
metadata=Metadata(
8+
name="test",
9+
namespace="clab-vlan",
10+
labels={"app": "test"},
11+
),
12+
spec=SpecModel(
13+
description="This is a test interface",
14+
enabled=True,
15+
members=[
16+
Member(
17+
node="leaf1",
18+
interface="ethernet-1-1",
19+
)
20+
]
21+
)
22+
)
23+
print(iface.model_dump_json(indent=2))
24+
25+
26+
if __name__ == "__main__":
27+
main()

models/__init__.py

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# generated by datamodel-codegen:
2+
# filename: https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json
3+
# timestamp: 2025-01-19T10:10:02+00:00
4+
5+
from __future__ import annotations
6+
7+
from typing import Any, Dict, List, Optional
8+
9+
from pydantic import BaseModel, Field, RootModel
10+
from typing_extensions import Annotated
11+
12+
13+
class AppGroupVersion(BaseModel):
14+
groupVersion: Optional[str] = None
15+
version: Optional[str] = None
16+
17+
18+
class DeletedResourceEntry(BaseModel):
19+
commitTime: Optional[str] = None
20+
hash: Optional[str] = None
21+
name: Optional[str] = None
22+
namespace: Optional[str] = None
23+
transactionId: Optional[int] = None
24+
25+
26+
class DeletedResources(RootModel[List[DeletedResourceEntry]]):
27+
root: List[DeletedResourceEntry]
28+
29+
30+
class ErrorIndex(BaseModel):
31+
index: Optional[int] = None
32+
33+
34+
class ErrorItem(BaseModel):
35+
error: Optional[Dict[str, Any]] = None
36+
type: Optional[str] = None
37+
38+
39+
class ErrorResponse(BaseModel):
40+
code: Annotated[
41+
int, Field(description='the numeric HTTP error code for the response.')
42+
]
43+
details: Annotated[
44+
Optional[str], Field(description='The optional details of the error response.')
45+
] = None
46+
dictionary: Annotated[
47+
Optional[Dict[str, Dict[str, Any]]],
48+
Field(
49+
description='Dictionary/map of associated data/information relevant to the error.\nThe error "message" may contain {{name}} escapes that should be substituted\nwith information from this dictionary.'
50+
),
51+
] = None
52+
errors: Annotated[
53+
Optional[List[ErrorItem]],
54+
Field(
55+
description='Collection of errors in cases where more than one exists. This needs to be\nflexible so we can support multiple formats'
56+
),
57+
] = None
58+
index: Optional[ErrorIndex] = None
59+
internal: Annotated[
60+
Optional[int],
61+
Field(
62+
description="Internal error code in cases where we don't have an array of errors"
63+
),
64+
] = None
65+
message: Annotated[
66+
str, Field(description='The basic text error message for the error response.')
67+
]
68+
ref: Annotated[
69+
Optional[str],
70+
Field(
71+
description='Reference to the error source. Should typically be the URI of the request'
72+
),
73+
] = None
74+
type: Annotated[
75+
Optional[str],
76+
Field(
77+
description='URI pointing at a document that describes the error and mitigation steps\nIf there is no document, point to the RFC for the HTTP error code'
78+
),
79+
] = None
80+
81+
82+
class Metadata(BaseModel):
83+
annotations: Optional[Dict[str, str]] = None
84+
labels: Optional[Dict[str, str]] = None
85+
name: Annotated[
86+
str,
87+
Field(
88+
max_length=253,
89+
pattern='^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$',
90+
),
91+
]
92+
namespace: Optional[str] = None
93+
94+
95+
class Resource(BaseModel):
96+
kind: Optional[str] = None
97+
name: Optional[str] = None
98+
readOnly: Optional[bool] = None
99+
singularName: Optional[str] = None
100+
uiCategory: Optional[str] = None
101+
102+
103+
class ResourceHistoryEntry(BaseModel):
104+
author: Optional[str] = None
105+
changeType: Optional[str] = None
106+
commitTime: Optional[str] = None
107+
hash: Optional[str] = None
108+
message: Optional[str] = None
109+
transactionId: Optional[int] = None
110+
111+
112+
class ResourceList(BaseModel):
113+
apiVersion: Optional[str] = None
114+
groupVersion: Optional[str] = None
115+
kind: Optional[str] = None
116+
resources: Optional[List[Resource]] = None
117+
118+
119+
class StatusDetails(BaseModel):
120+
group: Optional[str] = None
121+
kind: Optional[str] = None
122+
name: Optional[str] = None
123+
124+
125+
class UIResult(RootModel[str]):
126+
root: str
127+
128+
129+
class AppGroup(BaseModel):
130+
apiVersion: Optional[str] = None
131+
kind: Optional[str] = None
132+
name: Optional[str] = None
133+
preferredVersion: Optional[AppGroupVersion] = None
134+
versions: Optional[List[AppGroupVersion]] = None
135+
136+
137+
class ResourceHistory(RootModel[List[ResourceHistoryEntry]]):
138+
root: List[ResourceHistoryEntry]
139+
140+
141+
class Status(BaseModel):
142+
apiVersion: Optional[str] = None
143+
details: Optional[StatusDetails] = None
144+
kind: Optional[str] = None
145+
string: Optional[str] = None

models/com/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# generated by datamodel-codegen:
2+
# filename: https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json
3+
# timestamp: 2025-01-19T10:10:02+00:00

models/com/nokia/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# generated by datamodel-codegen:
2+
# filename: https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json
3+
# timestamp: 2025-01-19T10:10:02+00:00

models/com/nokia/eda/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# generated by datamodel-codegen:
2+
# filename: https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json
3+
# timestamp: 2025-01-19T10:10:02+00:00
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# generated by datamodel-codegen:
2+
# filename: https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json
3+
# timestamp: 2025-01-19T10:10:02+00:00

0 commit comments

Comments
 (0)