swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.42k stars 8.93k forks source link

Add helper to render to static HTML #4232

Open aeneasr opened 6 years ago

aeneasr commented 6 years ago

I would like to render the swagger UI to static HTML for SEO reasons. With react, this is typically done using the ReactDOMServer and should (in theory) be not too hard to add.

Is this maybe implemented already?

shockey commented 6 years ago

Hi @arekkas!

Server-side rendering is out of Swagger-UI's scope. If you need it, the best approach would be to create a SSR-capable React application that consumes Swagger-UI.

aeneasr commented 6 years ago

That's what I thought as well, but I was unable to find a way to consume the swagger-ui react component itself. All I found was the option to instantiate the swagger-ui with some ID, which (presumably) mounts the swagger-ui internal react component there.

It would be really cool if you could point me to some resource that shows how I can consume the react component itself directly! Then I can easily implement SSR myself :)

aeneasr commented 6 years ago

I know you're ( @shockey ) probably incredibly busy and I appreciate the time taken for answering my initial question - I'd really like to get the SSR done and would be very happy to learn how to achieve that, based on my last question :)

shockey commented 6 years ago

Hey again @arekkas - I don't think that it's possible to graft Swagger-UI's component tree into your application's own at the moment, because we assume that we're managing our own:

https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/view/root-injects.js#L69

I'm marking this as an enhancement: I think we could rewire Swagger-UI to provide a "child mode" as opposed to vanilla mounting into a DOM node.

This may also be solved as part of a larger flavor of the project that better supports React users (see #3158, #3934, #3955).

aeneasr commented 6 years ago

Thank you for your reply! That's what I thought. It would be of course very nice to have support to call Swagger-UI directly and thus potentially enable SSR which could help with indexing (e.g. via search engines, SEO) and things like faster page loads.