From 5aee09738a13b3a7e225109e3bf0225151f1c5c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Feb 2026 01:43:58 +0000 Subject: [PATCH] Bump github.com/swaggest/jsonschema-go from 0.3.72 to 0.3.79 Bumps [github.com/swaggest/jsonschema-go](https://github.com/swaggest/jsonschema-go) from 0.3.72 to 0.3.79. - [Release notes](https://github.com/swaggest/jsonschema-go/releases) - [Commits](https://github.com/swaggest/jsonschema-go/compare/v0.3.72...v0.3.79) --- updated-dependencies: - dependency-name: github.com/swaggest/jsonschema-go dependency-version: 0.3.79 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 4 +- go.sum | 12 +- .../swaggest/jsonschema-go/.golangci.yml | 141 ++++++++++-------- .../swaggest/jsonschema-go/Makefile | 2 +- .../swaggest/jsonschema-go/README.md | 16 +- .../swaggest/jsonschema-go/context.go | 15 +- .../swaggest/jsonschema-go/entities.go | 15 +- .../swaggest/jsonschema-go/helper.go | 3 +- .../swaggest/jsonschema-go/reflect.go | 135 +++++++++++++---- vendor/github.com/swaggest/refl/.golangci.yml | 28 ++-- vendor/github.com/swaggest/refl/Makefile | 2 +- vendor/github.com/swaggest/refl/tag.go | 41 ++++- vendor/modules.txt | 4 +- 13 files changed, 287 insertions(+), 131 deletions(-) diff --git a/go.mod b/go.mod index 9fc6d0b69..ee9044981 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/smartystreets/assertions v1.13.1 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/jsonschema-go v0.3.79 github.com/swaggest/openapi-go v0.2.53 github.com/zitadel/oidc/v2 v2.12.0 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.49.0 @@ -98,7 +98,7 @@ require ( github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/swaggest/refl v1.3.0 // indirect + github.com/swaggest/refl v1.4.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect github.com/yuin/gopher-lua v1.1.1 // indirect diff --git a/go.sum b/go.sum index 65500831b..05acd93ac 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= -github.com/bool64/dev v0.2.35 h1:M17TLsO/pV2J7PYI/gpe3Ua26ETkzZGb+dC06eoMqlk= -github.com/bool64/dev v0.2.35/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bool64/dev v0.2.43 h1:yQ7qiZVef6WtCl2vDYU0Y+qSq+0aBrQzY8KXkklk9cQ= +github.com/bool64/dev v0.2.43/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/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -410,12 +410,12 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= 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/jsonschema-go v0.3.79 h1:0TOShCbAJ9Xjt1e2W83l+QtMQSG2pbun2EkiYTyafCs= +github.com/swaggest/jsonschema-go v0.3.79/go.mod h1:GqVmJ+XNLeUHhFIhHNKc+C68euxfrl3a3aoZH4vTRl0= 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/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I= -github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= +github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k= +github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= diff --git a/vendor/github.com/swaggest/jsonschema-go/.golangci.yml b/vendor/github.com/swaggest/jsonschema-go/.golangci.yml index 49a308d49..49fcf060b 100644 --- a/vendor/github.com/swaggest/jsonschema-go/.golangci.yml +++ b/vendor/github.com/swaggest/jsonschema-go/.golangci.yml @@ -1,77 +1,94 @@ -# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +# See https://golangci-lint.run/docs/linters/configuration/ +version: "2" run: tests: true - -linters-settings: - errcheck: - check-type-assertions: true - check-blank: true - gocyclo: - min-complexity: 45 - dupl: - threshold: 100 - misspell: - locale: US - unused: - check-exported: false - unparam: - check-exported: true - nestif: - min-complexity: 7 - linters: - enable-all: true + default: all disable: + - containedctx + - embeddedstructfieldcheck - err113 - maintidx - - musttag - - containedctx - funlen + - gocyclo - gocognit - cyclop - - lll - - gochecknoglobals - - gomnd - - wrapcheck - - paralleltest + - noinlineerr + - wsl_v5 + - funcorder + - copyloopvar + - depguard + - dupword + - errname + - exhaustruct - forbidigo - forcetypeassert - - varnamelen - - tagliatelle - - errname + - gochecknoglobals + - intrange - ireturn - - exhaustruct + - lll + - mnd - nonamedreturns - - testableexamples - - dupword - - depguard + - paralleltest + - recvcheck - tagalign - - execinquery - - mnd + - tagliatelle + - testableexamples - testifylint - -issues: - exclude: - - "strings.Title is deprecated" - - "strings.Title has been deprecated" - - "\"io/ioutil\" has been deprecated" - - "cyclomatic complexity \\d+ of func `\\(Schema\\).IsTrivial` is high" - exclude-use-default: false - exclude-rules: - - linters: - - gomnd - - mnd - - goconst - - noctx - - funlen - - dupl - - unused - - unparam - - nosnakecase - path: "_test.go" - - linters: - - errcheck # Error checking omitted for brevity. - - errchkjson - - gosec - path: "example_" - + - varnamelen + - wrapcheck + settings: + dupl: + threshold: 100 + errcheck: + check-type-assertions: true + check-blank: true + gocyclo: + min-complexity: 45 + misspell: + locale: US + unparam: + check-exported: true + nestif: + min-complexity: 7 + exclusions: + generated: lax + rules: + - linters: + - staticcheck + text: strings.Title has been deprecated + - linters: + - gosec + - dupl + - funlen + - goconst + - mnd + - noctx + - unparam + - unused + - errchkjson + - err113 + path: _test.go + - linters: + - errcheck + - gosec + path: example_ + - linters: + - revive + text: 'unused-parameter: parameter' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/vendor/github.com/swaggest/jsonschema-go/Makefile b/vendor/github.com/swaggest/jsonschema-go/Makefile index 48c9a2552..3d5e4e289 100644 --- a/vendor/github.com/swaggest/jsonschema-go/Makefile +++ b/vendor/github.com/swaggest/jsonschema-go/Makefile @@ -1,4 +1,4 @@ -#GOLANGCI_LINT_VERSION := "v1.59.1" # Optional configuration to pinpoint golangci-lint version. +#GOLANGCI_LINT_VERSION := "v2.5.0" # Optional configuration to pinpoint golangci-lint version. # The head of Makefile determines location of dev-go to include standard targets. GO ?= go diff --git a/vendor/github.com/swaggest/jsonschema-go/README.md b/vendor/github.com/swaggest/jsonschema-go/README.md index f57fb2537..3234ef942 100644 --- a/vendor/github.com/swaggest/jsonschema-go/README.md +++ b/vendor/github.com/swaggest/jsonschema-go/README.md @@ -90,6 +90,9 @@ These tags can be used: * [`example`](https://json-schema.org/draft/2020-12/json-schema-validation.html#name-examples), a scalar value that matches type of parent property, for an array it is applied to items * [`examples`](https://json-schema.org/draft/2020-12/json-schema-validation.html#name-examples), a JSON array value * [`const`](https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.1.3), can be scalar or JSON value +* [`deprecated`](https://json-schema.org/draft/2020-12/json-schema-validation#name-deprecated), boolean +* [`readOnly`](https://json-schema.org/draft/2020-12/json-schema-validation#name-deprecated), boolean +* [`writeOnly`](https://json-schema.org/draft/2020-12/json-schema-validation#name-deprecated), boolean * [`pattern`](https://json-schema.org/draft-04/json-schema-validation.html#rfc.section.5.2.3), string * [`format`](https://json-schema.org/draft-04/json-schema-validation.html#rfc.section.7), string * [`multipleOf`](https://json-schema.org/draft-04/json-schema-validation.html#rfc.section.5.1.1), float > 0 @@ -130,6 +133,17 @@ type MyObj struct { } ``` +Complex nested maps and slices/arrays can be configured with path-prefixed field tags. + +```go +type MyObj struct { + Ints []int `json:"ints" items.title:"My int"` + ExtraFloats [][]float64 `json:"extra_floats" items.items.title:"My float" items.items.enum:"1.23,4.56"` + MappedStrings map[int]string `json:"mapped_strings" additionalProperties.enum:"abc,def"` + VeryDeep map[int][]string `json:"very_deep" additionalProperties.items.enum:"abc,def"` +} +``` + ### Implementing interfaces on a type There are a few interfaces that can be implemented on a type to customize JSON Schema generation. @@ -274,4 +288,4 @@ s, err := r.Reflect(My{}, jsonschema.InterceptProp(func(params jsonschema.Interc return nil })) -``` \ No newline at end of file +``` diff --git a/vendor/github.com/swaggest/jsonschema-go/context.go b/vendor/github.com/swaggest/jsonschema-go/context.go index 24490d38a..d0d9fffef 100644 --- a/vendor/github.com/swaggest/jsonschema-go/context.go +++ b/vendor/github.com/swaggest/jsonschema-go/context.go @@ -316,11 +316,16 @@ type ReflectContext struct { // SkipUnsupportedProperties skips properties with unsupported types (func, chan, etc...) instead of failing. SkipUnsupportedProperties bool - Path []string - definitions map[refl.TypeString]*Schema // list of all definition objects - definitionRefs map[refl.TypeString]Ref - typeCycles map[refl.TypeString]*Schema - rootDefName string + // EnumNames allows custom schema property name for enum values, default 'x-enum-names'. + EnumNames string + + Path []string + definitions map[refl.TypeString]*Schema // list of all definition objects + definitionRefs map[refl.TypeString]Ref + typeCycles map[refl.TypeString]*Schema + rootDefName string + parentStructField *reflect.StructField + parentTagPrefix string } func (rc *ReflectContext) getDefinition(ref string) *Schema { diff --git a/vendor/github.com/swaggest/jsonschema-go/entities.go b/vendor/github.com/swaggest/jsonschema-go/entities.go index 480c41e63..bc53fc493 100644 --- a/vendor/github.com/swaggest/jsonschema-go/entities.go +++ b/vendor/github.com/swaggest/jsonschema-go/entities.go @@ -1,6 +1,5 @@ // Code generated by github.com/swaggest/json-cli v1.7.7, DO NOT EDIT. -// Package jsonschema contains JSON mapping structures. package jsonschema import ( @@ -23,6 +22,8 @@ type Schema struct { Description *string `json:"description,omitempty"` Default *interface{} `json:"default,omitempty"` ReadOnly *bool `json:"readOnly,omitempty"` + WriteOnly *bool `json:"writeOnly,omitempty"` + Deprecated *bool `json:"deprecated,omitempty"` Examples []interface{} `json:"examples,omitempty"` MultipleOf *float64 `json:"multipleOf,omitempty"` Maximum *float64 `json:"maximum,omitempty"` @@ -113,6 +114,18 @@ func (s *Schema) WithReadOnly(val bool) *Schema { return s } +// WithWriteOnly sets WriteOnly value. +func (s *Schema) WithWriteOnly(val bool) *Schema { + s.WriteOnly = &val + return s +} + +// WithDeprecated sets Deprecated value. +func (s *Schema) WithDeprecated(val bool) *Schema { + s.Deprecated = &val + return s +} + // WithExamples sets Examples value. func (s *Schema) WithExamples(val ...interface{}) *Schema { s.Examples = val diff --git a/vendor/github.com/swaggest/jsonschema-go/helper.go b/vendor/github.com/swaggest/jsonschema-go/helper.go index 44a62ef52..b84bdfdf5 100644 --- a/vendor/github.com/swaggest/jsonschema-go/helper.go +++ b/vendor/github.com/swaggest/jsonschema-go/helper.go @@ -7,7 +7,8 @@ import ( ) const ( - // XEnumNames is the name of JSON property to store names of enumerated values. + // XEnumNames is the default name of JSON property to store names of enumerated values. + // Use ReflectContext.EnumNames for a different value. XEnumNames = "x-enum-names" ) diff --git a/vendor/github.com/swaggest/jsonschema-go/reflect.go b/vendor/github.com/swaggest/jsonschema-go/reflect.go index 3280a9965..9860a3988 100644 --- a/vendor/github.com/swaggest/jsonschema-go/reflect.go +++ b/vendor/github.com/swaggest/jsonschema-go/reflect.go @@ -130,7 +130,7 @@ func checkSchemaSetup(params InterceptSchemaParams) (bool, error) { v := params.Value s := params.Schema - reflectEnum(s, "", v.Interface()) + reflectEnum(params.Context, s, "", "", v.Interface()) var e Exposer @@ -543,13 +543,10 @@ func (r *Reflector) reflect(i interface{}, rc *ReflectContext, keepType bool, pa return schema, nil } -func checkTextMarshaler(t reflect.Type, schema *Schema) bool { +func isTextMarshaler(t reflect.Type) bool { if (t.Implements(typeOfTextUnmarshaler) || reflect.PtrTo(t).Implements(typeOfTextUnmarshaler)) && (t.Implements(typeOfTextMarshaler) || reflect.PtrTo(t).Implements(typeOfTextMarshaler)) { if !t.Implements(typeOfJSONMarshaler) && !reflect.PtrTo(t).Implements(typeOfJSONMarshaler) { - schema.TypeEns().WithSimpleTypes(String) - schema.Type.SliceOfSimpleTypeValues = nil - return true } } @@ -557,6 +554,17 @@ func checkTextMarshaler(t reflect.Type, schema *Schema) bool { return false } +func checkTextMarshaler(t reflect.Type, schema *Schema) bool { + if isTextMarshaler(t) { + schema.TypeEns().WithSimpleTypes(String) + schema.Type.SliceOfSimpleTypeValues = nil + + return true + } + + return false +} + func safeInterface(v reflect.Value) interface{} { if !v.IsValid() { return nil @@ -867,11 +875,28 @@ func (r *Reflector) kindSwitch(t reflect.Type, v reflect.Value, schema *Schema, itemValue = v.Index(0).Interface() } + prevTagPrefix := rc.parentTagPrefix + defer func() { + rc.parentTagPrefix = prevTagPrefix + }() + + rc.parentTagPrefix += "items." + itemsSchema, err := r.reflect(itemValue, rc, false, schema) if err != nil { return err } + if rc.parentStructField != nil && itemsSchema.Ref == nil { + if err := refl.PopulateFieldsFromTags(&itemsSchema, rc.parentStructField.Tag, func(o *refl.FieldsFromTagsOptions) { + o.TagPrefix = rc.parentTagPrefix + }); err != nil { + return err + } + + reflectEnum(rc, &itemsSchema, rc.parentTagPrefix, rc.parentStructField.Tag, itemValue) + } + schema.AddType(Array) schema.WithItems(*(&Items{}).WithSchemaOrBool(itemsSchema.ToSchemaOrBool())) @@ -898,11 +923,28 @@ func (r *Reflector) kindSwitch(t reflect.Type, v reflect.Value, schema *Schema, } } + prevTagPrefix := rc.parentTagPrefix + defer func() { + rc.parentTagPrefix = prevTagPrefix + }() + + rc.parentTagPrefix += "additionalProperties." + additionalPropertiesSchema, err := r.reflect(itemValue, rc, false, schema) if err != nil { return err } + if rc.parentStructField != nil && additionalPropertiesSchema.Ref == nil { + if err := refl.PopulateFieldsFromTags(&additionalPropertiesSchema, rc.parentStructField.Tag, func(o *refl.FieldsFromTagsOptions) { + o.TagPrefix = rc.parentTagPrefix + }); err != nil { + return err + } + + reflectEnum(rc, &additionalPropertiesSchema, rc.parentTagPrefix, rc.parentStructField.Tag, itemValue) + } + schema.AddType(Object) schema.WithAdditionalProperties(additionalPropertiesSchema.ToSchemaOrBool()) @@ -1032,8 +1074,9 @@ func (r *Reflector) walkProperties(v reflect.Value, parent *Schema, rc *ReflectC } deepIndirect := refl.DeepIndirect(field.Type) + propName := strings.Split(tag, ",")[0] - if tag == "" && field.Anonymous && + if propName == "" && field.Anonymous && (field.Type.Kind() == reflect.Struct || deepIndirect.Kind() == reflect.Struct) { forceReference := (field.Type.Implements(typeOfEmbedReferencer) && field.Tag.Get("refer") == "") || field.Tag.Get("refer") == "true" @@ -1089,7 +1132,6 @@ func (r *Reflector) walkProperties(v reflect.Value, parent *Schema, rc *ReflectC continue } - propName := strings.Split(tag, ",")[0] omitEmpty := strings.Contains(tag, ",omitempty") required := false @@ -1134,6 +1176,9 @@ func (r *Reflector) walkProperties(v reflect.Value, parent *Schema, rc *ReflectC } } + f := field + rc.parentStructField = &f + propertySchema, err := r.reflect(fieldVal, rc, true, parent) if err != nil { if errors.Is(err, ErrSkipProperty) { @@ -1143,6 +1188,8 @@ func (r *Reflector) walkProperties(v reflect.Value, parent *Schema, rc *ReflectC return err } + rc.parentStructField = nil + checkNullability(&propertySchema, rc, ft, omitEmpty, nullable) if !rc.SkipNonConstraints { @@ -1161,20 +1208,15 @@ func (r *Reflector) walkProperties(v reflect.Value, parent *Schema, rc *ReflectC return err } - deprecated := false - if err := refl.ReadBoolTag(field.Tag, "deprecated", &deprecated); err != nil { - return err - } else if deprecated { - propertySchema.WithExtraPropertiesItem("deprecated", true) - } - if !rc.SkipNonConstraints { if err := reflectExamples(rc, &propertySchema, field); err != nil { return err } } - reflectEnum(&propertySchema, field.Tag, nil) + if propertySchema.Ref == nil { + reflectEnum(rc, &propertySchema, "", field.Tag, fieldVal) + } // Remove temporary kept type from referenced schema. if propertySchema.Ref != nil { @@ -1381,9 +1423,14 @@ func reflectExample(rc *ReflectContext, propertySchema *Schema, field reflect.St return nil } -func reflectEnum(schema *Schema, fieldTag reflect.StructTag, fieldVal interface{}) { +func reflectEnum(rc *ReflectContext, schema *Schema, tagPrefix string, fieldTag reflect.StructTag, fieldVal interface{}) { enum := enum{} - enum.loadFromField(fieldTag, fieldVal) + enum.loadFromField(tagPrefix, fieldTag, fieldVal) + + enumNames := XEnumNames + if rc.EnumNames != "" { + enumNames = rc.EnumNames + } if len(enum.items) > 0 { schema.Enum = enum.items @@ -1392,19 +1439,18 @@ func reflectEnum(schema *Schema, fieldTag reflect.StructTag, fieldVal interface{ schema.ExtraProperties = make(map[string]interface{}, 1) } - schema.ExtraProperties[XEnumNames] = enum.names + schema.ExtraProperties[enumNames] = enum.names } } } -// enum can be use for sending enum data that need validate. type enum struct { items []interface{} names []string } // loadFromField loads enum from field tag: json array or comma-separated string. -func (enum *enum) loadFromField(fieldTag reflect.StructTag, fieldVal interface{}) { +func (enum *enum) loadFromField(tagPrefix string, fieldTag reflect.StructTag, fieldVal interface{}) { fv := reflect.ValueOf(fieldVal) if e, isEnumer := safeInterface(fv).(NamedEnum); isEnumer { @@ -1419,21 +1465,58 @@ func (enum *enum) loadFromField(fieldTag reflect.StructTag, fieldVal interface{} enum.items = e.Enum() } - if enumTag := fieldTag.Get("enum"); enumTag != "" { + if enumTag := fieldTag.Get(tagPrefix + "enum"); enumTag != "" { var e []interface{} err := json.Unmarshal([]byte(enumTag), &e) if err != nil { - es := strings.Split(enumTag, ",") - e = make([]interface{}, len(es)) + e = enum.inferType(enumTag, fv) + } + + enum.items = e + } +} + +func (enum *enum) inferType(enumTag string, fv reflect.Value) []interface{} { + es := strings.Split(enumTag, ",") + e := make([]interface{}, 0, len(es)) - for i, s := range es { - e[i] = s + if isTextMarshaler(fv.Type()) { + for _, s := range es { + e = append(e, s) + } + + return e + } + + switch { + case strings.HasPrefix(fv.Kind().String(), "int"): + for _, s := range es { + if v, err := strconv.ParseInt(s, 10, 64); err == nil { + e = append(e, v) + } + } + case strings.HasPrefix(fv.Kind().String(), "uint"): + for _, s := range es { + if v, err := strconv.ParseUint(s, 10, 64); err == nil { + e = append(e, v) } } - enum.items = e + case strings.HasPrefix(fv.Kind().String(), "float"): + for _, s := range es { + if v, err := strconv.ParseFloat(s, 64); err == nil { + e = append(e, v) + } + } + + default: + for _, s := range es { + e = append(e, s) + } } + + return e } type ( diff --git a/vendor/github.com/swaggest/refl/.golangci.yml b/vendor/github.com/swaggest/refl/.golangci.yml index 6c808d928..558d110cd 100644 --- a/vendor/github.com/swaggest/refl/.golangci.yml +++ b/vendor/github.com/swaggest/refl/.golangci.yml @@ -12,63 +12,55 @@ linters-settings: threshold: 100 misspell: locale: US - unused: - check-exported: false unparam: check-exported: true cyclop: - max-complexity: 12 + max-complexity: 13 linters: enable-all: true disable: - musttag - exhaustive + - intrange + - copyloopvar - lll - - maligned - gochecknoglobals - - gomnd - wrapcheck - paralleltest - forbidigo - - exhaustivestruct - - interfacer # deprecated - forcetypeassert - - scopelint # deprecated - - ifshort # too many false positives - - golint # deprecated - varnamelen - tagliatelle - errname - ireturn - exhaustruct - nonamedreturns - - nosnakecase - - structcheck - - varcheck - - deadcode - testableexamples - dupword - depguard - tagalign + - mnd + - testifylint + - recvcheck issues: exclude-use-default: false exclude-rules: - linters: - - gomnd + - mnd - goconst - - goerr113 - noctx - funlen - dupl - - structcheck - unused - unparam - - nosnakecase path: "_test.go" - linters: - errcheck # Error checking omitted for brevity. - gosec path: "example_" + - linters: + - revive + text: "unused-parameter: parameter" diff --git a/vendor/github.com/swaggest/refl/Makefile b/vendor/github.com/swaggest/refl/Makefile index e8209933d..8b4c583b0 100644 --- a/vendor/github.com/swaggest/refl/Makefile +++ b/vendor/github.com/swaggest/refl/Makefile @@ -1,4 +1,4 @@ -#GOLANGCI_LINT_VERSION := "v1.54.1" # 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 diff --git a/vendor/github.com/swaggest/refl/tag.go b/vendor/github.com/swaggest/refl/tag.go index 6aea4168b..c9878508b 100644 --- a/vendor/github.com/swaggest/refl/tag.go +++ b/vendor/github.com/swaggest/refl/tag.go @@ -41,10 +41,10 @@ type WalkFieldFn func(v reflect.Value, sf reflect.StructField, path []reflect.St // WalkFieldsRecursively walks scalar and non-scalar fields of a struct recursively and calls user function on them. func WalkFieldsRecursively(v reflect.Value, f WalkFieldFn) { - walkFieldsRecursively(v, f, nil) + walkFieldsRecursively(v, f, nil, make(map[reflect.Type]struct{})) } -func walkFieldsRecursively(v reflect.Value, f WalkFieldFn, path []reflect.StructField) { +func walkFieldsRecursively(v reflect.Value, f WalkFieldFn, path []reflect.StructField, visited map[reflect.Type]struct{}) { if v.Kind() == 0 { return } @@ -69,9 +69,15 @@ func walkFieldsRecursively(v reflect.Value, f WalkFieldFn, path []reflect.Struct if v.IsValid() { fieldVal = v.Field(i) } else { + if _, ok := visited[field.Type]; ok { + continue + } + fieldVal = reflect.Zero(field.Type) } + visited[field.Type] = struct{}{} + if fieldVal.CanAddr() { fieldVal = fieldVal.Addr() } @@ -89,10 +95,14 @@ func walkFieldsRecursively(v reflect.Value, f WalkFieldFn, path []reflect.Struct pp += "." + p.Name } + for k := range visited { + println("visited:", k.String()) + } + panic("too deep recursion, possible cyclic reference: " + pp) } - walkFieldsRecursively(fieldVal, f, append(path, field)) + walkFieldsRecursively(fieldVal, f, append(path, field), visited) } } @@ -291,16 +301,37 @@ func JoinErrors(errs ...error) error { return nil } +// FieldsFromTagsOptions controls advanced behavior of PopulateFieldsFromTags. +type FieldsFromTagsOptions struct { + // TagPrefix adds a prefix to looked up tags, for example "items.". + TagPrefix string + + // FieldToTag defines how Go field name is mapped into a tag name. + // Default is lowercasing first char. + FieldToTag func(field string) string +} + // PopulateFieldsFromTags extracts values from field tag and puts them in according property of structPtr. -func PopulateFieldsFromTags(structPtr interface{}, fieldTag reflect.StructTag) error { +func PopulateFieldsFromTags(structPtr interface{}, fieldTag reflect.StructTag, options ...func(o *FieldsFromTagsOptions)) error { pv := reflect.ValueOf(structPtr).Elem() pt := pv.Type() var errs []error + opts := &FieldsFromTagsOptions{} + for _, option := range options { + option(opts) + } + + if opts.FieldToTag == nil { + opts.FieldToTag = func(field string) string { + return strings.ToLower(field[0:1]) + field[1:] + } + } + for i := 0; i < pv.NumField(); i++ { ptf := pt.Field(i) - tagName := strings.ToLower(ptf.Name[0:1]) + ptf.Name[1:] + tagName := opts.TagPrefix + opts.FieldToTag(ptf.Name) pvf := pv.Field(i).Addr().Interface() var err error diff --git a/vendor/modules.txt b/vendor/modules.txt index e06c6a74b..fc3c1c832 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -425,7 +425,7 @@ github.com/spf13/pflag ## explicit; go 1.17 github.com/stretchr/testify/assert github.com/stretchr/testify/require -# github.com/swaggest/jsonschema-go v0.3.72 +# github.com/swaggest/jsonschema-go v0.3.79 ## explicit; go 1.18 github.com/swaggest/jsonschema-go # github.com/swaggest/openapi-go v0.2.53 @@ -433,7 +433,7 @@ github.com/swaggest/jsonschema-go github.com/swaggest/openapi-go github.com/swaggest/openapi-go/internal github.com/swaggest/openapi-go/openapi3 -# github.com/swaggest/refl v1.3.0 +# github.com/swaggest/refl v1.4.0 ## explicit; go 1.17 github.com/swaggest/refl # github.com/twitchyliquid64/golang-asm v0.15.1