Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpecRouter() cleanup arg #33

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ This validator can also be reused when generating routes:
router = SpecRouter(specs, validators=[MyValidator])
```

## Development

You will need:

- Python 3.7+ (though 3.11+ might have some issues with dependencies)
- [pre-commit](https://pre-commit.com/#install)

Before working on the project, make sure you run:

```shell
pre-commit install
```

After making changes you can run tests:

```shell
poetry run invoke test
```

## License

This code is released under the BSD 3-Clause license. Details in the
Expand Down
9 changes: 6 additions & 3 deletions openapi_to_fastapi/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ def __init__(
specs_path: Union[str, Path],
validators: Optional[List[Type[BaseValidator]]] = None,
format_code: bool = False,
cleanup: bool = True,
):
self._validators = [DefaultValidator] + (validators or []) # type: ignore
self._routes = RoutesMapping(post_map={}, get_map={})
self._format_code = format_code

self.specs_path = Path(specs_path)
self._validate_and_parse_specs()
self._validate_and_parse_specs(cleanup)

@property
def get_map(self) -> Optional[Dict[str, RouteInfo]]:
Expand All @@ -101,7 +102,7 @@ def post_map(self) -> Optional[Dict[str, RouteInfo]]:
"""
return self._routes.post_map

def _validate_and_parse_specs(self):
def _validate_and_parse_specs(self, cleanup=True):
"""
Validate OpenAPI specs and parse required information from them
"""
Expand All @@ -117,7 +118,9 @@ def _validate_and_parse_specs(self):
raw_spec = spec_path.read_text(encoding="utf8")
json_spec = json.loads(raw_spec)
for path, path_item in parse_openapi_spec(json_spec).items():
models = load_models(raw_spec, path, format_code=self._format_code)
models = load_models(
raw_spec, path, cleanup=cleanup, format_code=self._format_code
)
post = path_item.post
if post:
req_model = getattr(models, post.requestBodyModel, EmptyBody)
Expand Down
89 changes: 45 additions & 44 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openapi-to-fastapi"
version = "0.12.0"
version = "0.12.1"
description = "Create FastAPI routes from OpenAPI spec"
authors = ["IOXIO Ltd"]
license = "BSD-3-Clause"
Expand Down