honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
470 stars 168 forks source link

[@hono/swagger-ui] Is it possible to ship swagger-ui-dist assets ? #448

Open TitoVince35 opened 7 months ago

TitoVince35 commented 7 months ago

Hello all! I am working in a very secure environment. I cannot afford to use links to internet resources, like swagger-ui assets. Is there any way I can bundle them with my server app and tell hono-swagger-ui to use this local assets ? Thank you.

yusukebe commented 7 months ago

Hi @TitoVince35

Thanks for the issue.

@sor4chi @naporin0624 Can you handle this issue?

sor4chi commented 7 months ago

Hi, @TitoVince35

It would certainly be possible to include that as a feature. I am just concerned about the dependency increasing it would create on the file system, bundlers, etc.

If you want to achieve that with the current hono-stack, how about just simply exporting the openapi json from @hono/zod-openapi and delivering the static assets after bundling using serveStatic?

naporin0624 commented 7 months ago

hii, @TitoVince35

If you are concerned about non origin requests in the environment where swagger-ui is run, why not fetch resources from unpkg in advance on the server and embed the results in script or style?

The swagger-ui has an option to get a specific swagger-ui-dist version, so you can fix the output js and css.

This is a technique like cloudflare font optimized.

<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" />
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" crossorigin></script>

We investigated to see if these were reading additional assets and found that they were not, so we can simply fetch and expand the text.

But doing this makes the html very huge ....