Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Embedded plantuml diagrams in docstrings #65

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

tom-cook-pmev
Copy link

This PR adds an optional ability to embed plantuml diagrams in the description section of endpoint docstrings. Example:

@app.route('/foo')
def foo():
    """
    # Expected sequence
    @startuml
    client -> server: /foo
    server --> client: response {id}
    client -> server: /bar/{id}
    @enduml
    """
    return 'foobar'

This relies on having a PlantUML server available. By default, it uses the public server available at http://www.plantuml.com/plantuml/img/ but this can be configured by setting FLASK_SWAGGER_PLANTUML_SERVER in the flask app config.

The diagrams it generates go into a subdirectory of the app's static content directory. By default this subdirectory is called uml but it can be configured by setting FLASK_SWAGGER_PLANTUML_FOLDER in the flask app config.

The diagram content is replaced with a GFM image tag. If an error occurs while generating the image, the image content is replaced with an error message. If the plantuml package is not available, swagger generation proceeds as normal.

I've also added parameters to the swagger method for title, version and description. This is mostly so that the description content can be scanned for diagram content.

Currently uses some Python 3.6+ syntax. Let me know if this is an obstacle to merging & I can fix.

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

Successfully merging this pull request may close these issues.

1 participant