Skip to content

Commit 0e3ab07

Browse files
f-arruzaFernando Arruza
and
Fernando Arruza
authored
Use prance library to get bundled specs (#115)
* use prance library to get bundled OAS * prevent import errors Co-authored-by: Fernando Arruza <[email protected]>
1 parent 4a13881 commit 0e3ab07

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

Pipfile.lock

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyms/flask/services/swagger.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import os
2+
from pathlib import Path
3+
from typing import Dict, Any
24

35
import connexion
46
from connexion.resolver import RestyResolver
57

8+
try:
9+
import prance
10+
except ModuleNotFoundError: # pragma: no cover
11+
prance = None
12+
613
from pyms.exceptions import AttrDoesNotExistException
714
from pyms.flask.services.driver import DriverService
815
from pyms.utils import check_package_exists
@@ -40,6 +47,13 @@ def _get_application_root(config):
4047
application_root = "/"
4148
return application_root
4249

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+
4357
def init_app(self, config, path):
4458
"""
4559
Initialize Connexion App. See more info in [Connexion Github](https://github.com/zalando/connexion)
@@ -75,7 +89,8 @@ def init_app(self, config, path):
7589
resolver=RestyResolver(self.project_dir))
7690

7791
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,
7994
"arguments": {'title': config.APP_NAME},
8095
"base_path": application_root,
8196
"options": {"swagger_url": self.url},

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
'connexion[swagger-ui]>=2.6.0',
4040
'swagger-ui-bundle>=0.0.6',
4141
'anyconfig>=0.9.8',
42+
'semver>=2.9.1',
43+
'prance>=0.18.2',
4244
]
4345

4446
install_traces_requires = [

tests/swagger.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ paths:
3838
produces:
3939
- "application/json"
4040
responses:
41-
200:
41+
"200":
4242
description: "Example"
43-
405:
43+
"405":
4444
description: "Invalid input"
4545
x-swagger-router-controller: "tests.test_flask"
4646
externalDocs:

tests/swagger_for_tests/swagger.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ paths:
3838
produces:
3939
- "application/json"
4040
responses:
41-
200:
41+
"200":
4242
description: "Example"
43-
405:
43+
"405":
4444
description: "Invalid input"
4545
x-swagger-router-controller: "tests.test_flask"
4646
externalDocs:

0 commit comments

Comments
 (0)