Added serving scalar documentation
This commit is contained in:
parent
e006d4539a
commit
cd8561c700
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module git.supernets.org/perp/gopay
|
|||||||
go 1.22.3
|
go 1.22.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/MarceloPetrucio/go-scalar-api-reference v0.0.0-20240521013641-ce5d2efe0e06
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2
|
github.com/pelletier/go-toml/v2 v2.2.2
|
||||||
github.com/rs/zerolog v1.33.0
|
github.com/rs/zerolog v1.33.0
|
||||||
|
2
go.sum
2
go.sum
@ -1,5 +1,7 @@
|
|||||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||||
|
github.com/MarceloPetrucio/go-scalar-api-reference v0.0.0-20240521013641-ce5d2efe0e06 h1:W4Yar1SUsPmmA51qoIRb174uDO/Xt3C48MB1YX9Y3vM=
|
||||||
|
github.com/MarceloPetrucio/go-scalar-api-reference v0.0.0-20240521013641-ce5d2efe0e06/go.mod h1:/wotfjM8I3m8NuIHPz3S8k+CCYH80EqDT8ZeNLqMQm0=
|
||||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||||
|
26
internal/router/api/v1/spec.go
Normal file
26
internal/router/api/v1/spec.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.supernets.org/perp/gopay/internal/context"
|
||||||
|
"github.com/MarceloPetrucio/go-scalar-api-reference"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Handle spec reference
|
||||||
|
func Spec(ctx *context.Context) {
|
||||||
|
// Parse documentation
|
||||||
|
content, err := scalar.ApiReferenceHTML(&scalar.Options{
|
||||||
|
SpecURL: "docs/v1_swagger.json",
|
||||||
|
CustomOptions: scalar.CustomOptions{
|
||||||
|
PageTitle: "GoPay API documentation",
|
||||||
|
},
|
||||||
|
HideDownloadButton: true,
|
||||||
|
DarkMode: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Msg("Could not parse swagger with scalar")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Data(200, "text/html; charset=utf-8", []byte(content))
|
||||||
|
}
|
@ -14,4 +14,7 @@ import "git.supernets.org/perp/gopay/internal/context"
|
|||||||
|
|
||||||
// Register v1 routes
|
// Register v1 routes
|
||||||
func Register(ctx *context.Context) {
|
func Register(ctx *context.Context) {
|
||||||
|
v1 := ctx.Group("v1")
|
||||||
|
v1.GET("scalar", ctx.API(Spec))
|
||||||
|
v1.GET("swagger", ctx.API(Spec))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user