Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.2.0
uses: golangci/golangci-lint-action@v6.5.0
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.63.4
version: v1.64.5

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
10 changes: 2 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ linters-settings:
threshold: 100
misspell:
locale: US
unused:
check-exported: false
unparam:
check-exported: true

Expand All @@ -27,9 +25,10 @@ linters:
- cyclop
- gocognit
- musttag
- intrange
- copyloopvar
- lll
- gochecknoglobals
- gomnd
- wrapcheck
- paralleltest
- forbidigo
Expand All @@ -44,7 +43,6 @@ linters:
- dupword
- depguard
- tagalign
- execinquery
- mnd
- testifylint
- recvcheck
Expand All @@ -57,17 +55,13 @@ issues:
text: "SA1019: strings.Title .+ deprecated"

- linters:
- gomnd
- mnd
- goconst
- err113
- noctx
- funlen
- dupl
- structcheck
- unused
- unparam
- nosnakecase
path: "_test.go"
- linters:
- errcheck # Error checking omitted for brevity.
Expand Down
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.63.4" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.64.5" # 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/swaggest/openapi-go
go 1.18

require (
github.com/bool64/dev v0.2.38
github.com/bool64/dev v0.2.39
github.com/stretchr/testify v1.8.2
github.com/swaggest/assertjson v1.9.0
github.com/swaggest/jsonschema-go v0.3.73
github.com/swaggest/refl v1.3.0
github.com/swaggest/refl v1.3.1
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bool64/dev v0.2.38 h1:C5H9wkx/BhTYRfV14X90iIQKpSuhzsG+OHQvWdQ5YQ4=
github.com/bool64/dev v0.2.38/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.39 h1:kP8DnMGlWXhGYJEZE/J0l/gVBdbuhoPGL+MJG4QbofE=
github.com/bool64/dev v0.2.39/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -35,8 +35,8 @@ github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
github.com/swaggest/jsonschema-go v0.3.73 h1:gU1pBzF3pkZ1GDD3dRMdQoCjrA0sldJ+QcM7aSSPgvc=
github.com/swaggest/jsonschema-go v0.3.73/go.mod h1:qp+Ym2DIXHlHzch3HKz50gPf2wJhKOrAB/VYqLS2oJU=
github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I=
github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg=
github.com/swaggest/refl v1.3.1 h1:XGplEkYftR7p9cz1lsiwXMM2yzmOymTE9vneVVpaOh4=
github.com/swaggest/refl v1.3.1/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA=
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
Expand Down
59 changes: 59 additions & 0 deletions openapi3/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,3 +1402,62 @@ func TestRawBody(t *testing.T) {
}
}`, r.SpecSchema())
}

func TestSelfReference(t *testing.T) {
reflector := openapi3.NewReflector()

type SubEntity struct {
Self *SubEntity `json:"self"`
}

type My struct {
Foo string `json:"foo"`
SubEntity *SubEntity `json:"subentity"`
}

putOp, err := reflector.NewOperationContext(http.MethodPut, "/things/")
require.NoError(t, err)

putOp.AddReqStructure(My{})
putOp.AddRespStructure(My{})

require.NoError(t, reflector.AddOperation(putOp))

assertjson.EqMarshal(t, `{
"openapi":"3.0.3","info":{"title":"","version":""},
"paths":{
"/things/":{
"put":{
"requestBody":{
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi3TestMy"}}
}
},
"responses":{
"200":{
"description":"OK",
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi3TestMy"}}
}
}
}
}
}
},
"components":{
"schemas":{
"Openapi3TestMy":{
"type":"object",
"properties":{
"foo":{"type":"string"},
"subentity":{"$ref":"#/components/schemas/Openapi3TestSubEntity"}
}
},
"Openapi3TestSubEntity":{
"type":"object",
"properties":{"self":{"$ref":"#/components/schemas/Openapi3TestSubEntity"}}
}
}
}
}`, reflector.SpecSchema())
}
59 changes: 59 additions & 0 deletions openapi31/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1530,3 +1530,62 @@ func TestRawBody(t *testing.T) {
}
}`, r.SpecSchema())
}

func TestSelfReference(t *testing.T) {
reflector := openapi31.NewReflector()

type SubEntity struct {
Self *SubEntity `json:"self"`
}

type My struct {
Foo string `json:"foo"`
SubEntity *SubEntity `json:"subentity"`
}

putOp, err := reflector.NewOperationContext(http.MethodPut, "/things/")
require.NoError(t, err)

putOp.AddReqStructure(My{})
putOp.AddRespStructure(My{})

require.NoError(t, reflector.AddOperation(putOp))

assertjson.EqMarshal(t, `{
"openapi":"3.1.0","info":{"title":"","version":""},
"paths":{
"/things/":{
"put":{
"requestBody":{
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi31TestMy"}}
}
},
"responses":{
"200":{
"description":"OK",
"content":{
"application/json":{"schema":{"$ref":"#/components/schemas/Openapi31TestMy"}}
}
}
}
}
}
},
"components":{
"schemas":{
"Openapi31TestMy":{
"properties":{
"foo":{"type":"string"},
"subentity":{"$ref":"#/components/schemas/Openapi31TestSubEntity"}
},
"type":"object"
},
"Openapi31TestSubEntity":{
"properties":{"self":{"$ref":"#/components/schemas/Openapi31TestSubEntity"}},
"type":"object"
}
}
}
}`, reflector.SpecSchema())
}
2 changes: 1 addition & 1 deletion operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
oc.SetIsProcessingResponse(isProcessingResponse)
oc.SetProcessingIn(in)

rc.Context = context.WithValue(rc.Context, ocCtxKey{}, oc) //nolint:fatcontext
rc.Context = context.WithValue(rc.Context, ocCtxKey{}, oc)

Check notice on line 166 in operation.go

View workflow job for this annotation

GitHub Actions / test (stable)

3 statement(s) on lines 162:167 are not covered by tests.
}
}

Expand Down
Loading