Task Attachments (#104)
This commit is contained in:
32
vendor/github.com/swaggo/swag/property.go
generated
vendored
32
vendor/github.com/swaggo/swag/property.go
generated
vendored
@ -52,6 +52,11 @@ func parseFieldSelectorExpr(astTypeSelectorExpr *ast.SelectorExpr, parser *Parse
|
||||
|
||||
if pkgName, ok := astTypeSelectorExpr.X.(*ast.Ident); ok {
|
||||
if typeDefinitions, ok := parser.TypeDefinitions[pkgName.Name][astTypeSelectorExpr.Sel.Name]; ok {
|
||||
if expr, ok := typeDefinitions.Type.(*ast.SelectorExpr); ok {
|
||||
if primitiveType, err := convertFromSpecificToPrimitive(expr.Sel.Name); err == nil {
|
||||
return propertyNewFunc(primitiveType, "")
|
||||
}
|
||||
}
|
||||
parser.ParseDefinition(pkgName.Name, astTypeSelectorExpr.Sel.Name, typeDefinitions)
|
||||
return propertyNewFunc(astTypeSelectorExpr.Sel.Name, pkgName.Name)
|
||||
}
|
||||
@ -59,28 +64,26 @@ func parseFieldSelectorExpr(astTypeSelectorExpr *ast.SelectorExpr, parser *Parse
|
||||
return propertyName{SchemaType: actualPrimitiveType, ArrayType: actualPrimitiveType}
|
||||
}
|
||||
}
|
||||
|
||||
Printf("%s is not supported. but it will be set with string temporary. Please report any problems.\n", astTypeSelectorExpr.Sel.Name)
|
||||
return propertyName{SchemaType: "string", ArrayType: "string"}
|
||||
}
|
||||
|
||||
// getPropertyName returns the string value for the given field if it exists, otherwise it panics.
|
||||
// getPropertyName returns the string value for the given field if it exists
|
||||
// allowedValues: array, boolean, integer, null, number, object, string
|
||||
func getPropertyName(expr ast.Expr, parser *Parser) propertyName {
|
||||
func getPropertyName(expr ast.Expr, parser *Parser) (propertyName, error) {
|
||||
if astTypeSelectorExpr, ok := expr.(*ast.SelectorExpr); ok {
|
||||
return parseFieldSelectorExpr(astTypeSelectorExpr, parser, newProperty)
|
||||
return parseFieldSelectorExpr(astTypeSelectorExpr, parser, newProperty), nil
|
||||
}
|
||||
|
||||
// check if it is a custom type
|
||||
typeName := fmt.Sprintf("%v", expr)
|
||||
if actualPrimitiveType, isCustomType := parser.CustomPrimitiveTypes[typeName]; isCustomType {
|
||||
return propertyName{SchemaType: actualPrimitiveType, ArrayType: actualPrimitiveType}
|
||||
return propertyName{SchemaType: actualPrimitiveType, ArrayType: actualPrimitiveType}, nil
|
||||
}
|
||||
|
||||
if astTypeIdent, ok := expr.(*ast.Ident); ok {
|
||||
name := astTypeIdent.Name
|
||||
schemeType := TransToValidSchemeType(name)
|
||||
return propertyName{SchemaType: schemeType, ArrayType: schemeType}
|
||||
return propertyName{SchemaType: schemeType, ArrayType: schemeType}, nil
|
||||
}
|
||||
|
||||
if ptr, ok := expr.(*ast.StarExpr); ok {
|
||||
@ -88,23 +91,24 @@ func getPropertyName(expr ast.Expr, parser *Parser) propertyName {
|
||||
}
|
||||
|
||||
if astTypeArray, ok := expr.(*ast.ArrayType); ok { // if array
|
||||
return getArrayPropertyName(astTypeArray, parser)
|
||||
if _, ok := astTypeArray.Elt.(*ast.StructType); ok {
|
||||
return propertyName{SchemaType: "array", ArrayType: "object"}, nil
|
||||
}
|
||||
return getArrayPropertyName(astTypeArray, parser), nil
|
||||
}
|
||||
|
||||
if _, ok := expr.(*ast.MapType); ok { // if map
|
||||
//TODO: support map
|
||||
return propertyName{SchemaType: "object", ArrayType: "object"}
|
||||
return propertyName{SchemaType: "object", ArrayType: "object"}, nil
|
||||
}
|
||||
|
||||
if _, ok := expr.(*ast.StructType); ok { // if struct
|
||||
return propertyName{SchemaType: "object", ArrayType: "object"}
|
||||
return propertyName{SchemaType: "object", ArrayType: "object"}, nil
|
||||
}
|
||||
|
||||
if _, ok := expr.(*ast.InterfaceType); ok { // if interface{}
|
||||
return propertyName{SchemaType: "object", ArrayType: "object"}
|
||||
return propertyName{SchemaType: "object", ArrayType: "object"}, nil
|
||||
}
|
||||
|
||||
panic("not supported" + fmt.Sprint(expr))
|
||||
return propertyName{}, errors.New("not supported" + fmt.Sprint(expr))
|
||||
}
|
||||
|
||||
func getArrayPropertyName(astTypeArray *ast.ArrayType, parser *Parser) propertyName {
|
||||
|
Reference in New Issue
Block a user