Closed paul-england closed 1 year ago
Worth noting, the above is for an in-progress project that has some features I'll obviously need to look at. Copy / pasting the example from README.md
, I get the following in the console, but the page renders, so obviously better.
DevTools failed to load source map: Could not load content for http://localhost:8011/docs/swagger-ui-bundle.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load source map: Could not load content for http://localhost:8011/docs/swagger-ui-standalone-preset.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load source map: Could not load content for http://localhost:8011/docs/swagger-ui.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
Using v3cdn
fixes this issue. Sorry to spam the board.
Missing source maps are expected, as they are optional for the web app to function and only needed to debug frontend code.
However, both cdn and non-cdn packages should render Swagger UI properly.
For the record, using v3cdn
or v5cdn
both render the page just fine. v4cdn
, for my project, does not. I'm fine w/ ticking up to v5
.
Could you share some details to reproduce the issue?
I'm using it w/ *chirouter.Wrapper. Find the code below. Simply swapping out the problematic v4cdn
seems to work. And again, the error is that the page renders white (with no real clues in the console).
func NewRouter(apiVersion string, jsonLog bool) *chirouter.Wrapper {
logger := httplog.NewLogger("ems", httplog.Options{
JSON: jsonLog,
Tags: map[string]string{
"apiVer": apiVersion,
},
})
apiSchema := &openapi.Collector{}
apiSchema.Reflector().SpecEns().Info.Title = "My Service"
apiSchema.Reflector().SpecEns().Info.WithDescription("My Description")
apiSchema.Reflector().SpecEns().Info.Version = apiVersion
validatorFactory := jsonschema.NewFactory(apiSchema, apiSchema)
decoderFactory := request.NewDecoderFactory()
decoderFactory.SetDecoderFunc(rest.ParamInPath, chirouter.PathToURLValues)
router := chirouter.NewWrapper(chi.NewRouter())
router.Use(
middleware.RealIP,
httplog.RequestLogger(logger),
nethttp.OpenAPIMiddleware(apiSchema),
request.DecoderMiddleware(decoderFactory),
request.ValidatorMiddleware(validatorFactory),
response.EncoderMiddleware,
gzip.Middleware,
)
router.Method(http.MethodGet, "/api/v1/docs/openapi", apiSchema)
router.Mount("/api/v1/docs", v4cdn.NewHandler(apiSchema.Reflector().Spec.Info.Title, "/api/v1/docs/openapi", "/api/v1/docs"))
return router
}
Oh, very interesting.
https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.19.1/swagger-ui-bundle.js is indeed 404, apparently it was removed from CDN for some reason. Thank you for the report, I'll downgrade v4cdn
to 4.18.3
that still exists.
Excellent! Thanks for the help. Great project, btw.
In the console of the docs page, it attempts to GET a few js/css files (from Cloudflare) and fails (404). The result is the page renders white. Is there a way to to use an alternative?
Here is the output from my console.