Skip to content

chore: 为 Swagger UI 添加深色主题支持#995

Merged
joesdu merged 2 commits intomainfrom
dev
Oct 24, 2025
Merged

chore: 为 Swagger UI 添加深色主题支持#995
joesdu merged 2 commits intomainfrom
dev

Conversation

@joesdu
Copy link
Copy Markdown
Owner

@joesdu joesdu commented Oct 24, 2025

📝 描述 (Description)

为 Swagger UI 添加深色主题支持

🔗 相关问题 (Related Issues)

  • Closes #
  • Fixes #

🏷️ 变更类型 (Type of Change)

  • 🐛 错误修复 (Bug fix) (non-breaking change which fixes an issue)
  • ✨ 新功能 (New feature) (non-breaking change which adds functionality)
  • 💥 破坏性变更 (Breaking change) (fix or feature that would cause existing functionality to not work as expected)
  • 📚 文档更新 (Documentation update)
  • 🔧 重构 (Refactor) (no functional changes)
  • 🧪 测试 (Tests) (adding or updating tests)
  • 🛠️ 构建/CI 变更 (Build/CI changes)
  • 🎨 样式变更 (Style changes) (formatting, etc.)
  • 🚀 性能改进 (Performance improvements)
  • 🔒 安全改进 (Security improvements)

✅ 检查清单 (Checklist)

  • 我的代码遵循项目的编码标准 (My code follows the project's coding standards)
  • 我已经对自己的代码进行了自我审查 (I have performed a self-review of my own code)
  • 我已经在难以理解的区域注释了我的代码 (I have commented my code, particularly in hard-to-understand areas)
  • 我已经对文档进行了相应的更改 (I have made corresponding changes to the documentation)
  • 我的更改不会产生新的警告或错误 (My changes generate no new warnings or errors)
  • 我已经添加了证明我的修复有效或我的功能工作的测试 (I have added tests that prove my fix is effective or that my feature works)
  • 新增和现有的单元测试在本地通过我的更改 (New and existing unit tests pass locally with my changes)
  • 任何依赖变更都已合并并发布到下游模块 (Any dependent changes have been merged and published in downstream modules)

🧪 测试 (Testing)

  • 单元测试 (Unit tests)
  • 集成测试 (Integration tests)
  • 手动测试 (Manual testing)
  • 其他 (请指定) (Other (please specify)):

📸 截图 (如果适用) (Screenshots (if applicable))

🔍 附加说明 (Additional Notes)

- 在 SwaggerModule 中注入 /swagger-ui/custom.css 与 /swagger-ui/theme-toggle.js,启用深色模式样式与主题切换脚本
- 添加/更新 wwwroot/swagger-ui/custom.css(优化深色配色与只覆盖颜色的策略)
- 新增 theme-toggle.js 脚本以支持本地存储与系统主题检测的深/浅色切换
- 在应用初始化中启用静态文件中间件 (UseStaticFiles) 以对外提供上述静态资源
- 格式化 sample/WebApi.Test.Unit/Script.js(统一引号、缩进与样式)
Copilot AI review requested due to automatic review settings October 24, 2025 22:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds dark theme support to Swagger UI with a theme toggle button, allowing users to switch between light and dark modes. The implementation includes localStorage persistence and system preference detection.

Key changes:

  • Created a custom CSS file with comprehensive dark theme styling using GitHub Dark color scheme
  • Implemented a JavaScript theme toggle with localStorage persistence and system preference detection
  • Integrated the custom CSS and JavaScript into Swagger UI configuration

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sample/WebApi.Test.Unit/wwwroot/swagger-ui/theme-toggle.js New JavaScript file implementing theme toggle functionality with localStorage persistence and system preference detection
sample/WebApi.Test.Unit/wwwroot/swagger-ui/custom.css New CSS file defining dark theme styles for all Swagger UI components using CSS custom properties
sample/WebApi.Test.Unit/ServiceModules/SwaggerModule.cs Updated Swagger configuration to inject custom CSS and JavaScript files
sample/WebApi.Test.Unit/Script.js Code formatting changes (quotes, indentation) - no functional changes
sample/WebApi.Test.Unit/AppWebModule.cs Added static file middleware to serve wwwroot files

Comment thread sample/WebApi.Test.Unit/ServiceModules/SwaggerModule.cs
Comment thread sample/WebApi.Test.Unit/AppWebModule.cs
Comment thread sample/WebApi.Test.Unit/wwwroot/swagger-ui/theme-toggle.js
@joesdu joesdu merged commit 2018a6e into main Oct 24, 2025
7 checks passed
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