-
Notifications
You must be signed in to change notification settings - Fork 153
introduce swaggo and rename swagger to swaggerui #1444
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd9dc76
chore: rename swagger generator module
ReneWerner87 21ccf6b
fix: address swaggerdocgen review feedback
ReneWerner87 c121057
refactor: rename swaggerdocgen module to swaggo
ReneWerner87 0288372
Merge remote-tracking branch 'origin/main' into codex/2025-10-31-13-0…
ReneWerner87 8d4367c
Merge remote-tracking branch 'origin/main' into codex/2025-10-31-13-0…
ReneWerner87 6943d26
fix lint
ReneWerner87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: "Test swaggerdocgen" | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - main | ||
| paths: | ||
| - 'v3/swaggerdocgen/**/*.go' | ||
| - 'v3/swaggerdocgen/go.mod' | ||
| - 'v3/swaggerdocgen/go.sum' | ||
| pull_request: | ||
| paths: | ||
| - 'v3/swaggerdocgen/**/*.go' | ||
| - 'v3/swaggerdocgen/go.mod' | ||
| - 'v3/swaggerdocgen/go.sum' | ||
|
|
||
| jobs: | ||
| Tests: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| go-version: | ||
| - 1.25.x | ||
| steps: | ||
| - name: Fetch Repository | ||
| uses: actions/checkout@v5 | ||
| - name: Install Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '${{ matrix.go-version }}' | ||
| - name: Run Test | ||
| working-directory: ./v3/swaggerdocgen | ||
| run: go test -v -race ./... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| --- | ||
| id: swaggerdocgen | ||
| title: Swagger Doc Generator Middleware (formerly "swagger") | ||
| --- | ||
|
|
||
| # Swagger Doc Generator Middleware | ||
|
|
||
| > ⚠️ This module was renamed from `swagger` to `swaggerdocgen` to clearly distinguish it from the ported `swaggerui` middleware. Update your imports accordingly. | ||
|
|
||
|  | ||
| [](https://gofiber.io/discord) | ||
|  | ||
|
|
||
| Swagger documentation generator middleware for [Fiber](https://github.com/gofiber/fiber). It mounts the official Swagger UI that consumes the documentation generated by [swaggo/swag](https://github.com/swaggo/swag) and exposes helper utilities to serve the docs from a Fiber application. | ||
|
|
||
| **Compatible with Fiber v3.** | ||
|
|
||
| ## Go version support | ||
|
|
||
| We only support the latest two versions of Go. Visit [https://go.dev/doc/devel/release](https://go.dev/doc/devel/release) for more information. | ||
|
|
||
| ### Table of Contents | ||
| - [Signatures](#signatures) | ||
| - [Installation](#installation) | ||
| - [Usage](#usage) | ||
| - [Config](#config) | ||
| - [Default Config](#default-config) | ||
|
|
||
| ### Signatures | ||
| ```go | ||
| var HandlerDefault = New() | ||
| func New(config ...Config) fiber.Handler | ||
| ``` | ||
|
|
||
| ### Installation | ||
| Swagger Doc Generator is tested on the latest [Go versions](https://golang.org/dl/) with support for modules. Make sure to initialize one first if you have not done that yet: | ||
| ```bash | ||
| go mod init github.com/<user>/<repo> | ||
| ``` | ||
| Then install the middleware: | ||
| ```bash | ||
| go get github.com/gofiber/contrib/v3/swaggerdocgen | ||
| ``` | ||
|
|
||
| ### Usage | ||
| First, document your API using swaggo/swag comments and generate the documentation files (usually inside a `docs` package) by running `swag init`. | ||
|
|
||
| ```go | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/gofiber/fiber/v3" | ||
| swaggerdocgen "github.com/gofiber/contrib/v3/swaggerdocgen" | ||
|
|
||
| // docs are generated by Swag CLI, you have to import them. | ||
| // Replace with your own docs folder, usually "github.com/username/reponame/docs". | ||
| _ "github.com/username/reponame/docs" | ||
| ) | ||
|
|
||
| func main() { | ||
| app := fiber.New() | ||
|
|
||
| // Mount the UI with the default configuration under /swagger | ||
| app.Get("/swagger/*", swaggerdocgen.HandlerDefault) | ||
|
|
||
| // Customize the UI by passing a Config | ||
| app.Get("/docs/*", swaggerdocgen.New(swaggerdocgen.Config{ | ||
| URL: "http://example.com/doc.json", | ||
| DeepLinking: false, | ||
| DocExpansion: "none", | ||
| OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html", | ||
| })) | ||
|
|
||
| app.Listen(":8080") | ||
| } | ||
| ``` | ||
|
|
||
| ### Config | ||
| ```go | ||
| type Config struct { | ||
| InstanceName string | ||
| Title string | ||
| ConfigURL string | ||
| URL string | ||
| QueryConfigEnabled bool | ||
| Layout string | ||
| Plugins []template.JS | ||
| Presets []template.JS | ||
| DeepLinking bool | ||
| DisplayOperationId bool | ||
| DefaultModelsExpandDepth int | ||
| DefaultModelExpandDepth int | ||
| DefaultModelRendering string | ||
| DisplayRequestDuration bool | ||
| DocExpansion string | ||
| Filter FilterConfig | ||
| MaxDisplayedTags int | ||
| ShowExtensions bool | ||
| ShowCommonExtensions bool | ||
| TagsSorter template.JS | ||
| OnComplete template.JS | ||
| SyntaxHighlight *SyntaxHighlightConfig | ||
| TryItOutEnabled bool | ||
| RequestSnippetsEnabled bool | ||
| OAuth2RedirectUrl string | ||
| RequestInterceptor template.JS | ||
| RequestCurlOptions []string | ||
| ResponseInterceptor template.JS | ||
| ShowMutatedRequest bool | ||
| SupportedSubmitMethods []string | ||
| ValidatorUrl string | ||
| WithCredentials bool | ||
| ModelPropertyMacro template.JS | ||
| ParameterMacro template.JS | ||
| PersistAuthorization bool | ||
| OAuth *OAuthConfig | ||
| PreauthorizeBasic template.JS | ||
| PreauthorizeApiKey template.JS | ||
| CustomStyle template.CSS | ||
| CustomScript template.JS | ||
| } | ||
| ``` | ||
|
|
||
| ### Default Config | ||
| ```go | ||
| var ConfigDefault = Config{ | ||
| Title: "Swagger UI", | ||
| Layout: "StandaloneLayout", | ||
| URL: "doc.json", | ||
| DeepLinking: true, | ||
| ShowMutatedRequest: true, | ||
| Plugins: []template.JS{ | ||
| template.JS("SwaggerUIBundle.plugins.DownloadUrl"), | ||
| }, | ||
| Presets: []template.JS{ | ||
| template.JS("SwaggerUIBundle.presets.apis"), | ||
| template.JS("SwaggerUIStandalonePreset"), | ||
| }, | ||
| SyntaxHighlight: &SyntaxHighlightConfig{Activate: true, Theme: "agate"}, | ||
| } | ||
| ``` | ||
|
|
||
| > Refer to [`config.go`](./config.go) for a complete list of options and documentation strings. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.