How to use the apispec.utils.dedent function in apispec

To help you get started, we’ve selected a few apispec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tribe29 / checkmk / cmk / gui / plugins / openapi / restful_objects / decorators.py View on Github external
This is part of the rest.

    >>> _docstring_name(_docstring_name.__doc__)
    'Split the docstring by title and rest.'

    Args:
        docstring:

    Returns:
        A string or nothing.

    """ ""
    if not docstring:
        return None
    parts = apispec.utils.dedent(docstring).split("\n\n", 1)
    if len(parts) > 0:
        return parts[0].strip()
    return None
github marshmallow-code / apispec / src / apispec / yaml_utils.py View on Github external
def load_yaml_from_docstring(docstring):
    """Loads YAML from docstring."""
    split_lines = trim_docstring(docstring).split("\n")

    # Cut YAML from rest of docstring
    for index, line in enumerate(split_lines):
        line = line.strip()
        if line.startswith("---"):
            cut_from = index
            break
    else:
        return {}

    yaml_string = "\n".join(split_lines[cut_from:])
    yaml_string = dedent(yaml_string)
    return yaml.safe_load(yaml_string) or {}
github tribe29 / checkmk / cmk / gui / plugins / openapi / restful_objects / decorators.py View on Github external
This is part of the rest.

    >>> _docstring_description(_docstring_description.__doc__).split("\\n")[0]
    'This is part of the rest.'

    Args:
        docstring:

    Returns:
        A string or nothing.

    """
    if not docstring:
        return None
    parts = apispec.utils.dedent(docstring).split("\n\n", 1)
    if len(parts) > 1:
        return parts[1].strip()
    return None
github tribe29 / checkmk / cmk / gui / plugins / openapi / restful_objects / decorators.py View on Github external
if etag in ('output', 'both'):
            headers.update(ETAG_HEADER_PARAM.header_dict())

        # Not sure why mypy doesn't believe this to be a ResponseType. It's not even a TypedDict.
        responses: ResponseType = cast(ResponseType, {})

        # We don't(!) support any endpoint without an output schema.
        # Just define one!
        if response_schema is not None:
            responses['200'] = {
                'content': {
                    content_type: {
                        'schema': response_schema
                    },
                },
                'description': apispec.utils.dedent(response_schema.__doc__ or ''),
                'headers': headers,
            }

        if will_do_redirects:
            responses['302'] = {
                'description':
                    ('Either the resource has moved or has not yet completed. Please see this '
                     'resource for further information.')
            }

        # Actually, iff you don't want to give out anything, then we don't need a schema.
        if output_empty:
            responses['204'] = {
                'description': 'Operation done successfully. No further output.',
                'headers': headers,
            }
github tribe29 / checkmk / cmk / gui / plugins / openapi / restful_objects / specification.py View on Github external
import apispec.utils  # type: ignore
import apispec_oneofschema  # type: ignore

from cmk.gui.plugins.openapi import plugins
from cmk.gui.plugins.openapi.restful_objects.parameters import HOST_NAME, IDENT, NAME, ACCEPT_HEADER

# Path parameters look like {varname} and need to be checked.
from cmk.gui.plugins.openapi.restful_objects.type_defs import ParameterReference, PrimitiveParameter

DEFAULT_HEADERS = [
    ('Accept', 'Media type(s) that is/are acceptable for the response.', 'application/json'),
]

OPTIONS = {
    'info': {
        'description': apispec.utils.dedent(__doc__).strip(),
        'license': {
            'name': 'GNU General Public License version 2',
            'url': 'https://checkmk.com/gpl.html',
        },
        'contact': {
            'name': 'Contact the Checkmk Team',
            'url': 'https://checkmk.com/contact.php',
            'email': 'feedback@checkmk.com'
        },
    },
    'externalDocs': {
        'description': 'The Checkmk Handbook',
        'url': 'https://checkmk.com/cms.html',
    },
    'x-logo': {
        'url': 'https://checkmk.com/bilder/brand-assets/checkmk_logo_main.png',
github marshmallow-code / flask-smorest / flask_smorest / utils.py View on Github external
cut_at = index + 1
        split_lines = split_lines[:cut_at]

    # Description is separated from summary by an empty line
    for index, line in enumerate(split_lines):
        if line.strip() == '':
            summary_lines = split_lines[:index]
            description_lines = split_lines[index + 1:]
            break
    else:
        summary_lines = split_lines
        description_lines = []

    info = {}
    if summary_lines:
        info['summary'] = dedent('\n'.join(summary_lines))
    if description_lines:
        info['description'] = dedent('\n'.join(description_lines))
    return info