forked from platypush/platypush
- 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
This commit is contained in:
parent
49676fcc7f
commit
952a2a9379
3 changed files with 31 additions and 6 deletions
|
@ -3,10 +3,12 @@ import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
from random import randint
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.parsers.rst import Directive
|
from docutils.parsers.rst import Directive
|
||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
|
||||||
class SchemaDirective(Directive):
|
class SchemaDirective(Directive):
|
||||||
|
@ -22,10 +24,29 @@ class SchemaDirective(Directive):
|
||||||
|
|
||||||
sys.path.insert(0, _schemas_path)
|
sys.path.insert(0, _schemas_path)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def _get_field_value(field) -> str:
|
def _get_field_value(cls, field):
|
||||||
metadata = getattr(field, 'metadata', {})
|
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]]:
|
def _parse_schema(self) -> Union[dict, List[dict]]:
|
||||||
m = self._schema_regex.match('\n'.join(self.content))
|
m = self._schema_regex.match('\n'.join(self.content))
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
manifest:
|
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:
|
install:
|
||||||
pip:
|
pip:
|
||||||
- pyngrok
|
- pyngrok
|
||||||
|
|
|
@ -53,8 +53,8 @@ class SlackPlugin(ChatPlugin, RunnablePlugin):
|
||||||
def __init__(self, app_token: str, bot_token: str, user_token: Optional[str] = None, **kwargs):
|
def __init__(self, app_token: str, bot_token: str, user_token: Optional[str] = None, **kwargs):
|
||||||
"""
|
"""
|
||||||
:param app_token: Your Slack app token.
|
:param app_token: Your Slack app token.
|
||||||
:param bot_token: Bot 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.
|
:param user_token: User OAuth token reported on the *Install App* menu.
|
||||||
"""
|
"""
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self._app_token = app_token
|
self._app_token = app_token
|
||||||
|
|
Loading…
Reference in a new issue