jentic-openapi-datamodels 1.0.0a19__tar.gz → 1.0.0a20__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.0a20}/PKG-INFO +37 -30
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/README.md +36 -29
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/pyproject.toml +9 -1
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/LICENSE +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/NOTICE +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/context.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/extractors.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/fields.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/py.typed +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/sources.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/builders/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/callback.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/components.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/contact.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/discriminator.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/encoding.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/example.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/external_documentation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/header.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/info.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/license.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/link.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/media_type.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/oauth_flow.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/oauth_flows.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/openapi.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/operation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/parameter.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/path_item.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/paths.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/reference.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/request_body.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/response.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/responses.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/schema.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/security_requirement.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/security_scheme.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/server.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/server_variable.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/tag.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v30/xml.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/builders/__init__.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/callback.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/components.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/contact.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/discriminator.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/encoding.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/example.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/external_documentation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/header.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/info.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/license.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/link.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/media_type.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/oauth_flow.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/oauth_flows.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/openapi.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/operation.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/parameter.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/path_item.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/paths.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/reference.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/request_body.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/response.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/responses.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/schema.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/security_requirement.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/security_scheme.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/server.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/server_variable.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/src/jentic/apitools/openapi/datamodels/low/v31/tag.py +0 -0
- {jentic_openapi_datamodels-1.0.0a19 → jentic_openapi_datamodels-1.0.0a20}/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.0a20
|
|
4
4
|
Summary: Jentic OpenAPI Data Models
|
|
5
5
|
Author: Jentic
|
|
6
6
|
Author-email: Jentic <hello@jentic.com>
|
|
@@ -66,12 +66,13 @@ pip install jentic-openapi-datamodels
|
|
|
66
66
|
The main use case is parsing complete OpenAPI Documents:
|
|
67
67
|
|
|
68
68
|
```python
|
|
69
|
-
from
|
|
69
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
70
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
70
71
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
71
72
|
|
|
72
73
|
# Parse OpenAPI document
|
|
73
|
-
|
|
74
|
-
root =
|
|
74
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
75
|
+
root = parser.parse("""
|
|
75
76
|
openapi: 3.0.4
|
|
76
77
|
info:
|
|
77
78
|
title: Pet Store API
|
|
@@ -83,7 +84,7 @@ paths:
|
|
|
83
84
|
responses:
|
|
84
85
|
'200':
|
|
85
86
|
description: A list of pets
|
|
86
|
-
""")
|
|
87
|
+
""", return_type=MappingNode)
|
|
87
88
|
|
|
88
89
|
# Build OpenAPI document model
|
|
89
90
|
openapi_doc = build(root)
|
|
@@ -106,12 +107,13 @@ for path_key, path_item in openapi_doc.paths.value.path_items.items():
|
|
|
106
107
|
OpenAPI 3.1 fully supports JSON Schema 2020-12, including advanced features like boolean schemas, conditional validation and vocabulary declarations:
|
|
107
108
|
|
|
108
109
|
```python
|
|
109
|
-
from
|
|
110
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
111
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
110
112
|
from jentic.apitools.openapi.datamodels.low.v31 import build
|
|
111
113
|
|
|
112
114
|
# Parse OpenAPI 3.1 document with JSON Schema 2020-12 features
|
|
113
|
-
|
|
114
|
-
root =
|
|
115
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
116
|
+
root = parser.parse("""
|
|
115
117
|
openapi: 3.1.2
|
|
116
118
|
info:
|
|
117
119
|
title: Pet Store API
|
|
@@ -133,7 +135,7 @@ paths:
|
|
|
133
135
|
contains:
|
|
134
136
|
type: object
|
|
135
137
|
required: [id]
|
|
136
|
-
""")
|
|
138
|
+
""", return_type=MappingNode)
|
|
137
139
|
|
|
138
140
|
openapi_doc = build(root)
|
|
139
141
|
|
|
@@ -149,16 +151,17 @@ print(schema.contains.value.required.value[0].value) # "id"
|
|
|
149
151
|
You can also parse individual OpenAPI specification objects:
|
|
150
152
|
|
|
151
153
|
```python
|
|
152
|
-
from
|
|
154
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
155
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
153
156
|
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
|
|
154
157
|
|
|
155
158
|
# Parse a Security Scheme object
|
|
156
|
-
|
|
157
|
-
root =
|
|
159
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
160
|
+
root = parser.parse("""
|
|
158
161
|
type: http
|
|
159
162
|
scheme: bearer
|
|
160
163
|
bearerFormat: JWT
|
|
161
|
-
""")
|
|
164
|
+
""", return_type=MappingNode)
|
|
162
165
|
|
|
163
166
|
security_scheme = build_security_scheme(root)
|
|
164
167
|
|
|
@@ -173,12 +176,13 @@ print(security_scheme.bearer_format.key_node.start_mark.line) # Line number
|
|
|
173
176
|
You can also parse OpenAPI 3.1 Schema objects with JSON Schema 2020-12 features:
|
|
174
177
|
|
|
175
178
|
```python
|
|
176
|
-
from
|
|
179
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
180
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
177
181
|
from jentic.apitools.openapi.datamodels.low.v31.schema import build as build_schema
|
|
178
182
|
|
|
179
183
|
# Parse a Schema object with JSON Schema 2020-12 features
|
|
180
|
-
|
|
181
|
-
root =
|
|
184
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
185
|
+
root = parser.parse("""
|
|
182
186
|
type: object
|
|
183
187
|
properties:
|
|
184
188
|
id:
|
|
@@ -199,7 +203,7 @@ if:
|
|
|
199
203
|
const: true
|
|
200
204
|
then:
|
|
201
205
|
required: [support_tier]
|
|
202
|
-
""")
|
|
206
|
+
""", return_type=MappingNode)
|
|
203
207
|
|
|
204
208
|
schema = build_schema(root)
|
|
205
209
|
|
|
@@ -255,18 +259,19 @@ The package provides three immutable wrapper types for preserving source informa
|
|
|
255
259
|
- Example: Values in `Discriminator.mapping` are `ValueSource[str]`
|
|
256
260
|
|
|
257
261
|
```python
|
|
258
|
-
from
|
|
262
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
263
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
259
264
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
260
265
|
|
|
261
266
|
# FieldSource: Fixed specification fields in OpenAPI document
|
|
262
|
-
|
|
263
|
-
root =
|
|
267
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
268
|
+
root = parser.parse("""
|
|
264
269
|
openapi: 3.0.4
|
|
265
270
|
info:
|
|
266
271
|
title: Pet Store API
|
|
267
272
|
version: 1.0.0
|
|
268
273
|
paths: {}
|
|
269
|
-
""")
|
|
274
|
+
""", return_type=MappingNode)
|
|
270
275
|
openapi_doc = build(root)
|
|
271
276
|
|
|
272
277
|
field = openapi_doc.info.value.title # FieldSource[str]
|
|
@@ -276,7 +281,7 @@ print(field.value_node) # YAML node for "Pet Store API"
|
|
|
276
281
|
|
|
277
282
|
# KeySource/ValueSource: Dictionary fields (extensions, mapping)
|
|
278
283
|
# Extensions in OpenAPI objects use KeySource/ValueSource
|
|
279
|
-
root =
|
|
284
|
+
root = parser.parse("""
|
|
280
285
|
openapi: 3.0.4
|
|
281
286
|
info:
|
|
282
287
|
title: API
|
|
@@ -284,7 +289,7 @@ info:
|
|
|
284
289
|
x-custom: value
|
|
285
290
|
x-another: data
|
|
286
291
|
paths: {}
|
|
287
|
-
""")
|
|
292
|
+
""", return_type=MappingNode)
|
|
288
293
|
openapi_doc = build(root)
|
|
289
294
|
|
|
290
295
|
for key, value in openapi_doc.info.value.extensions.items():
|
|
@@ -299,7 +304,8 @@ for key, value in openapi_doc.info.value.extensions.items():
|
|
|
299
304
|
Access precise location ranges within the source document using start_mark and end_mark:
|
|
300
305
|
|
|
301
306
|
```python
|
|
302
|
-
from
|
|
307
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
308
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
303
309
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
304
310
|
|
|
305
311
|
yaml_content = """
|
|
@@ -311,8 +317,8 @@ info:
|
|
|
311
317
|
paths: {}
|
|
312
318
|
"""
|
|
313
319
|
|
|
314
|
-
|
|
315
|
-
root =
|
|
320
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
321
|
+
root = parser.parse(yaml_content, return_type=MappingNode)
|
|
316
322
|
openapi_doc = build(root)
|
|
317
323
|
|
|
318
324
|
# Access location information for any field
|
|
@@ -337,17 +343,18 @@ print(f"Field range: ({start.line}:{start.column}) to ({end.line}:{end.column})"
|
|
|
337
343
|
Low-level models preserve invalid data without validation:
|
|
338
344
|
|
|
339
345
|
```python
|
|
340
|
-
from
|
|
346
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
347
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
341
348
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
342
349
|
|
|
343
|
-
|
|
344
|
-
root =
|
|
350
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
351
|
+
root = parser.parse("""
|
|
345
352
|
openapi: 3.0.4
|
|
346
353
|
info:
|
|
347
354
|
title: 123 # Intentionally wrong type for demonstration (should be string)
|
|
348
355
|
version: 1.0.0
|
|
349
356
|
paths: {}
|
|
350
|
-
""")
|
|
357
|
+
""", return_type=MappingNode)
|
|
351
358
|
|
|
352
359
|
openapi_doc = build(root)
|
|
353
360
|
print(openapi_doc.info.value.title.value) # 123 (preserved as-is)
|
|
@@ -52,12 +52,13 @@ pip install jentic-openapi-datamodels
|
|
|
52
52
|
The main use case is parsing complete OpenAPI Documents:
|
|
53
53
|
|
|
54
54
|
```python
|
|
55
|
-
from
|
|
55
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
56
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
56
57
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
57
58
|
|
|
58
59
|
# Parse OpenAPI document
|
|
59
|
-
|
|
60
|
-
root =
|
|
60
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
61
|
+
root = parser.parse("""
|
|
61
62
|
openapi: 3.0.4
|
|
62
63
|
info:
|
|
63
64
|
title: Pet Store API
|
|
@@ -69,7 +70,7 @@ paths:
|
|
|
69
70
|
responses:
|
|
70
71
|
'200':
|
|
71
72
|
description: A list of pets
|
|
72
|
-
""")
|
|
73
|
+
""", return_type=MappingNode)
|
|
73
74
|
|
|
74
75
|
# Build OpenAPI document model
|
|
75
76
|
openapi_doc = build(root)
|
|
@@ -92,12 +93,13 @@ for path_key, path_item in openapi_doc.paths.value.path_items.items():
|
|
|
92
93
|
OpenAPI 3.1 fully supports JSON Schema 2020-12, including advanced features like boolean schemas, conditional validation and vocabulary declarations:
|
|
93
94
|
|
|
94
95
|
```python
|
|
95
|
-
from
|
|
96
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
97
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
96
98
|
from jentic.apitools.openapi.datamodels.low.v31 import build
|
|
97
99
|
|
|
98
100
|
# Parse OpenAPI 3.1 document with JSON Schema 2020-12 features
|
|
99
|
-
|
|
100
|
-
root =
|
|
101
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
102
|
+
root = parser.parse("""
|
|
101
103
|
openapi: 3.1.2
|
|
102
104
|
info:
|
|
103
105
|
title: Pet Store API
|
|
@@ -119,7 +121,7 @@ paths:
|
|
|
119
121
|
contains:
|
|
120
122
|
type: object
|
|
121
123
|
required: [id]
|
|
122
|
-
""")
|
|
124
|
+
""", return_type=MappingNode)
|
|
123
125
|
|
|
124
126
|
openapi_doc = build(root)
|
|
125
127
|
|
|
@@ -135,16 +137,17 @@ print(schema.contains.value.required.value[0].value) # "id"
|
|
|
135
137
|
You can also parse individual OpenAPI specification objects:
|
|
136
138
|
|
|
137
139
|
```python
|
|
138
|
-
from
|
|
140
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
141
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
139
142
|
from jentic.apitools.openapi.datamodels.low.v30.security_scheme import build as build_security_scheme
|
|
140
143
|
|
|
141
144
|
# Parse a Security Scheme object
|
|
142
|
-
|
|
143
|
-
root =
|
|
145
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
146
|
+
root = parser.parse("""
|
|
144
147
|
type: http
|
|
145
148
|
scheme: bearer
|
|
146
149
|
bearerFormat: JWT
|
|
147
|
-
""")
|
|
150
|
+
""", return_type=MappingNode)
|
|
148
151
|
|
|
149
152
|
security_scheme = build_security_scheme(root)
|
|
150
153
|
|
|
@@ -159,12 +162,13 @@ print(security_scheme.bearer_format.key_node.start_mark.line) # Line number
|
|
|
159
162
|
You can also parse OpenAPI 3.1 Schema objects with JSON Schema 2020-12 features:
|
|
160
163
|
|
|
161
164
|
```python
|
|
162
|
-
from
|
|
165
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
166
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
163
167
|
from jentic.apitools.openapi.datamodels.low.v31.schema import build as build_schema
|
|
164
168
|
|
|
165
169
|
# Parse a Schema object with JSON Schema 2020-12 features
|
|
166
|
-
|
|
167
|
-
root =
|
|
170
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
171
|
+
root = parser.parse("""
|
|
168
172
|
type: object
|
|
169
173
|
properties:
|
|
170
174
|
id:
|
|
@@ -185,7 +189,7 @@ if:
|
|
|
185
189
|
const: true
|
|
186
190
|
then:
|
|
187
191
|
required: [support_tier]
|
|
188
|
-
""")
|
|
192
|
+
""", return_type=MappingNode)
|
|
189
193
|
|
|
190
194
|
schema = build_schema(root)
|
|
191
195
|
|
|
@@ -241,18 +245,19 @@ The package provides three immutable wrapper types for preserving source informa
|
|
|
241
245
|
- Example: Values in `Discriminator.mapping` are `ValueSource[str]`
|
|
242
246
|
|
|
243
247
|
```python
|
|
244
|
-
from
|
|
248
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
249
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
245
250
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
246
251
|
|
|
247
252
|
# FieldSource: Fixed specification fields in OpenAPI document
|
|
248
|
-
|
|
249
|
-
root =
|
|
253
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
254
|
+
root = parser.parse("""
|
|
250
255
|
openapi: 3.0.4
|
|
251
256
|
info:
|
|
252
257
|
title: Pet Store API
|
|
253
258
|
version: 1.0.0
|
|
254
259
|
paths: {}
|
|
255
|
-
""")
|
|
260
|
+
""", return_type=MappingNode)
|
|
256
261
|
openapi_doc = build(root)
|
|
257
262
|
|
|
258
263
|
field = openapi_doc.info.value.title # FieldSource[str]
|
|
@@ -262,7 +267,7 @@ print(field.value_node) # YAML node for "Pet Store API"
|
|
|
262
267
|
|
|
263
268
|
# KeySource/ValueSource: Dictionary fields (extensions, mapping)
|
|
264
269
|
# Extensions in OpenAPI objects use KeySource/ValueSource
|
|
265
|
-
root =
|
|
270
|
+
root = parser.parse("""
|
|
266
271
|
openapi: 3.0.4
|
|
267
272
|
info:
|
|
268
273
|
title: API
|
|
@@ -270,7 +275,7 @@ info:
|
|
|
270
275
|
x-custom: value
|
|
271
276
|
x-another: data
|
|
272
277
|
paths: {}
|
|
273
|
-
""")
|
|
278
|
+
""", return_type=MappingNode)
|
|
274
279
|
openapi_doc = build(root)
|
|
275
280
|
|
|
276
281
|
for key, value in openapi_doc.info.value.extensions.items():
|
|
@@ -285,7 +290,8 @@ for key, value in openapi_doc.info.value.extensions.items():
|
|
|
285
290
|
Access precise location ranges within the source document using start_mark and end_mark:
|
|
286
291
|
|
|
287
292
|
```python
|
|
288
|
-
from
|
|
293
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
294
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
289
295
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
290
296
|
|
|
291
297
|
yaml_content = """
|
|
@@ -297,8 +303,8 @@ info:
|
|
|
297
303
|
paths: {}
|
|
298
304
|
"""
|
|
299
305
|
|
|
300
|
-
|
|
301
|
-
root =
|
|
306
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
307
|
+
root = parser.parse(yaml_content, return_type=MappingNode)
|
|
302
308
|
openapi_doc = build(root)
|
|
303
309
|
|
|
304
310
|
# Access location information for any field
|
|
@@ -323,17 +329,18 @@ print(f"Field range: ({start.line}:{start.column}) to ({end.line}:{end.column})"
|
|
|
323
329
|
Low-level models preserve invalid data without validation:
|
|
324
330
|
|
|
325
331
|
```python
|
|
326
|
-
from
|
|
332
|
+
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
333
|
+
from jentic.apitools.openapi.parser.backends.ruamel_ast import MappingNode
|
|
327
334
|
from jentic.apitools.openapi.datamodels.low.v30 import build
|
|
328
335
|
|
|
329
|
-
|
|
330
|
-
root =
|
|
336
|
+
parser = OpenAPIParser("ruamel-ast")
|
|
337
|
+
root = parser.parse("""
|
|
331
338
|
openapi: 3.0.4
|
|
332
339
|
info:
|
|
333
340
|
title: 123 # Intentionally wrong type for demonstration (should be string)
|
|
334
341
|
version: 1.0.0
|
|
335
342
|
paths: {}
|
|
336
|
-
""")
|
|
343
|
+
""", return_type=MappingNode)
|
|
337
344
|
|
|
338
345
|
openapi_doc = build(root)
|
|
339
346
|
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.20"
|
|
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
|