mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-12 19:56:01 +00:00
[Vendor] update go-swagger v0.21.0 -> v0.25.0 (#12670)
* Update go-swagger * vendor
This commit is contained in:
53
vendor/github.com/go-swagger/go-swagger/codescan/schema.go
generated
vendored
53
vendor/github.com/go-swagger/go-swagger/codescan/schema.go
generated
vendored
@@ -65,11 +65,17 @@ func (st schemaTypable) AdditionalProperties() swaggerTypable {
|
||||
st.schema.Typed("object", "")
|
||||
return schemaTypable{st.schema.AdditionalProperties.Schema, st.level + 1}
|
||||
}
|
||||
|
||||
func (st schemaTypable) Level() int { return st.level }
|
||||
|
||||
func (st schemaTypable) AddExtension(key string, value interface{}) {
|
||||
addExtension(&st.schema.VendorExtensible, key, value)
|
||||
}
|
||||
|
||||
func (st schemaTypable) WithEnum(values ...interface{}) {
|
||||
st.schema.WithEnum(values...)
|
||||
}
|
||||
|
||||
type schemaValidations struct {
|
||||
current *spec.Schema
|
||||
}
|
||||
@@ -182,8 +188,8 @@ func (s *schemaBuilder) buildFromDecl(decl *entityDecl, schema *spec.Schema) err
|
||||
debugLog("map: %v -> [%v]%v", s.decl.Ident.Name, tpe.Key().String(), tpe.Elem().String())
|
||||
case *types.Named:
|
||||
o := tpe.Obj()
|
||||
debugLog("got the named type object: %s.%s | isAlias: %t | exported: %t", o.Pkg().Path(), o.Name(), o.IsAlias(), o.Exported())
|
||||
if o != nil {
|
||||
debugLog("got the named type object: %s.%s | isAlias: %t | exported: %t", o.Pkg().Path(), o.Name(), o.IsAlias(), o.Exported())
|
||||
if o.Pkg().Name() == "time" && o.Name() == "Time" {
|
||||
schema.Typed("string", "date-time")
|
||||
return nil
|
||||
@@ -263,6 +269,10 @@ func (s *schemaBuilder) buildFromType(tpe types.Type, tgt swaggerTypable) error
|
||||
tgt.Typed("string", "date-time")
|
||||
return nil
|
||||
}
|
||||
if pkg.PkgPath == "encoding/json" && tio.Name() == "RawMessage" {
|
||||
tgt.Typed("object", "")
|
||||
return nil
|
||||
}
|
||||
cmt, hasComments := s.ctx.FindComments(pkg, tio.Name())
|
||||
if !hasComments {
|
||||
cmt = new(ast.CommentGroup)
|
||||
@@ -298,7 +308,12 @@ func (s *schemaBuilder) buildFromType(tpe types.Type, tgt swaggerTypable) error
|
||||
}
|
||||
|
||||
if enumName, ok := enumName(cmt); ok {
|
||||
debugLog(enumName)
|
||||
enumValues, _ := s.ctx.FindEnumValues(pkg, enumName)
|
||||
if len(enumValues) > 0 {
|
||||
tgt.WithEnum(enumValues...)
|
||||
enumTypeName := reflect.TypeOf(enumValues[0]).String()
|
||||
_ = swaggerSchemaForType(enumTypeName, tgt)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -693,6 +708,11 @@ func (s *schemaBuilder) buildFromStruct(decl *entityDecl, st *types.Struct, sche
|
||||
break
|
||||
}
|
||||
|
||||
if afld == nil {
|
||||
debugLog("can't find source associated with %s", fld.String())
|
||||
continue
|
||||
}
|
||||
|
||||
// if the field is annotated with swagger:ignore, ignore it
|
||||
if ignored(afld.Doc) {
|
||||
continue
|
||||
@@ -973,6 +993,21 @@ func schemaVendorExtensibleSetter(meta *spec.Schema) func(json.RawMessage) error
|
||||
}
|
||||
}
|
||||
|
||||
type tagOptions []string
|
||||
|
||||
func (t tagOptions) Contain(option string) bool {
|
||||
for i := 1; i < len(t); i++ {
|
||||
if t[i] == option {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t tagOptions) Name() string {
|
||||
return t[0]
|
||||
}
|
||||
|
||||
func parseJSONTag(field *ast.Field) (name string, ignore bool, isString bool, err error) {
|
||||
if len(field.Names) > 0 {
|
||||
name = field.Names[0].Name
|
||||
@@ -988,19 +1023,21 @@ func parseJSONTag(field *ast.Field) (name string, ignore bool, isString bool, er
|
||||
|
||||
if strings.TrimSpace(tv) != "" {
|
||||
st := reflect.StructTag(tv)
|
||||
jsonParts := strings.Split(st.Get("json"), ",")
|
||||
jsonName := jsonParts[0]
|
||||
jsonParts := tagOptions(strings.Split(st.Get("json"), ","))
|
||||
|
||||
if len(jsonParts) > 1 && jsonParts[1] == "string" {
|
||||
if jsonParts.Contain("string") {
|
||||
// Need to check if the field type is a scalar. Otherwise, the
|
||||
// ",string" directive doesn't apply.
|
||||
isString = isFieldStringable(field.Type)
|
||||
}
|
||||
|
||||
if jsonName == "-" {
|
||||
switch jsonParts.Name() {
|
||||
case "-":
|
||||
return name, true, isString, nil
|
||||
} else if jsonName != "" {
|
||||
return jsonName, false, isString, nil
|
||||
case "":
|
||||
return name, false, isString, nil
|
||||
default:
|
||||
return jsonParts.Name(), false, isString, nil
|
||||
}
|
||||
}
|
||||
return name, false, false, nil
|
||||
|
Reference in New Issue
Block a user