flask-smorest icon indicating copy to clipboard operation
flask-smorest copied to clipboard

How to add Rapidoc logo?

Open outer-core opened this issue 3 years ago • 2 comments

Is there a way, via API_SPEC_OPTIONS, OPENAPI_RAPIDOC_CONFIG, or some other app config constant, to set the logo for use in rapidoc? Specifically I'm looking for something like the Change Logo example from https://rapidocweb.com/examples.html.

From what I understand, it doesn't seem like there is without a change to flask_smorest/spec/tempaltes/rapidoc.html to add the <img> tag section as shown in the above example.

outer-core avatar May 04 '22 21:05 outer-core

Yeah I'm afraid so.

I'm not sure where to stand, here. Having the API framework serve the doc with close to no effort is certainly practical. We always use it. But ultimately, the user is free to host the doc statically on another server. Some big stable APIs do that for deployment reasons.

I'm happy to allow the user to pass customization parameters through API options (what is currently possible) but I'd rather not engage into too much trouble for features that can't be easily tweaked, especially since the static doc hosting alternative above is viable.

I'm open to suggestion, though. In this specific case, we could add a dedicated app config variable and a conditional block in the template. I won't do it but I guess someone could contribute that. I'm just concerned it might open the door to all kinds of customization requests.

lafrech avatar May 13 '22 08:05 lafrech

But ultimately, the user is free to host the doc statically on another server.

That is what I'm doing, but my aim is to pull down a given rapidoc version and deploy that to my server. As that'll provide flexibility to try new features as needed. But flask-smorest doesn't make available this logo feature.

Speaking of, I also would like a similar ability in Swagger docs, but one thing at a time since I haven't explored that as far yet.

... we could add a dedicated app config variable and a conditional block in the template.

I was exploring the concept of a child dict within OPENAPI_RAPIDOC_CONFIG, (iirc) something like:

OPENAPI_RAPIDOC_CONFIG = {
    "img": {
        "slot": "nav-logo",
        "src": "/path/to/logo.png",
    },
}

with the conditional block in the html template. If desired, that could later be extended to better formalize child dicts, but for now I was just looking to hardcode the img key in the html template.

I won't do it but I guess someone could contribute that.

I can create the PR for that, but first wanted to better understand if that was an acceptable change, especially given your concerns of the slippery slope this could introduce. Though biased, I would argue this just allows for more complete use of the rapidoc spec.

outer-core avatar May 17 '22 15:05 outer-core