Skip to content

Commit

Permalink
Add configurable constructor, hide schemas, remove swgui-server, upda…
Browse files Browse the repository at this point in the history
…te CI (#30)
  • Loading branch information
vearutop authored Sep 12, 2022
1 parent 82dde0d commit 0f3b5cc
Show file tree
Hide file tree
Showing 23 changed files with 164 additions and 59 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ jobs:
- name: Count Lines Of Code
id: loc
run: |
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.3/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
sccdiff_hash=$(git hash-object ./sccdiff)
[ "$sccdiff_hash" == "ae8a07b687bd3dba60861584efe724351aa7ff63" ] || (echo "::error::unexpected hash for sccdiff, possible tampering: $sccdiff_hash" && exit 1)
OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.19.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.49.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.18.x
GO_VERSION: 1.19.x
jobs:
gorelease:
runs-on: ubuntu-latest
Expand All @@ -35,12 +35,12 @@ jobs:
with:
path: |
~/go/bin/gorelease
key: ${{ runner.os }}-gorelease
key: ${{ runner.os }}-gorelease-generic
- name: Gorelease
id: gorelease
run: |
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
OUTPUT=$(gorelease || exit 0)
OUTPUT=$(gorelease 2>&1 || exit 0)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "::set-output name=report::$OUTPUT"
Expand Down
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ linters:
- tagliatelle
- errname
- ireturn
- exhaustruct
- nonamedreturns
- nosnakecase
- structcheck
- varcheck
- deadcode

issues:
exclude-use-default: false
Expand All @@ -54,5 +60,12 @@ issues:
- noctx
- funlen
- dupl
- structcheck
- unused
- unparam
- nosnakecase
path: "_test.go"
- linters:
- errcheck # Error checking omitted for brevity.
path: "example_"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.45.2" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.49.0" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
//
// 1. Install tools:
//
// go get -u github.com/shurcooL/vfsgen
// go get -u github.com/shurcooL/vfsgen
//
// 2. Generate file:
//
// At root folder, run command:
// go generate
//
// go generate
package swgui
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/swaggest/swgui
go 1.17

require (
github.com/bool64/dev v0.2.10
github.com/bool64/dev v0.2.20
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/vearutop/statigz v1.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/andybalholm/brotli v1.0.3 h1:fpcw+r1N1h0Poc1F/pHbW40cUm/lMEQslZtCkBQ0UnM=
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bool64/dev v0.1.41/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/dev v0.2.10 h1:ypAGBazcwyIy2JvIJio8V3kdqO7AgIAYvcckW54qxr4=
github.com/bool64/dev v0.2.10/go.mod h1:/csLrm+4oDSsKJRIVS0mrywAonLnYKFG8RvGT7Jh9b8=
github.com/bool64/dev v0.2.20 h1:9eIRGdcg2kQW2NGza++QbOKidNNaK+KfWuUXcZFDejE=
github.com/bool64/dev v0.2.20/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
2 changes: 1 addition & 1 deletion internal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewHandlerWithConfig(config swgui.Config, assetsBase, faviconBase string, s
panic(err)
}

h.ConfigJson = template.JS(j) // nolint:gosec // Data is well formed.
h.ConfigJson = template.JS(j) //nolint:gosec // Data is well formed.

h.tpl, err = template.New("index").Parse(IndexTpl(assetsBase, faviconBase, config))
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions internal/index.tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

// IndexTpl creates page template.
// nolint:funlen // The template is long.
//
//nolint:funlen // The template is long.
func IndexTpl(assetsBase, faviconBase string, cfg swgui.Config) string {
settings := map[string]string{
"url": "url",
Expand All @@ -21,10 +22,11 @@ func IndexTpl(assetsBase, faviconBase string, cfg swgui.Config) string {
"plugins": `[
SwaggerUIBundle.plugins.DownloadUrl
]`,
"layout": `"StandaloneLayout"`,
"showExtensions": "true",
"showCommonExtensions": "true",
"validatorUrl": "null",
"layout": `"StandaloneLayout"`,
"showExtensions": "true",
"showCommonExtensions": "true",
"validatorUrl": "null",
"defaultModelsExpandDepth": "-1", // Hides schemas, override with value "1" in Config.SettingsUI to show schemas.
`onComplete`: `function() {
if (cfg.preAuthorizeApiKey) {
for (var name in cfg.preAuthorizeApiKey) {
Expand Down
34 changes: 0 additions & 34 deletions swgui-server/main.go

This file was deleted.

1 change: 1 addition & 0 deletions v3/gen/gen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main generates legacy assets.
package main

import (
Expand Down
19 changes: 19 additions & 0 deletions v3/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ func New(title, swaggerJSONPath string, basePath string) http.Handler {
return NewHandler(title, swaggerJSONPath, basePath)
}

// NewWithConfig creates configurable handler constructor.
func NewWithConfig(config swgui.Config) func(title, swaggerJSONPath string, basePath string) http.Handler {
return func(title, swaggerJSONPath string, basePath string) http.Handler {
if config.Title == "" {
config.Title = title
}

if config.SwaggerJSON == "" {
config.SwaggerJSON = swaggerJSONPath
}

if config.BasePath == "" {
config.BasePath = basePath
}

return NewHandlerWithConfig(config)
}
}

// NewHandler creates HTTP handler for Swagger UI.
func NewHandler(title, swaggerJSONPath string, basePath string) *Handler {
return NewHandlerWithConfig(swgui.Config{
Expand Down
8 changes: 5 additions & 3 deletions v3/static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions v3/static/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import (
)

// FS holds embedded assets.
//
//go:embed *.png *.gz
var FS embed.FS
19 changes: 19 additions & 0 deletions v3cdn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ import (
// Handler handle swagger UI request.
type Handler = internal.Handler

// NewWithConfig creates configurable handler constructor.
func NewWithConfig(config swgui.Config) func(title, swaggerJSONPath string, basePath string) http.Handler {
return func(title, swaggerJSONPath string, basePath string) http.Handler {
if config.Title == "" {
config.Title = title
}

if config.SwaggerJSON == "" {
config.SwaggerJSON = swaggerJSONPath
}

if config.BasePath == "" {
config.BasePath = basePath
}

return NewHandlerWithConfig(config)
}
}

// New creates HTTP handler for Swagger UI.
func New(title, swaggerJSONPath string, basePath string) http.Handler {
return NewHandler(title, swaggerJSONPath, basePath)
Expand Down
19 changes: 19 additions & 0 deletions v3emb/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ import (
// Handler handles swagger UI request.
type Handler = internal.Handler

// NewWithConfig creates configurable handler constructor.
func NewWithConfig(config swgui.Config) func(title, swaggerJSONPath string, basePath string) http.Handler {
return func(title, swaggerJSONPath string, basePath string) http.Handler {
if config.Title == "" {
config.Title = title
}

if config.SwaggerJSON == "" {
config.SwaggerJSON = swaggerJSONPath
}

if config.BasePath == "" {
config.BasePath = basePath
}

return NewHandlerWithConfig(config)
}
}

// New creates HTTP handler for Swagger UI.
func New(title, swaggerJSONPath string, basePath string) http.Handler {
return NewHandler(title, swaggerJSONPath, basePath)
Expand Down
1 change: 1 addition & 0 deletions v4/gen/gen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main generates legacy static assets.
package main

import (
Expand Down
19 changes: 19 additions & 0 deletions v4/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ import (
// Handler handles swagger UI request.
type Handler = internal.Handler

// NewWithConfig creates configurable handler constructor.
func NewWithConfig(config swgui.Config) func(title, swaggerJSONPath string, basePath string) http.Handler {
return func(title, swaggerJSONPath string, basePath string) http.Handler {
if config.Title == "" {
config.Title = title
}

if config.SwaggerJSON == "" {
config.SwaggerJSON = swaggerJSONPath
}

if config.BasePath == "" {
config.BasePath = basePath
}

return NewHandlerWithConfig(config)
}
}

// New creates HTTP handler for Swagger UI.
func New(title, swaggerJSONPath string, basePath string) http.Handler {
return NewHandler(title, swaggerJSONPath, basePath)
Expand Down
8 changes: 5 additions & 3 deletions v4/static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f3b5cc

Please sign in to comment.