Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc page gets 404 when getting swagger-ui assets #81

Closed
paul-england opened this issue Sep 13, 2023 · 9 comments
Closed

Doc page gets 404 when getting swagger-ui assets #81

paul-england opened this issue Sep 13, 2023 · 9 comments

Comments

@paul-england
Copy link

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.

GET https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.19.1/swagger-ui.css net::ERR_ABORTED 404
docs:34     GET https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.19.1/swagger-ui-standalone-preset.js net::ERR_ABORTED 404
docs:33     GET https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.19.1/swagger-ui-bundle.js net::ERR_ABORTED 404
docs:63 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (docs:63:5)
@paul-england
Copy link
Author

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

@paul-england
Copy link
Author

Using v3cdn fixes this issue. Sorry to spam the board.

@vearutop
Copy link
Member

vearutop commented Sep 14, 2023

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.

@paul-england
Copy link
Author

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.

@vearutop
Copy link
Member

Could you share some details to reproduce the issue?

@paul-england
Copy link
Author

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
}

@vearutop
Copy link
Member

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.

@vearutop
Copy link
Member

@paul-england
Copy link
Author

Excellent! Thanks for the help. Great project, btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants