Skip to content

Commit 5f6a1f9

Browse files
committed
Merge branch 'main' into parameters-support
2 parents 9dfe7ff + 8d92190 commit 5f6a1f9

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

.golangci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ linters:
4747
- nakedret
4848
- nestif
4949
- prealloc
50-
- rowserrcheck
5150
- staticcheck
5251
- stylecheck
5352
- typecheck
@@ -64,7 +63,6 @@ linters:
6463
- gofumpt
6564
- goheader
6665
- noctx
67-
- sqlclosecheck
6866
- errorlint
6967
- paralleltest
7068
- tparallel
@@ -83,4 +81,9 @@ issues:
8381
- gochecknoglobals
8482
- path: _test\.go
8583
linters:
86-
- exhaustivestruct
84+
- exhaustivestruct
85+
- funlen
86+
- wrapcheck
87+
- path: server.go
88+
linters:
89+
- wrapcheck

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
lint:
2-
gofumpt -w -s ./..
2+
gofumpt -w ./..
33
golangci-lint run --fix
44

55
test:

examples/stream_output/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
apiSetExternalDocs(&apiDoc)
2525
apiSetComponents(&apiDoc)
2626

27-
apiDoc.AddRoute(docs.Path{
27+
apiDoc.AddRoute(&docs.Path{
2828
Route: "/users",
2929
HTTPMethod: "POST",
3030
OperationID: "createUser",
@@ -43,7 +43,7 @@ func main() {
4343
},
4444
})
4545

46-
apiDoc.AddRoute(docs.Path{
46+
apiDoc.AddRoute(&docs.Path{
4747
Route: "/users",
4848
HTTPMethod: "GET",
4949
OperationID: "getUser",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/go-oas/docs
22

3-
go 1.18
3+
go 1.19
44

55
require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
66

routing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ func (oas *OAS) GetPathByIndex(index int) *Path {
4040
}
4141

4242
// AddRoute is used for add API documentation routes.
43-
func (oas *OAS) AddRoute(path Path) {
44-
oas.Paths = append(oas.Paths, path)
43+
func (oas *OAS) AddRoute(path *Path) {
44+
oas.Paths = append(oas.Paths, *path)
4545
}

routing_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ func TestQuickUnitAttachRoutes(t *testing.T) {
270270
}
271271

272272
func TestOAS_AddRoute(t *testing.T) {
273+
t.Parallel()
274+
273275
var (
274276
respose200 = Response{Code: 200, Description: "Ok"}
275277
respose404 = Response{Code: 404, Description: "Not Found"}
@@ -305,27 +307,32 @@ func TestOAS_AddRoute(t *testing.T) {
305307
tests := []struct {
306308
name string
307309
oas *OAS
308-
path Path
310+
path *Path
309311
wantPaths Paths
310312
}{
311313
{
312314
name: "success-no-existing-paths",
313315
oas: &OAS{},
314-
path: pathGetUser,
316+
path: &pathGetUser,
315317
wantPaths: Paths{pathGetUser},
316318
},
317319
{
318320
name: "success-existing-paths",
319321
oas: &OAS{Paths: Paths{pathGetUser}},
320-
path: pathCreateUser,
322+
path: &pathCreateUser,
321323
wantPaths: Paths{pathGetUser, pathCreateUser},
322324
},
323325
}
326+
324327
for _, tt := range tests {
325-
t.Run(tt.name, func(t *testing.T) {
326-
tt.oas.AddRoute(tt.path)
327-
if !reflect.DeepEqual(tt.wantPaths, tt.oas.Paths) {
328-
t.Errorf("OAS.AddRoute() = [%v], want {%v}", tt.oas.Paths, tt.wantPaths)
328+
trn := tt
329+
330+
t.Run(trn.name, func(t *testing.T) {
331+
t.Parallel()
332+
333+
trn.oas.AddRoute(trn.path)
334+
if !reflect.DeepEqual(trn.wantPaths, trn.oas.Paths) {
335+
t.Errorf("OAS.AddRoute() = [%v], want {%v}", trn.oas.Paths, trn.wantPaths)
329336
}
330337
})
331338
}

server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
defaultIndexPath = "/index.html"
1919
fwSlashSuffix = "/"
2020
sigContSleeperMilliseconds = 20
21+
readHeaderTimeout = 60 * time.Second // same than nginx
2122
)
2223

2324
// ConfigSwaggerUI represents a structure which will be used to pass required configuration params to
@@ -156,8 +157,9 @@ func (c *ConfigSwaggerUI) initializeDefaultHTTPServer() {
156157
fileServer := http.FileServer(c.initFS)
157158

158159
c.httpServer = &http.Server{
159-
Addr: fmt.Sprintf(":%s", c.Port),
160-
Handler: http.StripPrefix(strings.TrimRight(c.Route, fwSlashSuffix), fileServer),
160+
Addr: fmt.Sprintf(":%s", c.Port),
161+
Handler: http.StripPrefix(strings.TrimRight(c.Route, fwSlashSuffix), fileServer),
162+
ReadHeaderTimeout: readHeaderTimeout,
161163
}
162164
}
163165

0 commit comments

Comments
 (0)