jentic-openapi-parser 1.0.0a21__py3-none-any.whl → 1.0.0a23__py3-none-any.whl
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/apitools/openapi/parser/core/openapi_parser.py +22 -1
- {jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/METADATA +15 -5
- {jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/RECORD +7 -7
- {jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/WHEEL +0 -0
- {jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/entry_points.txt +0 -0
- {jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/licenses/LICENSE +0 -0
- {jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import importlib.metadata
|
|
2
2
|
import logging
|
|
3
|
+
import types
|
|
3
4
|
import warnings
|
|
4
5
|
from typing import Any, Mapping, Optional, Sequence, Type, TypeVar, cast, overload
|
|
5
6
|
|
|
@@ -106,8 +107,17 @@ class OpenAPIParser:
|
|
|
106
107
|
@overload
|
|
107
108
|
def parse(self, document: str, *, return_type: type[T], strict: bool = False) -> T: ...
|
|
108
109
|
|
|
110
|
+
@overload
|
|
111
|
+
def parse(
|
|
112
|
+
self, document: str, *, return_type: types.UnionType, strict: bool = False
|
|
113
|
+
) -> Any: ...
|
|
114
|
+
|
|
109
115
|
def parse(
|
|
110
|
-
self,
|
|
116
|
+
self,
|
|
117
|
+
document: str,
|
|
118
|
+
*,
|
|
119
|
+
return_type: type[T] | types.UnionType | None = None,
|
|
120
|
+
strict: bool = False,
|
|
111
121
|
) -> Any:
|
|
112
122
|
try:
|
|
113
123
|
raw = self._parse(document)
|
|
@@ -119,6 +129,17 @@ class OpenAPIParser:
|
|
|
119
129
|
if return_type is None:
|
|
120
130
|
return self._to_plain(raw)
|
|
121
131
|
|
|
132
|
+
# Handle union types
|
|
133
|
+
if isinstance(return_type, types.UnionType):
|
|
134
|
+
if strict:
|
|
135
|
+
# Python 3.11+ supports isinstance with UnionType directly
|
|
136
|
+
if not isinstance(raw, return_type):
|
|
137
|
+
type_names = " | ".join(t.__name__ for t in return_type.__args__)
|
|
138
|
+
self.logger.error(f"Expected {type_names}, got {type(raw).__name__}")
|
|
139
|
+
raise TypeConversionError(f"Expected {type_names}, got {type(raw).__name__}")
|
|
140
|
+
return raw
|
|
141
|
+
|
|
142
|
+
# Handle concrete types
|
|
122
143
|
if strict:
|
|
123
144
|
if not isinstance(raw, return_type):
|
|
124
145
|
msg = f"Expected {getattr(return_type, '__name__', return_type)}, got {type(raw).__name__}"
|
{jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jentic-openapi-parser
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0a23
|
|
4
4
|
Summary: Jentic OpenAPI Parser
|
|
5
5
|
Author: Jentic
|
|
6
6
|
Author-email: Jentic <hello@jentic.com>
|
|
@@ -8,8 +8,8 @@ License-Expression: Apache-2.0
|
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
License-File: NOTICE
|
|
10
10
|
Requires-Dist: attrs~=25.4.0
|
|
11
|
-
Requires-Dist: jentic-openapi-common~=1.0.
|
|
12
|
-
Requires-Dist: jentic-openapi-datamodels~=1.0.
|
|
11
|
+
Requires-Dist: jentic-openapi-common~=1.0.0a23
|
|
12
|
+
Requires-Dist: jentic-openapi-datamodels~=1.0.0a23
|
|
13
13
|
Requires-Dist: pyyaml~=6.0.3
|
|
14
14
|
Requires-Dist: requests~=2.32.5
|
|
15
15
|
Requires-Dist: ruamel-yaml~=0.18.15
|
|
@@ -337,24 +337,34 @@ Low-level OpenAPI data model parser that automatically detects the OpenAPI versi
|
|
|
337
337
|
|
|
338
338
|
```python
|
|
339
339
|
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
340
|
+
from jentic.apitools.openapi.parser.backends.datamodel_low import DataModelLow
|
|
340
341
|
from jentic.apitools.openapi.datamodels.low.v30.openapi import OpenAPI30
|
|
341
342
|
from jentic.apitools.openapi.datamodels.low.v31.openapi import OpenAPI31
|
|
342
343
|
|
|
344
|
+
|
|
343
345
|
parser = OpenAPIParser("datamodel-low")
|
|
344
346
|
|
|
345
347
|
# Parse OpenAPI 3.0.x document
|
|
346
|
-
doc = parser.parse("file:///path/to/openapi-3.0.yaml")
|
|
348
|
+
doc = parser.parse("file:///path/to/openapi-3.0.yaml", return_type=OpenAPI30)
|
|
347
349
|
assert isinstance(doc, OpenAPI30)
|
|
348
350
|
print(doc.openapi.value) # "3.0.4"
|
|
349
351
|
print(doc.info.value.title.value) # Access with source tracking
|
|
350
352
|
|
|
351
353
|
# Parse OpenAPI 3.1.x document
|
|
352
|
-
doc = parser.parse("file:///path/to/openapi-3.1.yaml")
|
|
354
|
+
doc = parser.parse("file:///path/to/openapi-3.1.yaml", return_type=OpenAPI31)
|
|
353
355
|
assert isinstance(doc, OpenAPI31)
|
|
354
356
|
print(doc.openapi.value) # "3.1.2"
|
|
355
357
|
|
|
356
358
|
# Access fields with source information
|
|
357
359
|
print(f"Title at line {doc.info.key_node.start_mark.line}")
|
|
360
|
+
|
|
361
|
+
doc = parser.parse("file:///path/to/openapi.yaml", return_type=DataModelLow)
|
|
362
|
+
# Type checker sees 'Any', runtime type will be one of: OpenAPI30, OpenAPI31, or ValueSource
|
|
363
|
+
print(type(doc).__name__) # "OpenAPI30" or "OpenAPI31"
|
|
364
|
+
|
|
365
|
+
# Optional: Enable strict runtime validation
|
|
366
|
+
doc = parser.parse("file:///path/to/openapi.yaml", return_type=DataModelLow, strict=True)
|
|
367
|
+
# Raises TypeConversionError if result is not one of the union types
|
|
358
368
|
```
|
|
359
369
|
|
|
360
370
|
**Features:**
|
{jentic_openapi_parser-1.0.0a21.dist-info → jentic_openapi_parser-1.0.0a23.dist-info}/RECORD
RENAMED
|
@@ -8,12 +8,12 @@ jentic/apitools/openapi/parser/backends/ruamel_safe.py,sha256=9WNBgcU9wotBWIYOgA
|
|
|
8
8
|
jentic/apitools/openapi/parser/core/__init__.py,sha256=FChrSb22a7m9LOku4KG0_Vsm4ConyEAlrFW3qLXjMAY,578
|
|
9
9
|
jentic/apitools/openapi/parser/core/exceptions.py,sha256=wtH_kRvn3b3TsM4HEkTKLCdIQVEfsN-dEct8oVlnGrM,693
|
|
10
10
|
jentic/apitools/openapi/parser/core/loader.py,sha256=Q57UiWiJACeuxMdroHAAEcoU-lwvxiRBcdz106N2VVQ,1462
|
|
11
|
-
jentic/apitools/openapi/parser/core/openapi_parser.py,sha256=
|
|
11
|
+
jentic/apitools/openapi/parser/core/openapi_parser.py,sha256=ACoiv4bTYhmZQizkzhkMTKbkE0iMBg-dGmaPj9oGbJg,8309
|
|
12
12
|
jentic/apitools/openapi/parser/core/py.typed,sha256=uEf7mrkecd7wYBi4Jxa95cHb65ZSz_tMK6UDi55KymA,33
|
|
13
13
|
jentic/apitools/openapi/parser/core/serialization.py,sha256=qr9CBgZzb9GKRPTwOb_MmS0-GdHpVZLmXiHiX1n1cIM,2810
|
|
14
|
-
jentic_openapi_parser-1.0.
|
|
15
|
-
jentic_openapi_parser-1.0.
|
|
16
|
-
jentic_openapi_parser-1.0.
|
|
17
|
-
jentic_openapi_parser-1.0.
|
|
18
|
-
jentic_openapi_parser-1.0.
|
|
19
|
-
jentic_openapi_parser-1.0.
|
|
14
|
+
jentic_openapi_parser-1.0.0a23.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
15
|
+
jentic_openapi_parser-1.0.0a23.dist-info/licenses/NOTICE,sha256=pAOGW-rGw9KNc2cuuLWZkfx0GSTV4TicbgBKZSLPMIs,168
|
|
16
|
+
jentic_openapi_parser-1.0.0a23.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
17
|
+
jentic_openapi_parser-1.0.0a23.dist-info/entry_points.txt,sha256=eMCrbxAvCRJRKUU4ZwsD-soLKoDomhzrJ19ayMyeXNo,497
|
|
18
|
+
jentic_openapi_parser-1.0.0a23.dist-info/METADATA,sha256=2T-h8lJuzA8MLbC_DNBz7pbbpo40Rb5E4Ne3IKd6csQ,12330
|
|
19
|
+
jentic_openapi_parser-1.0.0a23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|