Allow configuration of openAPI interface

This commit is contained in:
Matthias 2020-12-27 15:54:05 +01:00
parent 1717121f10
commit 68d148e72d
3 changed files with 15 additions and 2 deletions

View File

@ -165,6 +165,7 @@
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
"verbosity": "info",
"enable_openapi": false,
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "freqtrader",

View File

@ -12,6 +12,7 @@ Sample configuration:
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
"verbosity": "info",
"enable_openapi": false,
"jwt_secret_key": "somethingrandom",
"CORS_origins": [],
"username": "Freqtrader",
@ -263,6 +264,11 @@ whitelist
```
## OpenAPI interface
To enable the builtin openAPI interface, specify `"enable_openapi": true` in the api_server configuration.
This will enable the Swagger UI at the `/docs` endpoint. By default, that's running at http://localhost:8080/docs/ - but it'll depend on your settings.
## Advanced API usage using JWT tokens
!!! Note

View File

@ -26,8 +26,13 @@ class ApiServer(RPCHandler):
ApiServer._rpc = rpc
ApiServer._config = config
api_config = self._config['api_server']
self.app = FastAPI(title="Freqtrade API")
self.app = FastAPI(title="Freqtrade API",
openapi_url='openapi.json' if api_config.get(
'enable_openapi') else None,
redoc_url=None,
)
self.configure_app(self.app, self._config)
self.start_api()
@ -92,10 +97,11 @@ class ApiServer(RPCHandler):
"Others may be able to log into your bot.")
logger.info('Starting Local Rest Server.')
verbosity = self._config['api_server'].get('verbosity', 'info')
uvconfig = uvicorn.Config(self.app,
port=rest_port,
host=rest_ip,
access_log=True)
access_log=True if verbosity != 'error' else False)
try:
self._server = UvicornServer(uvconfig)
self._server.run_in_thread()