PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
67 stars 32 forks source link

Configuration options for custom CSS #44

Open usimd opened 1 month ago

usimd commented 1 month ago

In addition to the existing options to configure SwaggerUI itself via its parameters, it would be great to have the ability to add custom CSS as well (https://github.com/ostranme/swagger-ui-themes for instance seems fairly popular).

From my point of view it would be enough to provide an additional <link> tag with href being populated from a config parameter (if defined) after https://github.com/PWZER/swagger-ui-py/blob/21c62701c12d7a5b47f340c1631500cdaa5ef00f/swagger_ui/templates/doc.html#L8

The content served at the route could then easily be managed by the user, something like (pseudo)

api_doc(app, config_path='./config/test.yaml', url_prefix='/api/doc', custom_css='/static/custom.css')

@app.route('/static/custom.css')
def custom_css():
    css = 'h1 { color: blue; }'
    return Response(css, mimetype='text/css')

What do you think? Would be willing to contribute a PR for this.

PWZER commented 4 weeks ago

@usimd Yes, that's a good idea.