From 095bdb27ff2724984e883857d3e70bac9a3250fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 02:01:27 +0000 Subject: [PATCH] Bump github.com/swaggest/openapi-go from 0.2.53 to 0.2.54 Bumps [github.com/swaggest/openapi-go](https://github.com/swaggest/openapi-go) from 0.2.53 to 0.2.54. - [Release notes](https://github.com/swaggest/openapi-go/releases) - [Commits](https://github.com/swaggest/openapi-go/compare/v0.2.53...v0.2.54) --- updated-dependencies: - dependency-name: github.com/swaggest/openapi-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +-- .../swaggest/openapi-go/openapi3/helper.go | 12 +++++++ .../swaggest/openapi-go/openapi3/reflect.go | 14 ++++++-- .../swaggest/openapi-go/operation.go | 32 ++++++++++++++++++- vendor/modules.txt | 2 +- 6 files changed, 59 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 4dc20f00d..d9719e07b 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,7 @@ require ( github.com/smartystreets/gunit v1.4.5 github.com/stretchr/testify v1.9.0 github.com/swaggest/jsonschema-go v0.3.72 - github.com/swaggest/openapi-go v0.2.53 + github.com/swaggest/openapi-go v0.2.54 github.com/zitadel/oidc/v2 v2.12.0 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.49.0 go.opentelemetry.io/contrib/propagators/jaeger v1.27.0 diff --git a/go.sum b/go.sum index 4d4f2ce63..f24ca0dfd 100644 --- a/go.sum +++ b/go.sum @@ -412,8 +412,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.72 h1:IHaGlR1bdBUBPfhe4tfacN2TGAPKENEGiNyNzvnVHv4= github.com/swaggest/jsonschema-go v0.3.72/go.mod h1:OrGyEoVqpfSFJ4Am4V/FQcQ3mlEC1vVeleA+5ggbVW4= -github.com/swaggest/openapi-go v0.2.53 h1:lWHKgC9IN48nBYxvuBrmAVJgki/1xsrGZWaWJnOLenE= -github.com/swaggest/openapi-go v0.2.53/go.mod h1:2Q7NpuG9NgpGeTaNOo852GSR6cCzSP4IznA9DNdUTQw= +github.com/swaggest/openapi-go v0.2.54 h1:WnFKIHAgR2RIOiYys3qvSuYmsFd2a17MIoC9Tcvog5c= +github.com/swaggest/openapi-go v0.2.54/go.mod h1:2Q7NpuG9NgpGeTaNOo852GSR6cCzSP4IznA9DNdUTQw= github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I= github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= diff --git a/vendor/github.com/swaggest/openapi-go/openapi3/helper.go b/vendor/github.com/swaggest/openapi-go/openapi3/helper.go index d4c4c49d9..b2152051b 100644 --- a/vendor/github.com/swaggest/openapi-go/openapi3/helper.go +++ b/vendor/github.com/swaggest/openapi-go/openapi3/helper.go @@ -210,3 +210,15 @@ func (s *Spec) SetHTTPBearerTokenSecurity(securityName string, format string, de }, ) } + +// SetReference sets a reference and discards existing content. +func (r *ResponseOrRef) SetReference(ref string) { + r.ResponseReferenceEns().Ref = ref + r.Response = nil +} + +// SetReference sets a reference and discards existing content. +func (r *RequestBodyOrRef) SetReference(ref string) { + r.RequestBodyReferenceEns().Ref = ref + r.RequestBody = nil +} diff --git a/vendor/github.com/swaggest/openapi-go/openapi3/reflect.go b/vendor/github.com/swaggest/openapi-go/openapi3/reflect.go index faf674277..c55c2687a 100644 --- a/vendor/github.com/swaggest/openapi-go/openapi3/reflect.go +++ b/vendor/github.com/swaggest/openapi-go/openapi3/reflect.go @@ -300,6 +300,10 @@ func (r *Reflector) setupRequest(o *Operation, oc openapi.OperationContext) erro if cu.Description != "" && o.RequestBody != nil && o.RequestBody.RequestBody != nil { o.RequestBody.RequestBody.WithDescription(cu.Description) } + + if cu.Customize != nil && o.RequestBody != nil { + cu.Customize(o.RequestBody) + } } return nil @@ -668,10 +672,16 @@ func (r *Reflector) setupResponse(o *Operation, oc openapi.OperationContext) err resp.Description = http.StatusText(cu.HTTPStatus) } + ror := ResponseOrRef{Response: resp} + + if cu.Customize != nil { + cu.Customize(&ror) + } + if cu.IsDefault { - o.Responses.Default = &ResponseOrRef{Response: resp} + o.Responses.Default = &ror } else { - o.Responses.WithMapOfResponseOrRefValuesItem(httpStatus, ResponseOrRef{Response: resp}) + o.Responses.WithMapOfResponseOrRefValuesItem(httpStatus, ror) } } diff --git a/vendor/github.com/swaggest/openapi-go/operation.go b/vendor/github.com/swaggest/openapi-go/operation.go index 057e9eff9..74b6d4c87 100644 --- a/vendor/github.com/swaggest/openapi-go/operation.go +++ b/vendor/github.com/swaggest/openapi-go/operation.go @@ -37,10 +37,40 @@ type ContentUnit struct { // IsDefault indicates default response. IsDefault bool - Description string + Description string + + // Customize allows fine control over prepared content entities. + // The cor value can be asserted to one of these types: + // *openapi3.RequestBodyOrRef + // *openapi3.ResponseOrRef + // *openapi31.RequestBodyOrReference + // *openapi31.ResponseOrReference + Customize func(cor ContentOrReference) + fieldMapping map[In]map[string]string } +// ContentOrReference defines content entity that can be a reference. +type ContentOrReference interface { + SetReference(ref string) +} + +// WithCustomize is a ContentUnit option. +func WithCustomize(customize func(cor ContentOrReference)) ContentOption { + return func(cu *ContentUnit) { + cu.Customize = customize + } +} + +// WithReference is a ContentUnit option. +func WithReference(ref string) ContentOption { + return func(cu *ContentUnit) { + cu.Customize = func(cor ContentOrReference) { + cor.SetReference(ref) + } + } +} + // ContentUnitPreparer defines self-contained ContentUnit. type ContentUnitPreparer interface { SetupContentUnit(cu *ContentUnit) diff --git a/vendor/modules.txt b/vendor/modules.txt index 6f6922efd..acfde3c2f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -428,7 +428,7 @@ github.com/stretchr/testify/require # github.com/swaggest/jsonschema-go v0.3.72 ## explicit; go 1.18 github.com/swaggest/jsonschema-go -# github.com/swaggest/openapi-go v0.2.53 +# github.com/swaggest/openapi-go v0.2.54 ## explicit; go 1.18 github.com/swaggest/openapi-go github.com/swaggest/openapi-go/internal