jentic-openapi-datamodels 1.0.0a19__tar.gz → 1.0.0a21__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/PKG-INFO +95 -33
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/README.md +94 -32
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/pyproject.toml +9 -1
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/LICENSE +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/NOTICE +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/context.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/extractors.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/fields.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/py.typed +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/sources.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/builders/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/callback.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/components.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/contact.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/discriminator.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/encoding.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/example.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/external_documentation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/header.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/info.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/license.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/link.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/media_type.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/oauth_flow.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/oauth_flows.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/openapi.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/operation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/parameter.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/path_item.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/paths.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/reference.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/request_body.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/response.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/responses.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/schema.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/security_requirement.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/security_scheme.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/server.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/server_variable.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/tag.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v30/xml.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/builders/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/callback.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/components.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/contact.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/discriminator.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/encoding.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/example.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/external_documentation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/header.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/info.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/license.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/link.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/media_type.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/oauth_flow.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/oauth_flows.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/openapi.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/operation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/parameter.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/path_item.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/paths.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/reference.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/request_body.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/response.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/responses.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/schema.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/security_requirement.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/security_scheme.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/server.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/server_variable.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/tag.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a21}/src/jentic/apitools/openapi/datamodels/low/v31/xml.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jentic-openapi-datamodels
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0a21
|
|
4
4
|
Summary: Jentic OpenAPI Data Models
|
|
5
5
|
Author: Jentic
|
|
6
6
|
Author-email: Jentic <hello@jentic.com>
|
|
@@ -61,17 +61,73 @@ pip install jentic-openapi-datamodels
|
|
|
61
61
|
|
|
62
62
|
## Quick Start
|
|
63
63
|
|
|
64
|
-
### Parsing
|
|
64
|
+
### Parsing with the `datamodel-low` Parser Backend (Recommended)
|
|
65
65
|
|
|
66
|
-
The
|
|
66
|
+
The easiest way to parse OpenAPI documents into datamodels is using the `datamodel-low` backend from `jentic-openapi-parser`. This backend automatically detects the OpenAPI version and returns the appropriate typed datamodel:
|
|
67
67
|
|
|
68
68
|
```python
|
|
69
|
-
from
|
|
69
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
70
|
+
from jentic.apitools.openapi.parser.backends.datamodel_low import DataModelLow
|
|
71
|
+
from jentic.apitools.openapi.datamodels.low.v30.openapi import OpenAPI30
|
|
72
|
+
from jentic.apitools.openapi.datamodels.low.v31.openapi import OpenAPI31
|
|
73
|
+
|
|
74
|
+
# Create parser with datamodel-low backend
|
|
75
|
+
parser = OpenAPIParser("datamodel-low")
|
|
76
|
+
|
|
77
|
+
# Parse OpenAPI 3.0 document - automatically returns OpenAPI30
|
|
78
|
+
doc = parser.parse("""
|
|
79
|
+
openapi: 3.0.4
|
|
80
|
+
info:
|
|
81
|
+
title: Pet Store API
|
|
82
|
+
version: 1.0.0
|
|
83
|
+
paths:
|
|
84
|
+
/pets:
|
|
85
|
+
get:
|
|
86
|
+
summary: List all pets
|
|
87
|
+
responses:
|
|
88
|
+
'200':
|
|
89
|
+
description: A list of pets
|
|
90
|
+
""", return_type=DataModelLow)
|
|
91
|
+
|
|
92
|
+
assert isinstance(doc, OpenAPI30)
|
|
93
|
+
print(doc.openapi.value) # "3.0.4"
|
|
94
|
+
print(doc.info.value.title.value) # "Pet Store API"
|
|
95
|
+
|
|
96
|
+
# Parse OpenAPI 3.1 document - automatically returns OpenAPI31
|
|
97
|
+
doc = parser.parse("""
|
|
98
|
+
openapi: 3.1.2
|
|
99
|
+
info:
|
|
100
|
+
title: Pet Store API
|
|
101
|
+
version: 1.0.0
|
|
102
|
+
paths: {}
|
|
103
|
+
""", return_type=DataModelLow)
|
|
104
|
+
|
|
105
|
+
assert isinstance(doc, OpenAPI31)
|
|
106
|
+
print(doc.openapi.value) # "3.1.2"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Benefits of `datamodel-low` backend:**
|
|
110
|
+
- Automatic version detection (no manual version checking)
|
|
111
|
+
- Returns strongly-typed `OpenAPI30` or `OpenAPI31` objects
|
|
112
|
+
- Complete source tracking preserved
|
|
113
|
+
- Single-step parsing (no need to manually call `build()`)
|
|
114
|
+
|
|
115
|
+
### Manual Parsing with Builder Functions
|
|
116
|
+
|
|
117
|
+
For advanced use cases or custom workflows, you can manually parse and build datamodels:
|
|
118
|
+
|
|
119
|
+
#### Parsing OpenAPI 3.0 Documents
|
|
120
|
+
|
|
121
|
+
The manual approach uses the `ruamel-ast` backend followed by calling the builder function:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
125
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
70
126
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
71
127
|
|
|
72
128
|
# Parse OpenAPI document
|
|
73
|
-
|
|
74
|
-
root =
|
|
129
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
130
|
+
root = parser.parse("""
|
|
75
131
|
openapi: 3.0.4
|
|
76
132
|
info:
|
|
77
133
|
title: Pet Store API
|
|
@@ -83,7 +139,7 @@ paths:
|
|
|
83
139
|
responses:
|
|
84
140
|
'200':
|
|
85
141
|
description: A list of pets
|
|
86
|
-
""")
|
|
142
|
+
""", return_type=MappingNode)
|
|
87
143
|
|
|
88
144
|
# Build OpenAPI document model
|
|
89
145
|
openapi_doc = build(root)
|
|
@@ -101,17 +157,18 @@ for path_key, path_item in openapi_doc.paths.value.path_items.items():
|
|
|
101
157
|
print(f" Summary: {operation.summary.value}") # "List all pets"
|
|
102
158
|
```
|
|
103
159
|
|
|
104
|
-
|
|
160
|
+
#### Parsing OpenAPI 3.1 Documents with JSON Schema 2020-12
|
|
105
161
|
|
|
106
162
|
OpenAPI 3.1 fully supports JSON Schema 2020-12, including advanced features like boolean schemas, conditional validation and vocabulary declarations:
|
|
107
163
|
|
|
108
164
|
```python
|
|
109
|
-
from
|
|
165
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
166
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
110
167
|
from jentic.apitools.openapi.datamodels.low.v31 import build
|
|
111
168
|
|
|
112
169
|
# Parse OpenAPI 3.1 document with JSON Schema 2020-12 features
|
|
113
|
-
|
|
114
|
-
root =
|
|
170
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
171
|
+
root = parser.parse("""
|
|
115
172
|
openapi: 3.1.2
|
|
116
173
|
info:
|
|
117
174
|
title: Pet Store API
|
|
@@ -133,7 +190,7 @@ paths:
|
|
|
133
190
|
contains:
|
|
134
191
|
type: object
|
|
135
192
|
required: [id]
|
|
136
|
-
""")
|
|
193
|
+
""", return_type=MappingNode)
|
|
137
194
|
|
|
138
195
|
openapi_doc = build(root)
|
|
139
196
|
|
|
@@ -149,16 +206,17 @@ print(schema.contains.value.required.value[0].value) # "id"
|
|
|
149
206
|
You can also parse individual OpenAPI specification objects:
|
|
150
207
|
|
|
151
208
|
```python
|
|
152
|
-
from
|
|
209
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
210
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
153
211
|
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
|
|
154
212
|
|
|
155
213
|
# Parse a Security Scheme object
|
|
156
|
-
|
|
157
|
-
root =
|
|
214
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
215
|
+
root = parser.parse("""
|
|
158
216
|
type: http
|
|
159
217
|
scheme: bearer
|
|
160
218
|
bearerFormat: JWT
|
|
161
|
-
""")
|
|
219
|
+
""", return_type=MappingNode)
|
|
162
220
|
|
|
163
221
|
security_scheme = build_security_scheme(root)
|
|
164
222
|
|
|
@@ -173,12 +231,13 @@ print(security_scheme.bearer_format.key_node.start_mark.line) # Line number
|
|
|
173
231
|
You can also parse OpenAPI 3.1 Schema objects with JSON Schema 2020-12 features:
|
|
174
232
|
|
|
175
233
|
```python
|
|
176
|
-
from
|
|
234
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
235
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
177
236
|
from jentic.apitools.openapi.datamodels.low.v31.schema import build as build_schema
|
|
178
237
|
|
|
179
238
|
# Parse a Schema object with JSON Schema 2020-12 features
|
|
180
|
-
|
|
181
|
-
root =
|
|
239
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
240
|
+
root = parser.parse("""
|
|
182
241
|
type: object
|
|
183
242
|
properties:
|
|
184
243
|
id:
|
|
@@ -199,7 +258,7 @@ if:
|
|
|
199
258
|
const: true
|
|
200
259
|
then:
|
|
201
260
|
required: [support_tier]
|
|
202
|
-
""")
|
|
261
|
+
""", return_type=MappingNode)
|
|
203
262
|
|
|
204
263
|
schema = build_schema(root)
|
|
205
264
|
|
|
@@ -255,18 +314,19 @@ The package provides three immutable wrapper types for preserving source informa
|
|
|
255
314
|
- Example: Values in `Discriminator.mapping` are `ValueSource[str]`
|
|
256
315
|
|
|
257
316
|
```python
|
|
258
|
-
from
|
|
317
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
318
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
259
319
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
260
320
|
|
|
261
321
|
# FieldSource: Fixed specification fields in OpenAPI document
|
|
262
|
-
|
|
263
|
-
root =
|
|
322
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
323
|
+
root = parser.parse("""
|
|
264
324
|
openapi: 3.0.4
|
|
265
325
|
info:
|
|
266
326
|
title: Pet Store API
|
|
267
327
|
version: 1.0.0
|
|
268
328
|
paths: {}
|
|
269
|
-
""")
|
|
329
|
+
""", return_type=MappingNode)
|
|
270
330
|
openapi_doc = build(root)
|
|
271
331
|
|
|
272
332
|
field = openapi_doc.info.value.title # FieldSource[str]
|
|
@@ -276,7 +336,7 @@ print(field.value_node) # YAML node for "Pet Store API"
|
|
|
276
336
|
|
|
277
337
|
# KeySource/ValueSource: Dictionary fields (extensions, mapping)
|
|
278
338
|
# Extensions in OpenAPI objects use KeySource/ValueSource
|
|
279
|
-
root =
|
|
339
|
+
root = parser.parse("""
|
|
280
340
|
openapi: 3.0.4
|
|
281
341
|
info:
|
|
282
342
|
title: API
|
|
@@ -284,7 +344,7 @@ info:
|
|
|
284
344
|
x-custom: value
|
|
285
345
|
x-another: data
|
|
286
346
|
paths: {}
|
|
287
|
-
""")
|
|
347
|
+
""", return_type=MappingNode)
|
|
288
348
|
openapi_doc = build(root)
|
|
289
349
|
|
|
290
350
|
for key, value in openapi_doc.info.value.extensions.items():
|
|
@@ -299,7 +359,8 @@ for key, value in openapi_doc.info.value.extensions.items():
|
|
|
299
359
|
Access precise location ranges within the source document using start_mark and end_mark:
|
|
300
360
|
|
|
301
361
|
```python
|
|
302
|
-
from
|
|
362
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
363
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
303
364
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
304
365
|
|
|
305
366
|
yaml_content = """
|
|
@@ -311,8 +372,8 @@ info:
|
|
|
311
372
|
paths: {}
|
|
312
373
|
"""
|
|
313
374
|
|
|
314
|
-
|
|
315
|
-
root =
|
|
375
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
376
|
+
root = parser.parse(yaml_content, return_type=MappingNode)
|
|
316
377
|
openapi_doc = build(root)
|
|
317
378
|
|
|
318
379
|
# Access location information for any field
|
|
@@ -337,17 +398,18 @@ print(f"Field range: ({start.line}:{start.column}) to ({end.line}:{end.column})"
|
|
|
337
398
|
Low-level models preserve invalid data without validation:
|
|
338
399
|
|
|
339
400
|
```python
|
|
340
|
-
from
|
|
401
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
402
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
341
403
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
342
404
|
|
|
343
|
-
|
|
344
|
-
root =
|
|
405
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
406
|
+
root = parser.parse("""
|
|
345
407
|
openapi: 3.0.4
|
|
346
408
|
info:
|
|
347
409
|
title: 123 # Intentionally wrong type for demonstration (should be string)
|
|
348
410
|
version: 1.0.0
|
|
349
411
|
paths: {}
|
|
350
|
-
""")
|
|
412
|
+
""", return_type=MappingNode)
|
|
351
413
|
|
|
352
414
|
openapi_doc = build(root)
|
|
353
415
|
print(openapi_doc.info.value.title.value) # 123 (preserved as-is)
|
|
@@ -47,17 +47,73 @@ pip install jentic-openapi-datamodels
|
|
|
47
47
|
|
|
48
48
|
## Quick Start
|
|
49
49
|
|
|
50
|
-
### Parsing
|
|
50
|
+
### Parsing with the `datamodel-low` Parser Backend (Recommended)
|
|
51
51
|
|
|
52
|
-
The
|
|
52
|
+
The easiest way to parse OpenAPI documents into datamodels is using the `datamodel-low` backend from `jentic-openapi-parser`. This backend automatically detects the OpenAPI version and returns the appropriate typed datamodel:
|
|
53
53
|
|
|
54
54
|
```python
|
|
55
|
-
from
|
|
55
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
56
|
+
from jentic.apitools.openapi.parser.backends.datamodel_low import DataModelLow
|
|
57
|
+
from jentic.apitools.openapi.datamodels.low.v30.openapi import OpenAPI30
|
|
58
|
+
from jentic.apitools.openapi.datamodels.low.v31.openapi import OpenAPI31
|
|
59
|
+
|
|
60
|
+
# Create parser with datamodel-low backend
|
|
61
|
+
parser = OpenAPIParser("datamodel-low")
|
|
62
|
+
|
|
63
|
+
# Parse OpenAPI 3.0 document - automatically returns OpenAPI30
|
|
64
|
+
doc = parser.parse("""
|
|
65
|
+
openapi: 3.0.4
|
|
66
|
+
info:
|
|
67
|
+
title: Pet Store API
|
|
68
|
+
version: 1.0.0
|
|
69
|
+
paths:
|
|
70
|
+
/pets:
|
|
71
|
+
get:
|
|
72
|
+
summary: List all pets
|
|
73
|
+
responses:
|
|
74
|
+
'200':
|
|
75
|
+
description: A list of pets
|
|
76
|
+
""", return_type=DataModelLow)
|
|
77
|
+
|
|
78
|
+
assert isinstance(doc, OpenAPI30)
|
|
79
|
+
print(doc.openapi.value) # "3.0.4"
|
|
80
|
+
print(doc.info.value.title.value) # "Pet Store API"
|
|
81
|
+
|
|
82
|
+
# Parse OpenAPI 3.1 document - automatically returns OpenAPI31
|
|
83
|
+
doc = parser.parse("""
|
|
84
|
+
openapi: 3.1.2
|
|
85
|
+
info:
|
|
86
|
+
title: Pet Store API
|
|
87
|
+
version: 1.0.0
|
|
88
|
+
paths: {}
|
|
89
|
+
""", return_type=DataModelLow)
|
|
90
|
+
|
|
91
|
+
assert isinstance(doc, OpenAPI31)
|
|
92
|
+
print(doc.openapi.value) # "3.1.2"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Benefits of `datamodel-low` backend:**
|
|
96
|
+
- Automatic version detection (no manual version checking)
|
|
97
|
+
- Returns strongly-typed `OpenAPI30` or `OpenAPI31` objects
|
|
98
|
+
- Complete source tracking preserved
|
|
99
|
+
- Single-step parsing (no need to manually call `build()`)
|
|
100
|
+
|
|
101
|
+
### Manual Parsing with Builder Functions
|
|
102
|
+
|
|
103
|
+
For advanced use cases or custom workflows, you can manually parse and build datamodels:
|
|
104
|
+
|
|
105
|
+
#### Parsing OpenAPI 3.0 Documents
|
|
106
|
+
|
|
107
|
+
The manual approach uses the `ruamel-ast` backend followed by calling the builder function:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
111
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
56
112
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
57
113
|
|
|
58
114
|
# Parse OpenAPI document
|
|
59
|
-
|
|
60
|
-
root =
|
|
115
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
116
|
+
root = parser.parse("""
|
|
61
117
|
openapi: 3.0.4
|
|
62
118
|
info:
|
|
63
119
|
title: Pet Store API
|
|
@@ -69,7 +125,7 @@ paths:
|
|
|
69
125
|
responses:
|
|
70
126
|
'200':
|
|
71
127
|
description: A list of pets
|
|
72
|
-
""")
|
|
128
|
+
""", return_type=MappingNode)
|
|
73
129
|
|
|
74
130
|
# Build OpenAPI document model
|
|
75
131
|
openapi_doc = build(root)
|
|
@@ -87,17 +143,18 @@ for path_key, path_item in openapi_doc.paths.value.path_items.items():
|
|
|
87
143
|
print(f" Summary: {operation.summary.value}") # "List all pets"
|
|
88
144
|
```
|
|
89
145
|
|
|
90
|
-
|
|
146
|
+
#### Parsing OpenAPI 3.1 Documents with JSON Schema 2020-12
|
|
91
147
|
|
|
92
148
|
OpenAPI 3.1 fully supports JSON Schema 2020-12, including advanced features like boolean schemas, conditional validation and vocabulary declarations:
|
|
93
149
|
|
|
94
150
|
```python
|
|
95
|
-
from
|
|
151
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
152
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
96
153
|
from jentic.apitools.openapi.datamodels.low.v31 import build
|
|
97
154
|
|
|
98
155
|
# Parse OpenAPI 3.1 document with JSON Schema 2020-12 features
|
|
99
|
-
|
|
100
|
-
root =
|
|
156
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
157
|
+
root = parser.parse("""
|
|
101
158
|
openapi: 3.1.2
|
|
102
159
|
info:
|
|
103
160
|
title: Pet Store API
|
|
@@ -119,7 +176,7 @@ paths:
|
|
|
119
176
|
contains:
|
|
120
177
|
type: object
|
|
121
178
|
required: [id]
|
|
122
|
-
""")
|
|
179
|
+
""", return_type=MappingNode)
|
|
123
180
|
|
|
124
181
|
openapi_doc = build(root)
|
|
125
182
|
|
|
@@ -135,16 +192,17 @@ print(schema.contains.value.required.value[0].value) # "id"
|
|
|
135
192
|
You can also parse individual OpenAPI specification objects:
|
|
136
193
|
|
|
137
194
|
```python
|
|
138
|
-
from
|
|
195
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
196
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
139
197
|
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
|
|
140
198
|
|
|
141
199
|
# Parse a Security Scheme object
|
|
142
|
-
|
|
143
|
-
root =
|
|
200
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
201
|
+
root = parser.parse("""
|
|
144
202
|
type: http
|
|
145
203
|
scheme: bearer
|
|
146
204
|
bearerFormat: JWT
|
|
147
|
-
""")
|
|
205
|
+
""", return_type=MappingNode)
|
|
148
206
|
|
|
149
207
|
security_scheme = build_security_scheme(root)
|
|
150
208
|
|
|
@@ -159,12 +217,13 @@ print(security_scheme.bearer_format.key_node.start_mark.line) # Line number
|
|
|
159
217
|
You can also parse OpenAPI 3.1 Schema objects with JSON Schema 2020-12 features:
|
|
160
218
|
|
|
161
219
|
```python
|
|
162
|
-
from
|
|
220
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
221
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
163
222
|
from jentic.apitools.openapi.datamodels.low.v31.schema import build as build_schema
|
|
164
223
|
|
|
165
224
|
# Parse a Schema object with JSON Schema 2020-12 features
|
|
166
|
-
|
|
167
|
-
root =
|
|
225
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
226
|
+
root = parser.parse("""
|
|
168
227
|
type: object
|
|
169
228
|
properties:
|
|
170
229
|
id:
|
|
@@ -185,7 +244,7 @@ if:
|
|
|
185
244
|
const: true
|
|
186
245
|
then:
|
|
187
246
|
required: [support_tier]
|
|
188
|
-
""")
|
|
247
|
+
""", return_type=MappingNode)
|
|
189
248
|
|
|
190
249
|
schema = build_schema(root)
|
|
191
250
|
|
|
@@ -241,18 +300,19 @@ The package provides three immutable wrapper types for preserving source informa
|
|
|
241
300
|
- Example: Values in `Discriminator.mapping` are `ValueSource[str]`
|
|
242
301
|
|
|
243
302
|
```python
|
|
244
|
-
from
|
|
303
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
304
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
245
305
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
246
306
|
|
|
247
307
|
# FieldSource: Fixed specification fields in OpenAPI document
|
|
248
|
-
|
|
249
|
-
root =
|
|
308
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
309
|
+
root = parser.parse("""
|
|
250
310
|
openapi: 3.0.4
|
|
251
311
|
info:
|
|
252
312
|
title: Pet Store API
|
|
253
313
|
version: 1.0.0
|
|
254
314
|
paths: {}
|
|
255
|
-
""")
|
|
315
|
+
""", return_type=MappingNode)
|
|
256
316
|
openapi_doc = build(root)
|
|
257
317
|
|
|
258
318
|
field = openapi_doc.info.value.title # FieldSource[str]
|
|
@@ -262,7 +322,7 @@ print(field.value_node) # YAML node for "Pet Store API"
|
|
|
262
322
|
|
|
263
323
|
# KeySource/ValueSource: Dictionary fields (extensions, mapping)
|
|
264
324
|
# Extensions in OpenAPI objects use KeySource/ValueSource
|
|
265
|
-
root =
|
|
325
|
+
root = parser.parse("""
|
|
266
326
|
openapi: 3.0.4
|
|
267
327
|
info:
|
|
268
328
|
title: API
|
|
@@ -270,7 +330,7 @@ info:
|
|
|
270
330
|
x-custom: value
|
|
271
331
|
x-another: data
|
|
272
332
|
paths: {}
|
|
273
|
-
""")
|
|
333
|
+
""", return_type=MappingNode)
|
|
274
334
|
openapi_doc = build(root)
|
|
275
335
|
|
|
276
336
|
for key, value in openapi_doc.info.value.extensions.items():
|
|
@@ -285,7 +345,8 @@ for key, value in openapi_doc.info.value.extensions.items():
|
|
|
285
345
|
Access precise location ranges within the source document using start_mark and end_mark:
|
|
286
346
|
|
|
287
347
|
```python
|
|
288
|
-
from
|
|
348
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
349
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
289
350
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
290
351
|
|
|
291
352
|
yaml_content = """
|
|
@@ -297,8 +358,8 @@ info:
|
|
|
297
358
|
paths: {}
|
|
298
359
|
"""
|
|
299
360
|
|
|
300
|
-
|
|
301
|
-
root =
|
|
361
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
362
|
+
root = parser.parse(yaml_content, return_type=MappingNode)
|
|
302
363
|
openapi_doc = build(root)
|
|
303
364
|
|
|
304
365
|
# Access location information for any field
|
|
@@ -323,17 +384,18 @@ print(f"Field range: ({start.line}:{start.column}) to ({end.line}:{end.column})"
|
|
|
323
384
|
Low-level models preserve invalid data without validation:
|
|
324
385
|
|
|
325
386
|
```python
|
|
326
|
-
from
|
|
387
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
388
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
327
389
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
328
390
|
|
|
329
|
-
|
|
330
|
-
root =
|
|
391
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
392
|
+
root = parser.parse("""
|
|
331
393
|
openapi: 3.0.4
|
|
332
394
|
info:
|
|
333
395
|
title: 123 # Intentionally wrong type for demonstration (should be string)
|
|
334
396
|
version: 1.0.0
|
|
335
397
|
paths: {}
|
|
336
|
-
""")
|
|
398
|
+
""", return_type=MappingNode)
|
|
337
399
|
|
|
338
400
|
openapi_doc = build(root)
|
|
339
401
|
print(openapi_doc.info.value.title.value) # 123 (preserved as-is)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "jentic-openapi-datamodels"
|
|
3
|
-
version = "1.0.0-alpha.
|
|
3
|
+
version = "1.0.0-alpha.21"
|
|
4
4
|
description = "Jentic OpenAPI Data Models"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Jentic", email = "hello@jentic.com" }]
|
|
@@ -11,12 +11,20 @@ dependencies = [
|
|
|
11
11
|
"ruamel-yaml~=0.18.15"
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
+
[dependency-groups]
|
|
15
|
+
dev = [
|
|
16
|
+
"jentic-openapi-parser",
|
|
17
|
+
]
|
|
18
|
+
|
|
14
19
|
[project.urls]
|
|
15
20
|
Homepage = "https://github.com/jentic/jentic-openapi-tools"
|
|
16
21
|
|
|
17
22
|
[tool.uv]
|
|
18
23
|
package = true
|
|
19
24
|
|
|
25
|
+
[tool.uv.sources]
|
|
26
|
+
jentic-openapi-parser = { workspace = true }
|
|
27
|
+
|
|
20
28
|
[tool.uv.build-backend]
|
|
21
29
|
namespace = true
|
|
22
30
|
module-name = "jentic.apitools.openapi.datamodels"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|