mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-18 20:23:02 -06:00
* Add Swagger spec test script * Fix Swagger spec errors not related to statuses with polls * Add API tests that post a status with a poll * Fix creating a status with a poll from form params * Fix Swagger spec errors related to statuses with polls (this is the last error) * Fix Swagger spec warnings not related to unused definitions * Suppress a duplicate list update params definition that was somehow causing wrong param names * Add Swagger test to CI - updates Drone config - vendorizes go-swagger - fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version * Put `Sample: ` on its own line everywhere * Remove unused id param from emojiCategoriesGet * Add 5 more pairs of profile fields to account update API Swagger * Remove Swagger prefix from dummy fields It makes the generated code look weird * Manually annotate params for statusCreate operation * Fix all remaining Swagger spec warnings - Change some models into operation parameters - Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields) * Documented that creating a status with scheduled_at isn't implemented yet * sign drone.yml * Fix filter API Swagger errors * fixup! Fix filter API Swagger errors --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
//go:build !go1.11
|
|
// +build !go1.11
|
|
|
|
package scan
|
|
|
|
import (
|
|
"go/ast"
|
|
"strconv"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
func upperSnakeCase(s string) string {
|
|
in := []rune(s)
|
|
isLower := func(idx int) bool {
|
|
return idx >= 0 && idx < len(in) && unicode.IsLower(in[idx])
|
|
}
|
|
|
|
out := make([]rune, 0, len(in)+len(in)/2)
|
|
|
|
for i, r := range in {
|
|
if unicode.IsUpper(r) {
|
|
r = unicode.ToLower(r)
|
|
if i > 0 && in[i-1] != '_' && (isLower(i-1) || isLower(i+1)) {
|
|
out = append(out, '_')
|
|
}
|
|
}
|
|
out = append(out, r)
|
|
}
|
|
|
|
return strings.ToUpper(string(out))
|
|
}
|
|
|
|
func getEnumBasicLitValue(basicLit *ast.BasicLit) interface{} {
|
|
switch basicLit.Kind.String() {
|
|
case "INT":
|
|
if result, err := strconv.ParseInt(basicLit.Value, 10, 64); err == nil {
|
|
return result
|
|
}
|
|
case "FLOAT":
|
|
if result, err := strconv.ParseFloat(basicLit.Value, 64); err == nil {
|
|
return result
|
|
}
|
|
default:
|
|
return strings.Trim(basicLit.Value, "\"")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func getEnumValues(file *ast.File, typeName string) (list []interface{}) {
|
|
for _, decl := range file.Decls {
|
|
genDecl, ok := decl.(*ast.GenDecl)
|
|
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
if genDecl.Tok.String() == "const" {
|
|
for _, spec := range genDecl.Specs {
|
|
if valueSpec, ok := spec.(*ast.ValueSpec); ok {
|
|
switch valueSpec.Type.(type) {
|
|
case *ast.Ident:
|
|
if valueSpec.Type.(*ast.Ident).Name == typeName {
|
|
if basicLit, ok := valueSpec.Values[0].(*ast.BasicLit); ok {
|
|
list = append(list, getEnumBasicLitValue(basicLit))
|
|
}
|
|
}
|
|
default:
|
|
var name = valueSpec.Names[0].Name
|
|
if strings.HasPrefix(name, upperSnakeCase(typeName)) {
|
|
var values = strings.SplitN(name, "__", 2)
|
|
if len(values) == 2 {
|
|
list = append(list, values[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|