-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from jacekv/feature/PAN-2158-api-docs
PAN-2158: Adding OpenAPI docs generation
- Loading branch information
Showing
6 changed files
with
264 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
from apispec.ext.marshmallow import MarshmallowPlugin | ||
from apispec_webframeworks.flask import FlaskPlugin | ||
from flasgger import APISpec # type: ignore | ||
from flasgger import Swagger | ||
|
||
from pantos.servicenode.restapi import _BidSchema | ||
from pantos.servicenode.restapi import _BidsSchema | ||
from pantos.servicenode.restapi import _TransferSchema | ||
from pantos.servicenode.restapi import _TransferStatusSchema | ||
from pantos.servicenode.restapi import flask_app | ||
|
||
DOCS_PATH = "docs/openapi.json" | ||
|
||
if len(sys.argv) > 1: | ||
DOCS_PATH = sys.argv[1] | ||
|
||
plugins = [FlaskPlugin(), MarshmallowPlugin()] | ||
spec = APISpec("Pantos Service Node APISpec", '1.0', "3.0.2", plugins=plugins) | ||
|
||
template = spec.to_flasgger( | ||
flask_app, definitions=[ | ||
_BidSchema, _BidsSchema, _TransferSchema, _TransferStatusSchema | ||
]) | ||
|
||
swagger = Swagger(flask_app, template=template, parse=True) | ||
|
||
with flask_app.test_request_context(): | ||
data = swagger.get_apispecs() | ||
data.pop('definitions') | ||
data.pop('swagger') | ||
data['servers'] = [{'url': 'https://sn1.testnet.pantos.io'}] | ||
|
||
if not (Path.cwd() / DOCS_PATH).exists(): | ||
os.makedirs(os.path.dirname(DOCS_PATH), exist_ok=True) | ||
|
||
with open(DOCS_PATH, "w") as f: | ||
f.write(json.dumps(data, indent=4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters