Skip to content

Commit d595799

Browse files
committed
- Added testing for generated code with the httpx library
- fixed build process for nox for the vast majority (rest isn't too important) - Fixed various small errors while testing the generated code - Added TypeConversion Model for generated types and to ease import statements - Models now do specific referencing to other models
1 parent 765c079 commit d595799

File tree

17 files changed

+784
-393
lines changed

17 files changed

+784
-393
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ application-import-names = openapi_python_generator
55
import-order-style = google
66
ignore = E203,E501,W503
77
max-line-length = 120
8-
per-file-ignores = tests/*:S101
8+
exclude=tests/*

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ ignore_missing_imports = True
88

99
[mypy-autopep8.*]
1010
ignore_missing_imports = True
11+
12+
[mypy-uvicorn.*]
13+
ignore_missing_imports = True

noxfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def mypy(session: Session) -> None:
149149
"""Type-check using mypy."""
150150
args = session.posargs or ["src", "tests", "docs/conf.py"]
151151
session.install(".")
152-
session.install("mypy", "pytest")
152+
session.install("mypy", "pytest", "respx", "fastapi", "uvicorn")
153153
session.run("mypy", *args)
154154
if not session.posargs:
155155
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
@@ -159,7 +159,7 @@ def mypy(session: Session) -> None:
159159
def tests(session: Session) -> None:
160160
"""Run the test suite."""
161161
session.install(".")
162-
session.install("coverage[toml]", "pytest", "pygments")
162+
session.install("coverage[toml]", "pytest", "pygments", "respx", "fastapi")
163163
try:
164164
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
165165
finally:
@@ -184,7 +184,7 @@ def coverage(session: Session) -> None:
184184
def typeguard(session: Session) -> None:
185185
"""Runtime type checking using Typeguard."""
186186
session.install(".")
187-
session.install("pytest", "typeguard", "pygments")
187+
session.install("pytest", "typeguard", "pygments", "respx", "fastapi", "uvicorn")
188188
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
189189

190190

poetry.lock

Lines changed: 77 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openapi-python-generator"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = "Openapi Python Generator"
55
authors = ["Marco Müllner <[email protected]>"]
66
license = "MIT"
@@ -51,6 +51,9 @@ typeguard = ">=2.13.3"
5151
xdoctest = {extras = ["colors"], version = ">=0.15.10"}
5252
myst-parser = {version = ">=0.16.1"}
5353
pytest-cov = "^3.0.0"
54+
fastapi = "^0.78.0"
55+
uvicorn = "^0.18.1"
56+
respx = "^0.19.2"
5457

5558
[tool.poetry.scripts]
5659
openapi-python-generator = "openapi_python_generator.__main__:main"

src/openapi_python_generator/generate_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def write_data(data: ConversionResult, output: Union[str, Path]):
8484
# Create models.__init__.py file containing imports to all models.
8585
write_code(
8686
models_path / "__init__.py",
87-
"\n".join([f"from {file} import *" for file in files]),
87+
"\n".join([f"from .{file} import *" for file in files]),
8888
)
8989

9090
files = []
@@ -100,7 +100,7 @@ def write_data(data: ConversionResult, output: Union[str, Path]):
100100
# Create services.__init__.py file containing imports to all services.
101101
write_code(
102102
services_path / "__init__.py",
103-
"\n".join([f"from {file} import *" for file in files]),
103+
"\n".join([f"from .{file} import *" for file in files]),
104104
)
105105

106106
# Write the api_config.py file.
@@ -109,7 +109,7 @@ def write_data(data: ConversionResult, output: Union[str, Path]):
109109
# Write the __init__.py file.
110110
write_code(
111111
Path(output) / "__init__.py",
112-
"from models import *\nfrom services import *\nfrom api_config import *",
112+
"from .models import *\nfrom .services import *\nfrom .api_config import *",
113113
)
114114

115115

src/openapi_python_generator/language_converters/python/api_config_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ def generate_api_config(data: OpenAPI) -> APIConfig:
1414
return APIConfig(
1515
file_name="api_config",
1616
content=JINJA_ENV.get_template(API_CONFIG_TEMPLATE).render(**data.dict()),
17+
base_url=data.servers[0].url,
1718
)

0 commit comments

Comments
 (0)