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

Dark Mode Support? #300

Open
adiatma85 opened this issue Apr 26, 2024 · 2 comments
Open

Dark Mode Support? #300

adiatma85 opened this issue Apr 26, 2024 · 2 comments

Comments

@adiatma85
Copy link

Reference --> https://github.com/Amoenus/SwaggerDark/

My idea is we adding new configuration field something to be something like this:

type Config struct {
	// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
	URL                      string
	DocExpansion             string
	InstanceName             string
	Title                    string
	DefaultModelsExpandDepth int
	DeepLinking              bool
	PersistAuthorization     bool
	Oauth2DefaultClientID    string
	IsDarkMode               bool
}

Then we can tweak the logic for css file creation to be something like this:

css := &textTemplate.Template{}
	if config.IsDarkMode {
		css, _ = textTemplate.New("swagger_index.css").Parse(swaggerDarkStyleTpl)
	} else {
		css, _ = textTemplate.New("swagger_index.css").Parse(swaggerStyleTpl)
	}

Add new function for modify the Dark Mode:

// Dark Mode for the Swagger
// Defaults to false
func SetDarkMode(isDarkMode bool) func(*Config) {
	return func(c *Config) {
		c.IsDarkMode = isDarkMode
	}
}

Finally, we can call it like this:

func main() {
	r := gin.New()

	r.GET("/v2/testapi/get-string-by-int/:some_id", api.GetStringByInt)
	r.GET("/v2/testapi/get-struct-array-by-string/:some_id", api.GetStructArrayByString)

	url := ginSwagger.URL("http://petstore.swagger.io:8080/swagger/doc.json") // The url pointing to API definition
	isDarkMode := ginSwagger.SetDarkMode(true)
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url, isDarkMode))

	r.Run()
}

Wdyt?

@adiatma85
Copy link
Author

I am already trying this on forked repo, here is the result:
image

@rookie-luochao
Copy link

Maybe you can try my new openapi-ui tool --> https://github.com/openapi-ui/go-openapi-ui

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