middleware icon indicating copy to clipboard operation
middleware copied to clipboard

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

Open TitoVince35 opened this issue 1 year ago • 6 comments

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.

TitoVince35 avatar Apr 11 '24 13:04 TitoVince35

Hi @TitoVince35

Thanks for the issue.

@sor4chi @naporin0624 Can you handle this issue?

yusukebe avatar Apr 13 '24 08:04 yusukebe

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?

sor4chi avatar Apr 13 '24 08:04 sor4chi

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/[email protected]/swagger-ui.css" />
<script src="https://unpkg.com/[email protected]/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 ....

naporin0624 avatar Apr 13 '24 10:04 naporin0624

@sor4chi how does one export the openapi json as a static file? Can you provide a snippet?

platform-kit avatar Dec 08 '24 03:12 platform-kit

Hi, @platform-kit It’s simply setting up a Hono server with OpenAPI, making requests to the endpoint where OpenAPI is served, and saving the results as JSON. https://github.com/sor4chi/hono-openapi-export-sample

sor4chi avatar Dec 08 '24 12:12 sor4chi