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

Fix swagger css #306

Merged
merged 3 commits into from
Nov 28, 2023
Merged

Fix swagger css #306

merged 3 commits into from
Nov 28, 2023

Conversation

szczys
Copy link
Collaborator

@szczys szczys commented Nov 26, 2023

Swagger CSS has been broken, especially in dark mode. This PR fixes the style and closes #253

Before:

Screenshot 2023-11-25 at 22-52-24 Open API Docs Golioth

After:

Screenshot 2023-11-25 at 22-52-37 Open API Docs Golioth

Copy link

github-actions bot commented Nov 26, 2023

Visit the preview URL for this PR (updated for commit 747e611):

https://golioth-docs-dev--pr306-szczys-fix-swagger-c-ss7gk3o1.web.app

(expires Thu, 28 Dec 2023 17:13:05 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f53b02bdc98ce6f5593931ec4c339aa96bac84df

@szczys szczys force-pushed the szczys/fix-swagger-css branch 2 times, most recently from 98cc405 to 5b8971c Compare November 26, 2023 18:22
@szczys
Copy link
Collaborator Author

szczys commented Nov 26, 2023

I spent some time trying to use an existing swagger-ui dark mode library but the issue is that Docusaurus is handling the dark mode switch, not the browser. All of the swagger themes I found use prefers-color-scheme:

https://github.com/Amoenus/SwaggerDark/blob/2064ccd45b571865a64c731fa6bfddfbf2a01fe1/SwaggerDark.user.css#L13

Because of that, if your system/browser prefers dark, but the Docusaurus toggle is set to light, it breaks the light mode styling.

Fixing it the way I have done here is brittle--a game of whack-a-mole where anything not anticipated will be styled incorrectly. But it will be hard to solve this correctly unless proper support becomes available.

@szczys
Copy link
Collaborator Author

szczys commented Nov 26, 2023

I wonder if we could use this plugin to replace our openAPI section: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs

Demo: https://docusaurus-openapi.tryingpan.dev/petstore/get-pet-by-id

Update: this is promising but they have not yet merged support for Docusaurus v3 and changing to this will be non-trivial. I think we should merge the changes in this PR as a fix for current styling and consider this plugin in future improvements.

Comment on lines 99 to 101
html[data-theme="dark"] .loading-container .loading {
filter: invert(100%);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this one is not restricted to the .swagger-ui class -- is that intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I've added and tested that change as working.

Remove swagger-ui styling that placed white text on a light background in the
Authorize dialog

Signed-off-by: Mike Szczys <mike@golioth.io>
* Change order of css include so swagger styles can be overridden
* Add css file for fixing swagger-ui styles (especially in dark mode)

Signed-off-by: Mike Szczys <mike@golioth.io>
Change the codeblock background from the blue tint to use a grey from our new
branding colors.

Signed-off-by: Mike Szczys <mike@golioth.io>
@szczys szczys merged commit 789eca8 into develop Nov 28, 2023
2 checks passed
@szczys szczys deleted the szczys/fix-swagger-css branch November 28, 2023 19:15
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

Successfully merging this pull request may close these issues.

2 participants