http-swagger icon indicating copy to clipboard operation
http-swagger copied to clipboard

Got error: Uncaught Invariant Violation: Minified React error #37, possible fix is provided.

Open yeehenchen opened this issue 3 years ago • 3 comments

Versions:

swaggo/swag v1.8.1 swaggo/http-swagger v1.2.7

Describe the bug:

Recently I am trying to initiate a project with swaggo then encountered this error Uncaught Invariant Violation: Minified React error #37

image

I couldn't provide complete steps to reproduce this error because it's a new project that generated from a template automatically. But the main steps are: First go get github.com/swaggo/swag, then swag init to generate /docs/swagger directory with docs.go, swagger.json and swagger.yaml files.

// routes.go setup
router.Mount("/docs/", httpSwagger.WrapHandler)

Then go to http://localhost:port/docs/index.html to see the blank page. So there's actually no too much customization.

Solution

After searching a bit I found a similar issue in swagger-ui: https://github.com/swagger-api/swagger-ui/issues/5608.

I've successfully fixed this error locally by changing the default dom_id here to #swagger-ui: https://github.com/swaggo/http-swagger/blob/285f7b0560cc9299b1baa3ccc04802821bac379a/swagger.go#L117 e.g.

func newConfig(configFns ...func(*Config)) *Config {
	config := Config{
		...
		DomID:                "#swagger-ui",
		...
	}

	...
}

Please let me know if any concerns, it will not block my progress since I'll switch to edit the swagger doc manually, so not urgent here. 😄

yeehenchen avatar May 03 '22 10:05 yeehenchen

I'm aware of this issue. Hopefully, I will be able to write a PR and push a release this week.

ubogdan avatar May 03 '22 10:05 ubogdan

@ubogdan Thanks for your quick response and your work!!

yeehenchen avatar May 03 '22 10:05 yeehenchen

fix added to v1.2.8 release

ubogdan avatar May 03 '22 10:05 ubogdan