Verified Commit 952a2a93 authored by Fabio Manganiello's avatar Fabio Manganiello
Browse files

- Render nested attributes in schemas

- Provide relevant examples for schema fields with no description/examples based on the field type

- Fixed RST warnings in Slack plugin

- Fixed list of events in ngrok plugin
parent 49676fcc
Pipeline #90 passed with stages
in 6 minutes and 1 second
......@@ -3,10 +3,12 @@ import json
import os
import re
import sys
from random import randint
from typing import Union, List
from docutils import nodes
from docutils.parsers.rst import Directive
from marshmallow import fields
class SchemaDirective(Directive):
......@@ -22,10 +24,29 @@ class SchemaDirective(Directive):
sys.path.insert(0, _schemas_path)
@staticmethod
def _get_field_value(field) -> str:
@classmethod
def _get_field_value(cls, field):
metadata = getattr(field, 'metadata', {})
return metadata.get('example', metadata.get('description', str(field.__class__.__name__).lower()))
if metadata.get('example'):
return metadata['example']
if metadata.get('description'):
return metadata['description']
if isinstance(field, fields.Number):
return randint(1, 99)
if isinstance(field, fields.Boolean):
return bool(randint(0, 1))
if isinstance(field, fields.URL):
return 'https://example.org'
if isinstance(field, fields.Nested):
ret = {
name: cls._get_field_value(f)
for name, f in field.nested().fields.items()
}
return [ret] if field.many else ret
return str(field.__class__.__name__).lower()
def _parse_schema(self) -> Union[dict, List[dict]]:
m = self._schema_regex.match('\n'.join(self.content))
......
manifest:
events: {}
events:
platypush.message.event.ngrok.NgrokProcessStartedEvent: when the ``ngrok`` process is started.
platypush.message.event.ngrok.NgrokProcessStoppedEvent: when the ``ngrok`` process is stopped.
platypush.message.event.ngrok.NgrokTunnelStartedEvent: when a tunnel is started.
platypush.message.event.ngrok.NgrokTunnelStoppedEvent: when a tunnel is stopped.
install:
pip:
- pyngrok
......
......@@ -53,8 +53,8 @@ class SlackPlugin(ChatPlugin, RunnablePlugin):
def __init__(self, app_token: str, bot_token: str, user_token: Optional[str] = None, **kwargs):
"""
:param app_token: Your Slack app token.
:param bot_token: Bot OAuth token reported on the _Install App_ menu.
:param user_token: User OAuth token reported on the _Install App_ menu.
:param bot_token: Bot OAuth token reported on the *Install App* menu.
:param user_token: User OAuth token reported on the *Install App* menu.
"""
super().__init__(**kwargs)
self._app_token = app_token
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment