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

feat(swagger): bump fiber v3 & go v1.21+ #1137

Open
wants to merge 1 commit into
base: v3-beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 4 additions & 6 deletions .github/workflows/test-swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ on:
- master
- main
paths:
- 'swagger/**'
- "swagger/**"
pull_request:
paths:
- 'swagger/**'
- "swagger/**"

jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.18.x
- 1.19.x
- 1.20.x
- 1.21.x
- 1.22.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '${{ matrix.go-version }}'
go-version: "${{ matrix.go-version }}"
- name: Run Test
working-directory: ./swagger
run: go test -v -race ./...
101 changes: 58 additions & 43 deletions swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,67 @@ id: swagger
title: Swagger
---

# Swagger
# Swagger <!-- omit from toc -->

![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=swagger*)
[![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/workflows/Tests/badge.svg)
![Security](https://github.com/gofiber/contrib/workflows/Security/badge.svg)
![Linter](https://github.com/gofiber/contrib/workflows/Linter/badge.svg)

Swagger middleware for [Fiber](https://github.com/gofiber/fiber). The middleware handles Swagger UI.
Swagger middleware for [Fiber](https://github.com/gofiber/fiber). The middleware handles Swagger UI.

**Note: Requires Go 1.18 and above**
> **Note**
Requires Go 1.21 and above

### Table of Contents <!-- omit from toc -->

### Table of Contents
- [Signatures](#signatures)
- [Installation](#installation)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)

### Signatures

```go
func New(config ...swagger.Config) fiber.Handler
```

### Installation

Swagger is tested on the latests [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:

```bash
go mod init github.com/<user>/<repo>
```

And then install the swagger middleware:

```bash
go get github.com/gofiber/contrib/swagger
go get github.com/gofiber/fiber/v3
go get github.com/gofiber/contrib/swagger/v2
```

### Examples

Import the middleware package

```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/contrib/swagger"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/contrib/swagger/v2"
)
```

Using the default config:

```go
app.Use(swagger.New(cfg))
```

Using a custom config:

```go
cfg := swagger.Config{
BasePath: "/",
Expand All @@ -64,6 +76,7 @@ app.Use(swagger.New(cfg))
```

Using multiple instances of Swagger:

```go
// Create Swagger middleware for v1
//
Expand All @@ -85,48 +98,50 @@ app.Use(swagger.New(swagger.Config{
```

### Config

```go
type Config struct {
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(c *fiber.Ctx) bool

// BasePath for the UI path
//
// Optional. Default: /
BasePath string

// FilePath for the swagger.json or swagger.yaml file
//
// Optional. Default: ./swagger.json
FilePath string

// Path combines with BasePath for the full UI path
//
// Optional. Default: docs
Path string

// Title for the documentation site
//
// Optional. Default: Fiber API documentation
Title string

// CacheAge defines the max-age for the Cache-Control header in seconds.
//
// Optional. Default: 3600 (1 hour)
CacheAge int
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(c fiber.Ctx) bool

// BasePath for the UI path
//
// Optional. Default: /
BasePath string

// FilePath for the swagger.json or swagger.yaml file
//
// Optional. Default: ./swagger.json
FilePath string

// Path combines with BasePath for the full UI path
//
// Optional. Default: docs
Path string

// Title for the documentation site
//
// Optional. Default: Fiber API documentation
Title string

// CacheAge defines the max-age for the Cache-Control header in seconds.
//
// Optional. Default: 3600 (1 hour)
CacheAge int
}
```

### Default Config

```go
var ConfigDefault = Config{
Next: nil,
BasePath: "/",
FilePath: "./swagger.json",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 3600, // Default to 1 hour
Next: nil,
BasePath: "/",
FilePath: "./swagger.json",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 3600, // Default to 1 hour
}
```
```
44 changes: 22 additions & 22 deletions swagger/go.mod
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
module github.com/gofiber/contrib/swagger
module github.com/gofiber/contrib/swagger/v2

go 1.18
go 1.21

require (
github.com/go-openapi/runtime v0.26.2
github.com/gofiber/fiber/v2 v2.51.0
github.com/stretchr/testify v1.8.4
github.com/go-openapi/runtime v0.28.0
github.com/gofiber/fiber/v3 v3.0.0-beta.2
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.11 // indirect
github.com/go-openapi/strfmt v0.21.8 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.3 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.50.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.13.1 // indirect
golang.org/x/sys v0.14.0 // indirect
go.mongodb.org/mongo-driver v1.15.1 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading