Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make docstring parser more flexible #85

Open
costrouc opened this issue Jan 9, 2020 · 0 comments
Open

Make docstring parser more flexible #85

costrouc opened this issue Jan 9, 2020 · 0 comments

Comments

@costrouc
Copy link

costrouc commented Jan 9, 2020

This is an issue to judge interest in making the parser for docstrings more flexible (I will create a PR if so). Currently it looks like everything past --- is interpreted as a swagger specification for a route. I would like to create a PR for a docstring_handler function that can parse a given docstring and return the dict of the yaml specification. In my case I am using numpy docstring style https://www.sphinx-doc.org/en/master/usage/extensions/example_numpy.html and the --- conflicts with the documentation syntax. I would like to add a docstring_handler to can parse a specification like so.

def function_with_types_in_docstring(param1, param2):
    """Example function with types documented in the docstring.

    `PEP 484`_ type annotations are supported. If attribute, parameter, and
    return types are annotated according to `PEP 484`_, they do not need to be
    included in the docstring:

    Parameters
    ----------
    param1 : int
        The first parameter.
    param2 : str
        The second parameter.

    Route
    --------
    
    .. code-block:: yaml
 
              summary: Adds a new user
                requestBody:
                  content:
                    application/json:
                      schema:      # Request body contents
                        type: object
                        properties:
                          id:
                            type: integer
                          name:
                            type: string
                        example:   # Sample object
                          id: 10
                          name: Jessica Smith
                responses:
                  '200':
                    description: OK

    Returns
    -------
    bool
        True if successful, False otherwise.

    .. _PEP 484:
        https://www.python.org/dev/peps/pep-0484/

    """
    pass

This docstring_handler would return

summary: Adds a new user
  requestBody:
    content:
      application/json:
        schema:      # Request body contents
          type: object
          properties:
            id:
              type: integer
            name:
              type: string
          example:   # Sample object
            id: 10
            name: Jessica Smith
  responses:
    '200':
      description: OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant