jentic-openapi-parser 1.0.0a22__tar.gz → 1.0.0a23__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_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/PKG-INFO +15 -5
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/README.md +12 -2
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/pyproject.toml +3 -3
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/core/openapi_parser.py +22 -1
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/LICENSE +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/NOTICE +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/base.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/datamodel_low.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/py.typed +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/pyyaml.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/ruamel_ast.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/ruamel_roundtrip.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/backends/ruamel_safe.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/core/__init__.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/core/exceptions.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/core/loader.py +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/core/py.typed +0 -0
- {jentic_openapi_parser-1.0.0a22 → jentic_openapi_parser-1.0.0a23}/src/jentic/apitools/openapi/parser/core/serialization.py +0 -0
|
@@ -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:**
|
|
@@ -318,24 +318,34 @@ Low-level OpenAPI data model parser that automatically detects the OpenAPI versi
|
|
|
318
318
|
|
|
319
319
|
```python
|
|
320
320
|
from jentic.apitools.openapi.parser.core import OpenAPIParser
|
|
321
|
+
from jentic.apitools.openapi.parser.backends.datamodel_low import DataModelLow
|
|
321
322
|
from jentic.apitools.openapi.datamodels.low.v30.openapi import OpenAPI30
|
|
322
323
|
from jentic.apitools.openapi.datamodels.low.v31.openapi import OpenAPI31
|
|
323
324
|
|
|
325
|
+
|
|
324
326
|
parser = OpenAPIParser("datamodel-low")
|
|
325
327
|
|
|
326
328
|
# Parse OpenAPI 3.0.x document
|
|
327
|
-
doc = parser.parse("file:///path/to/openapi-3.0.yaml")
|
|
329
|
+
doc = parser.parse("file:///path/to/openapi-3.0.yaml", return_type=OpenAPI30)
|
|
328
330
|
assert isinstance(doc, OpenAPI30)
|
|
329
331
|
print(doc.openapi.value) # "3.0.4"
|
|
330
332
|
print(doc.info.value.title.value) # Access with source tracking
|
|
331
333
|
|
|
332
334
|
# Parse OpenAPI 3.1.x document
|
|
333
|
-
doc = parser.parse("file:///path/to/openapi-3.1.yaml")
|
|
335
|
+
doc = parser.parse("file:///path/to/openapi-3.1.yaml", return_type=OpenAPI31)
|
|
334
336
|
assert isinstance(doc, OpenAPI31)
|
|
335
337
|
print(doc.openapi.value) # "3.1.2"
|
|
336
338
|
|
|
337
339
|
# Access fields with source information
|
|
338
340
|
print(f"Title at line {doc.info.key_node.start_mark.line}")
|
|
341
|
+
|
|
342
|
+
doc = parser.parse("file:///path/to/openapi.yaml", return_type=DataModelLow)
|
|
343
|
+
# Type checker sees 'Any', runtime type will be one of: OpenAPI30, OpenAPI31, or ValueSource
|
|
344
|
+
print(type(doc).__name__) # "OpenAPI30" or "OpenAPI31"
|
|
345
|
+
|
|
346
|
+
# Optional: Enable strict runtime validation
|
|
347
|
+
doc = parser.parse("file:///path/to/openapi.yaml", return_type=DataModelLow, strict=True)
|
|
348
|
+
# Raises TypeConversionError if result is not one of the union types
|
|
339
349
|
```
|
|
340
350
|
|
|
341
351
|
**Features:**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "jentic-openapi-parser"
|
|
3
|
-
version = "1.0.0-alpha.
|
|
3
|
+
version = "1.0.0-alpha.23"
|
|
4
4
|
description = "Jentic OpenAPI Parser"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Jentic", email = "hello@jentic.com" }]
|
|
@@ -9,8 +9,8 @@ license-files = ["LICENSE", "NOTICE"]
|
|
|
9
9
|
requires-python = ">=3.11"
|
|
10
10
|
dependencies = [
|
|
11
11
|
"attrs~=25.4.0",
|
|
12
|
-
"jentic-openapi-common~=1.0.0-alpha.
|
|
13
|
-
"jentic-openapi-datamodels~=1.0.0-alpha.
|
|
12
|
+
"jentic-openapi-common~=1.0.0-alpha.23",
|
|
13
|
+
"jentic-openapi-datamodels~=1.0.0-alpha.23",
|
|
14
14
|
"pyyaml~=6.0.3",
|
|
15
15
|
"requests~=2.32.5",
|
|
16
16
|
"ruamel-yaml~=0.18.15"
|
|
@@ -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__}"
|
|
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
|