Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/test-swaggerdocgen.yml
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 ./...
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: "Test swagger"
name: "Test swaggerui"

on:
push:
branches:
- master
- main
paths:
- 'v3/swagger/**/*.go'
- 'v3/swagger/go.mod'
- 'v3/swaggerui/**/*.go'
- 'v3/swaggerui/go.mod'
- 'v3/swaggerui/go.sum'
pull_request:
paths:
- 'v3/swagger/**/*.go'
- 'v3/swagger/go.mod'
- 'v3/swaggerui/**/*.go'
- 'v3/swaggerui/go.mod'
- 'v3/swaggerui/go.sum'

jobs:
Tests:
Expand All @@ -28,5 +30,5 @@ jobs:
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
working-directory: ./v3/swagger
working-directory: ./v3/swaggerui
run: go test -v -race ./...
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Repository for third party middlewares and service implementations, with depende
* [otel (opentelemetry)](./v3/otel/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+otel%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-otel.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="otel workflow status" /> </a>
* [paseto](./v3/paseto/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+paseto%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-paseto.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="paseto workflow status" /> </a>
* [socket.io](./v3/socketio/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+socketio%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-socketio.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="socket.io workflow status" /> </a>
* [swagger](./v3/swagger/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swagger%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swagger.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swagger workflow status" /> </a>
* [swaggerdocgen](./v3/swaggerdocgen/README.md) _(formerly `swagger`)_ <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swaggerdocgen%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swaggerdocgen.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swaggerdocgen workflow status" /> </a>
* [swaggerui](./v3/swaggerui/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swaggerui%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swaggerui.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swaggerui workflow status" /> </a>
* [websocket](./v3/websocket/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+websocket%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-websocket.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="websocket workflow status" /> </a>

## 🥡 Service Implementations
Expand Down
3 changes: 2 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use (
./v3/paseto
./v3/sentry
./v3/socketio
./v3/swagger
./v3/swaggerdocgen
./v3/swaggerui
./v3/testcontainers
./v3/websocket
./v3/zap
Expand Down
3 changes: 2 additions & 1 deletion v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Repository for third party middlewares and service implementations, with depende
* [otel (opentelemetry)](./otel/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+otel%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-otel.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="otel workflow status" /> </a>
* [paseto](./paseto/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+paseto%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-paseto.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="paseto workflow status" /> </a>
* [socket.io](./socketio/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+socketio%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-socketio.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="socket.io workflow status" /> </a>
* [swagger](./swagger/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swagger%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swagger.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swagger workflow status" /> </a>
* [swaggerdocgen](./swaggerdocgen/README.md) _(formerly `swagger`)_ <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swaggerdocgen%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swaggerdocgen.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swaggerdocgen workflow status" /> </a>
* [swaggerui](./swaggerui/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+swaggerui%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-swaggerui.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="swaggerui workflow status" /> </a>
* [websocket](./websocket/README.md) <a href="https://github.com/gofiber/contrib/actions?query=workflow%3A%22Test+websocket%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/contrib/test-websocket.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="websocket workflow status" /> </a>

## 🥡 Service Implementations
Expand Down
144 changes: 144 additions & 0 deletions v3/swaggerdocgen/README.md
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.

![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=swaggerdocgen*)
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord)
![Test](https://github.com/gofiber/contrib/actions/workflows/test-swaggerdocgen.yml/badge.svg)

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.

Loading