Skip to content

Commit 3770471

Browse files
committed
feat: Using updated openapi library
1 parent 390ce1a commit 3770471

12 files changed

+1853
-1519
lines changed

poetry.lock

+1,707-1,266
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ keywords = ["OpenAPI", "Generator", "Python", "async"]
1717
Changelog = "https://github.com/MarcoMuellner/openapi-python-generator/releases"
1818

1919
[tool.poetry.dependencies]
20-
python = "^3.7"
20+
python = "^3.8"
2121
httpx = {extras = ["all"], version = "^0.23.0"}
22-
pydantic = "^1.9.1"
23-
orjson = "^3.7.2"
24-
openapi-schema-pydantic = "^1.2.3"
22+
pydantic = "^2.10.2"
23+
orjson = "^3.9.15"
2524
Jinja2 = "^3.1.2"
2625
click = "^8.1.3"
2726
black = ">=21.10b0"
2827
isort = ">=5.10.1"
28+
openapi-pydantic = "^0.5.0"
2929

3030
[tool.poetry.dev-dependencies]
3131
Pygments = ">=2.10.0"
@@ -48,7 +48,7 @@ typeguard = ">=2.13.3"
4848
xdoctest = {extras = ["colors"], version = ">=0.15.10"}
4949
myst-parser = {version = ">=0.16.1"}
5050
pytest-cov = "^3.0.0"
51-
fastapi = "^0.78.0"
51+
fastapi = "^0.115.5"
5252
uvicorn = "^0.18.1"
5353
respx = "^0.20.1"
5454
aiohttp = "^3.8.3"

src/openapi_python_generator/generate_data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from black import NothingChanged
1111
from httpx import ConnectError
1212
from httpx import ConnectTimeout
13-
from openapi_schema_pydantic import OpenAPI
13+
from openapi_pydantic.v3.v3_0 import OpenAPI
1414
from pydantic import ValidationError
1515

1616
from .common import HTTPLibrary
@@ -56,7 +56,8 @@ def get_open_api(source: Union[str, Path]) -> OpenAPI:
5656
return OpenAPI(**orjson.loads(httpx.get(source).text))
5757

5858
with open(source, "r") as f:
59-
return OpenAPI(**orjson.loads(f.read()))
59+
file_content = f.read()
60+
return OpenAPI(**orjson.loads(file_content))
6061
except FileNotFoundError:
6162
click.echo(
6263
f"File {source} not found. Please make sure to pass the path to the OpenAPI 3.0 specification."

src/openapi_python_generator/language_converters/python/api_config_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22

3-
from openapi_schema_pydantic import OpenAPI
3+
from openapi_pydantic.v3.v3_0 import OpenAPI
44

55
from openapi_python_generator.language_converters.python.jinja_config import (
66
API_CONFIG_TEMPLATE,

src/openapi_python_generator/language_converters/python/generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22

3-
from openapi_schema_pydantic import OpenAPI
3+
from openapi_pydantic.v3.v3_0 import OpenAPI
44

55
from openapi_python_generator.language_converters.python import common
66
from openapi_python_generator.language_converters.python.api_config_generator import (

src/openapi_python_generator/language_converters/python/model_generator.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
from typing import Optional
55

66
import click
7-
from openapi_schema_pydantic import Components
8-
from openapi_schema_pydantic import Reference
9-
from openapi_schema_pydantic import Schema
7+
from openapi_pydantic.v3.v3_0 import Schema, Reference, Components
108

119
from openapi_python_generator.language_converters.python import common
1210
from openapi_python_generator.language_converters.python.jinja_config import (
@@ -42,7 +40,7 @@ def type_converter( # noqa: C901
4240
pre_type = "Optional["
4341
post_type = "]"
4442

45-
original_type = schema.type if schema.type is not None else "object"
43+
original_type = schema.type.value if schema.type is not None else "object"
4644
import_types: Optional[List[str]] = None
4745

4846
if schema.allOf is not None:
@@ -156,7 +154,7 @@ def type_converter( # noqa: C901
156154
original_type = "array<" + converted_reference.type.original_type + ">"
157155
retVal += converted_reference.type.converted_type
158156
elif isinstance(schema.items, Schema):
159-
original_type = "array<" + str(schema.items.type) + ">"
157+
original_type = "array<" + (str(schema.items.type.value) if schema.items.type is not None else "unknown")+ ">"
160158
retVal += type_converter(schema.items, True).converted_type
161159
else:
162160
original_type = "array<unknown>"
@@ -196,11 +194,17 @@ def _generate_property_from_schema(
196194
and parent_schema.required is not None
197195
and name in parent_schema.required
198196
)
197+
198+
import_type = None
199+
if required:
200+
import_type = [] if name == model_name else [name]
201+
199202
return Property(
200203
name=name,
201204
type=type_converter(schema, required, model_name),
202205
required=required,
203206
default=None if required else "None",
207+
import_type=import_type,
204208
)
205209

206210

src/openapi_python_generator/language_converters/python/service_generator.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
from typing import Union
88

99
import click
10-
from openapi_schema_pydantic import MediaType
11-
from openapi_schema_pydantic import Operation
12-
from openapi_schema_pydantic import Parameter
13-
from openapi_schema_pydantic import PathItem
14-
from openapi_schema_pydantic import Reference
15-
from openapi_schema_pydantic import RequestBody
16-
from openapi_schema_pydantic import Response
17-
from openapi_schema_pydantic import Schema
10+
from openapi_pydantic.v3.v3_0 import Reference, Schema, Operation, Parameter, RequestBody, Response, MediaType, PathItem
1811

1912
from openapi_python_generator.language_converters.python import common
2013
from openapi_python_generator.language_converters.python.common import normalize_symbol

src/openapi_python_generator/models.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from typing import List
22
from typing import Optional
33

4-
from openapi_schema_pydantic import Operation
5-
from openapi_schema_pydantic import PathItem
6-
from openapi_schema_pydantic import Schema
4+
from openapi_pydantic.v3.v3_0 import Operation, PathItem, Schema
75
from pydantic import BaseModel
86

97

tests/conftest.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from typing import Generator
66

77
import pytest
8-
from openapi_schema_pydantic import OpenAPI
9-
8+
from openapi_pydantic.v3.v3_0 import OpenAPI
9+
from openapi_pydantic.v3.v3_0 import OpenAPI as OpenAPIv3_0
10+
from pydantic import ValidationError
1011

1112
test_data_folder = Path(__file__).parent / "test_data"
1213
test_data_path = test_data_folder / "test_api.json"
@@ -21,7 +22,10 @@ def json_data_fixture() -> Generator[Dict, None, None]:
2122

2223
@pytest.fixture(name="model_data", scope="module")
2324
def model_data_fixture(json_data) -> OpenAPI: # type: ignore
24-
yield OpenAPI(**json_data)
25+
try:
26+
yield OpenAPI(**json_data)
27+
except ValidationError:
28+
yield OpenAPIv3_0(**json_data)
2529

2630

2731
@pytest.fixture(name="model_data_with_cleanup", scope="module")

tests/test_api_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from openapi_schema_pydantic import OpenAPI
1+
from openapi_pydantic.v3.v3_0 import OpenAPI
22

33
from openapi_python_generator.language_converters.python.api_config_generator import (
44
generate_api_config,

0 commit comments

Comments
 (0)