Skip to content

Commit

Permalink
Merge pull request #33 from ioxiocom/feature/optional_skip_cleanup
Browse files Browse the repository at this point in the history
SpecRouter() `cleanup` arg
  • Loading branch information
lietu authored Oct 19, 2023
2 parents ada9da4 + 575d546 commit adf98a6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 48 deletions.
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

0 comments on commit adf98a6

Please sign in to comment.