Skip to content

Commit fb0da34

Browse files
authored
Update deps to fix infinite recursion in cyclic references (#138)
1 parent 45ede01 commit fb0da34

File tree

8 files changed

+130
-18
lines changed

8 files changed

+130
-18
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
go-version: stable
2525
- uses: actions/checkout@v4
2626
- name: golangci-lint
27-
uses: golangci/golangci-lint-action@v6.2.0
27+
uses: golangci/golangci-lint-action@v6.5.0
2828
with:
2929
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
30-
version: v1.63.4
30+
version: v1.64.5
3131

3232
# Optional: working directory, useful for monorepos
3333
# working-directory: somedir

.golangci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ linters-settings:
1212
threshold: 100
1313
misspell:
1414
locale: US
15-
unused:
16-
check-exported: false
1715
unparam:
1816
check-exported: true
1917

@@ -27,9 +25,10 @@ linters:
2725
- cyclop
2826
- gocognit
2927
- musttag
28+
- intrange
29+
- copyloopvar
3030
- lll
3131
- gochecknoglobals
32-
- gomnd
3332
- wrapcheck
3433
- paralleltest
3534
- forbidigo
@@ -44,7 +43,6 @@ linters:
4443
- dupword
4544
- depguard
4645
- tagalign
47-
- execinquery
4846
- mnd
4947
- testifylint
5048
- recvcheck
@@ -57,17 +55,13 @@ issues:
5755
text: "SA1019: strings.Title .+ deprecated"
5856

5957
- linters:
60-
- gomnd
6158
- mnd
6259
- goconst
63-
- err113
6460
- noctx
6561
- funlen
6662
- dupl
67-
- structcheck
6863
- unused
6964
- unparam
70-
- nosnakecase
7165
path: "_test.go"
7266
- linters:
7367
- errcheck # Error checking omitted for brevity.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#GOLANGCI_LINT_VERSION := "v1.63.4" # Optional configuration to pinpoint golangci-lint version.
1+
#GOLANGCI_LINT_VERSION := "v1.64.5" # Optional configuration to pinpoint golangci-lint version.
22

33
# The head of Makefile determines location of dev-go to include standard targets.
44
GO ?= go

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module github.com/swaggest/openapi-go
33
go 1.18
44

55
require (
6-
github.com/bool64/dev v0.2.38
6+
github.com/bool64/dev v0.2.39
77
github.com/stretchr/testify v1.8.2
88
github.com/swaggest/assertjson v1.9.0
99
github.com/swaggest/jsonschema-go v0.3.73
10-
github.com/swaggest/refl v1.3.0
10+
github.com/swaggest/refl v1.3.1
1111
gopkg.in/yaml.v2 v2.4.0
1212
)
1313

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/bool64/dev v0.2.38 h1:C5H9wkx/BhTYRfV14X90iIQKpSuhzsG+OHQvWdQ5YQ4=
2-
github.com/bool64/dev v0.2.38/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
1+
github.com/bool64/dev v0.2.39 h1:kP8DnMGlWXhGYJEZE/J0l/gVBdbuhoPGL+MJG4QbofE=
2+
github.com/bool64/dev v0.2.39/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
33
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
44
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
55
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -35,8 +35,8 @@ github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7
3535
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
3636
github.com/swaggest/jsonschema-go v0.3.73 h1:gU1pBzF3pkZ1GDD3dRMdQoCjrA0sldJ+QcM7aSSPgvc=
3737
github.com/swaggest/jsonschema-go v0.3.73/go.mod h1:qp+Ym2DIXHlHzch3HKz50gPf2wJhKOrAB/VYqLS2oJU=
38-
github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I=
39-
github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg=
38+
github.com/swaggest/refl v1.3.1 h1:XGplEkYftR7p9cz1lsiwXMM2yzmOymTE9vneVVpaOh4=
39+
github.com/swaggest/refl v1.3.1/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA=
4040
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
4141
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
4242
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=

openapi3/reflect_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,3 +1402,62 @@ func TestRawBody(t *testing.T) {
14021402
}
14031403
}`, r.SpecSchema())
14041404
}
1405+
1406+
func TestSelfReference(t *testing.T) {
1407+
reflector := openapi3.NewReflector()
1408+
1409+
type SubEntity struct {
1410+
Self *SubEntity `json:"self"`
1411+
}
1412+
1413+
type My struct {
1414+
Foo string `json:"foo"`
1415+
SubEntity *SubEntity `json:"subentity"`
1416+
}
1417+
1418+
putOp, err := reflector.NewOperationContext(http.MethodPut, "/things/")
1419+
require.NoError(t, err)
1420+
1421+
putOp.AddReqStructure(My{})
1422+
putOp.AddRespStructure(My{})
1423+
1424+
require.NoError(t, reflector.AddOperation(putOp))
1425+
1426+
assertjson.EqMarshal(t, `{
1427+
"openapi":"3.0.3","info":{"title":"","version":""},
1428+
"paths":{
1429+
"/things/":{
1430+
"put":{
1431+
"requestBody":{
1432+
"content":{
1433+
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi3TestMy"}}
1434+
}
1435+
},
1436+
"responses":{
1437+
"200":{
1438+
"description":"OK",
1439+
"content":{
1440+
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi3TestMy"}}
1441+
}
1442+
}
1443+
}
1444+
}
1445+
}
1446+
},
1447+
"components":{
1448+
"schemas":{
1449+
"Openapi3TestMy":{
1450+
"type":"object",
1451+
"properties":{
1452+
"foo":{"type":"string"},
1453+
"subentity":{"$ref":"#/components/schemas/Openapi3TestSubEntity"}
1454+
}
1455+
},
1456+
"Openapi3TestSubEntity":{
1457+
"type":"object",
1458+
"properties":{"self":{"$ref":"#/components/schemas/Openapi3TestSubEntity"}}
1459+
}
1460+
}
1461+
}
1462+
}`, reflector.SpecSchema())
1463+
}

openapi31/reflect_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,3 +1530,62 @@ func TestRawBody(t *testing.T) {
15301530
}
15311531
}`, r.SpecSchema())
15321532
}
1533+
1534+
func TestSelfReference(t *testing.T) {
1535+
reflector := openapi31.NewReflector()
1536+
1537+
type SubEntity struct {
1538+
Self *SubEntity `json:"self"`
1539+
}
1540+
1541+
type My struct {
1542+
Foo string `json:"foo"`
1543+
SubEntity *SubEntity `json:"subentity"`
1544+
}
1545+
1546+
putOp, err := reflector.NewOperationContext(http.MethodPut, "/things/")
1547+
require.NoError(t, err)
1548+
1549+
putOp.AddReqStructure(My{})
1550+
putOp.AddRespStructure(My{})
1551+
1552+
require.NoError(t, reflector.AddOperation(putOp))
1553+
1554+
assertjson.EqMarshal(t, `{
1555+
"openapi":"3.1.0","info":{"title":"","version":""},
1556+
"paths":{
1557+
"/things/":{
1558+
"put":{
1559+
"requestBody":{
1560+
"content":{
1561+
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi31TestMy"}}
1562+
}
1563+
},
1564+
"responses":{
1565+
"200":{
1566+
"description":"OK",
1567+
"content":{
1568+
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi31TestMy"}}
1569+
}
1570+
}
1571+
}
1572+
}
1573+
}
1574+
},
1575+
"components":{
1576+
"schemas":{
1577+
"Openapi31TestMy":{
1578+
"properties":{
1579+
"foo":{"type":"string"},
1580+
"subentity":{"$ref":"#/components/schemas/Openapi31TestSubEntity"}
1581+
},
1582+
"type":"object"
1583+
},
1584+
"Openapi31TestSubEntity":{
1585+
"properties":{"self":{"$ref":"#/components/schemas/Openapi31TestSubEntity"}},
1586+
"type":"object"
1587+
}
1588+
}
1589+
}
1590+
}`, reflector.SpecSchema())
1591+
}

operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func WithOperationCtx(oc OperationContext, isProcessingResponse bool, in In) fun
163163
oc.SetIsProcessingResponse(isProcessingResponse)
164164
oc.SetProcessingIn(in)
165165

166-
rc.Context = context.WithValue(rc.Context, ocCtxKey{}, oc) //nolint:fatcontext
166+
rc.Context = context.WithValue(rc.Context, ocCtxKey{}, oc)
167167
}
168168
}
169169

0 commit comments

Comments
 (0)