Skip to content

Use prance library to get bundled specs #115

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

Merged
merged 6 commits into from
Apr 21, 2020
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
30 changes: 30 additions & 0 deletions Pipfile.lock

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

17 changes: 16 additions & 1 deletion pyms/flask/services/swagger.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import os
from pathlib import Path
from typing import Dict, Any

import connexion
from connexion.resolver import RestyResolver

try:
import prance
except ModuleNotFoundError: # pragma: no cover
prance = None

from pyms.exceptions import AttrDoesNotExistException
from pyms.flask.services.driver import DriverService
from pyms.utils import check_package_exists
Expand Down Expand Up @@ -40,6 +47,13 @@ def _get_application_root(config):
application_root = "/"
return application_root

@staticmethod
def get_bundled_specs(main_file: Path) -> Dict[str, Any]:
parser = prance.ResolvingParser(str(main_file.absolute()),
lazy=True, backend='openapi-spec-validator')
parser.parse()
return parser.specification

def init_app(self, config, path):
"""
Initialize Connexion App. See more info in [Connexion Github](https://github.com/zalando/connexion)
Expand Down Expand Up @@ -75,7 +89,8 @@ def init_app(self, config, path):
resolver=RestyResolver(self.project_dir))

params = {
"specification": self.file,
"specification": self.get_bundled_specs(
Path(os.path.join(specification_dir, self.file))) if prance else self.file,
"arguments": {'title': config.APP_NAME},
"base_path": application_root,
"options": {"swagger_url": self.url},
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
'connexion[swagger-ui]>=2.6.0',
'swagger-ui-bundle>=0.0.6',
'anyconfig>=0.9.8',
'semver>=2.9.1',
'prance>=0.18.2',
]

install_traces_requires = [
Expand Down
4 changes: 2 additions & 2 deletions tests/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ paths:
produces:
- "application/json"
responses:
200:
"200":
description: "Example"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "tests.test_flask"
externalDocs:
Expand Down
4 changes: 2 additions & 2 deletions tests/swagger_for_tests/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ paths:
produces:
- "application/json"
responses:
200:
"200":
description: "Example"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "tests.test_flask"
externalDocs:
Expand Down