swagger-ui-py icon indicating copy to clipboard operation
swagger-ui-py copied to clipboard

Configuration options for custom CSS

Open usimd opened this issue 1 year ago • 1 comments

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.

usimd avatar Jun 10 '24 19:06 usimd