|
1 | 1 | import os |
| 2 | +from pathlib import Path |
| 3 | +from typing import Dict, Any |
2 | 4 |
|
3 | 5 | import connexion |
4 | 6 | from connexion.resolver import RestyResolver |
5 | 7 |
|
| 8 | +try: |
| 9 | + import prance |
| 10 | +except ModuleNotFoundError: # pragma: no cover |
| 11 | + prance = None |
| 12 | + |
6 | 13 | from pyms.exceptions import AttrDoesNotExistException |
7 | 14 | from pyms.flask.services.driver import DriverService |
8 | 15 | from pyms.utils import check_package_exists |
@@ -40,6 +47,13 @@ def _get_application_root(config): |
40 | 47 | application_root = "/" |
41 | 48 | return application_root |
42 | 49 |
|
| 50 | + @staticmethod |
| 51 | + def get_bundled_specs(main_file: Path) -> Dict[str, Any]: |
| 52 | + parser = prance.ResolvingParser(str(main_file.absolute()), |
| 53 | + lazy=True, backend='openapi-spec-validator') |
| 54 | + parser.parse() |
| 55 | + return parser.specification |
| 56 | + |
43 | 57 | def init_app(self, config, path): |
44 | 58 | """ |
45 | 59 | Initialize Connexion App. See more info in [Connexion Github](https://github.com/zalando/connexion) |
@@ -75,7 +89,8 @@ def init_app(self, config, path): |
75 | 89 | resolver=RestyResolver(self.project_dir)) |
76 | 90 |
|
77 | 91 | params = { |
78 | | - "specification": self.file, |
| 92 | + "specification": self.get_bundled_specs( |
| 93 | + Path(os.path.join(specification_dir, self.file))) if prance else self.file, |
79 | 94 | "arguments": {'title': config.APP_NAME}, |
80 | 95 | "base_path": application_root, |
81 | 96 | "options": {"swagger_url": self.url}, |
|
0 commit comments