mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 16:37:04 +08:00
Update dependencies
This commit is contained in:
31
vendor/github.com/swaggo/echo-swagger/swagger.go
generated
vendored
31
vendor/github.com/swaggo/echo-swagger/swagger.go
generated
vendored
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/labstack/echo/v4"
|
||||
swaggerFiles "github.com/swaggo/files/v2"
|
||||
"github.com/swaggo/swag"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
// Config stores echoSwagger configuration variables.
|
||||
type Config struct {
|
||||
// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `mockedSwag.json`.
|
||||
URL string
|
||||
URLs []string
|
||||
DocExpansion string
|
||||
DomID string
|
||||
InstanceName string
|
||||
@@ -42,7 +43,7 @@ type OAuthConfig struct {
|
||||
// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
|
||||
func URL(url string) func(*Config) {
|
||||
return func(c *Config) {
|
||||
c.URL = url
|
||||
c.URLs = append(c.URLs, url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +98,7 @@ func OAuth(config *OAuthConfig) func(*Config) {
|
||||
|
||||
func newConfig(configFns ...func(*Config)) *Config {
|
||||
config := Config{
|
||||
URL: "doc.json",
|
||||
URLs: []string{"doc.json", "doc.yaml"},
|
||||
DocExpansion: "list",
|
||||
DomID: "swagger-ui",
|
||||
InstanceName: "swagger",
|
||||
@@ -146,6 +147,8 @@ func EchoWrapHandler(options ...func(*Config)) echo.HandlerFunc {
|
||||
c.Response().Header().Set("Content-Type", "application/javascript")
|
||||
case ".json":
|
||||
c.Response().Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
case ".yaml":
|
||||
c.Response().Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
case ".png":
|
||||
c.Response().Header().Set("Content-Type", "image/png")
|
||||
}
|
||||
@@ -170,7 +173,20 @@ func EchoWrapHandler(options ...func(*Config)) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
_, _ = c.Response().Writer.Write([]byte(doc))
|
||||
case "doc.yaml":
|
||||
jsonString, err := swag.ReadDoc(config.InstanceName)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
|
||||
return nil
|
||||
}
|
||||
doc, err := yaml.JSONToYAML([]byte(jsonString))
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
|
||||
return nil
|
||||
}
|
||||
_, _ = c.Response().Writer.Write(doc)
|
||||
default:
|
||||
c.Request().URL.Path = matches[2]
|
||||
http.FileServer(http.FS(swaggerFiles.FS)).ServeHTTP(c.Response(), c.Request())
|
||||
@@ -254,7 +270,14 @@ const indexTemplate = `<!-- HTML for static distribution bundle build -->
|
||||
window.onload = function() {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "{{.URL}}",
|
||||
urls: [
|
||||
{{range $index, $url := .URLs}}
|
||||
{
|
||||
name: "{{$url}}",
|
||||
url: "{{$url}}",
|
||||
},
|
||||
{{end}}
|
||||
],
|
||||
syntaxHighlight: {{.SyntaxHighlight}},
|
||||
deepLinking: {{.DeepLinking}},
|
||||
docExpansion: "{{.DocExpansion}}",
|
||||
|
16
vendor/github.com/swaggo/swag/README_pt.md
generated
vendored
16
vendor/github.com/swaggo/swag/README_pt.md
generated
vendored
@@ -95,7 +95,7 @@ OPÇÕES:
|
||||
--parseInternal Parse go ficheiros em pacotes internos, desactivados por padrão (padrão: falso)
|
||||
--generatedTime Gerar timestamp no topo dos docs.go, desactivado por padrão (padrão: falso)
|
||||
--parteDepth value Dependência profundidade parse (por padrão: 100)
|
||||
|
||||
--templateDelims value, --td value fornecem delimitadores personalizados para a geração de modelos Go. O formato é leftDelim,rightDelim. Por exemplo: "[[,]]"
|
||||
...
|
||||
|
||||
--help, -h mostrar ajuda (por padrão: falso)
|
||||
@@ -418,7 +418,7 @@ Quando uma pequena sequência na sua documentação é insuficiente, ou precisa
|
||||
| success | resposta de sucesso que separou por espaços. `return code or default`,`{param type}`,`data type`,`comment` |.
|
||||
| failure | Resposta de falha que separou por espaços. `return code or default`,`{param type}`,`data type`,`comment` |
|
||||
| response | Igual ao `sucesso` e `falha` |
|
||||
| header | Cabeçalho em resposta que separou por espaços. `código de retorno`,`{{tipo de parâmetro}`,`tipo de dados`,`comentário` |.
|
||||
| header | Cabeçalho em resposta que separou por espaços. `código de retorno`,`{tipo de parâmetro}`,`tipo de dados`,`comentário` |.
|
||||
| router | Definição do caminho que separou por espaços. caminho",`path`,`[httpMethod]` |[httpMethod]` |
|
||||
| x-name | A chave de extensão, deve ser iniciada por x- e tomar apenas o valor json. |
|
||||
| x-codeSample | Optional Markdown use. tomar `file` como parâmetro. Isto irá então procurar um ficheiro nomeado como o resumo na pasta dada. |
|
||||
@@ -905,6 +905,18 @@ Por defeito, o comando `swag` gera especificação Swagger em três tipos difere
|
||||
|
||||
Se desejar limitar um conjunto de tipos de ficheiros que devem ser gerados pode utilizar a bandeira `--outputTypes` (short `-ot`). O valor por defeito é `go,json,yaml` - tipos de saída separados por vírgula. Para limitar a saída apenas a ficheiros `go` e `yaml`, escrever-se-ia `go,yaml'. Com comando completo que seria `swag init --outputTypes go,yaml`.
|
||||
|
||||
### Alterar os delimitadores de acção padrão Go Template
|
||||
[#980](https://github.com/swaggo/swag/issues/980)
|
||||
[#1177](https://github.com/swaggo/swag/issues/1177)
|
||||
|
||||
Se as suas anotações ou campos estruturantes contêm "{{" or "}}", a geração de modelos irá muito provavelmente falhar, uma vez que estes são os delimitadores por defeito para [go templates](https://pkg.go.dev/text/template#Template.Delims).
|
||||
|
||||
Para que a geração funcione correctamente, pode alterar os delimitadores por defeito com `-td'. Por exemplo:
|
||||
``console
|
||||
swag init -g http/api.go -td "[[,]"
|
||||
```
|
||||
|
||||
O novo delimitador é um fio com o formato "`<left delimiter>`,`<right delimiter>`".
|
||||
|
||||
## Sobre o projecto
|
||||
Este projecto foi inspirado por [yvasiyarov/swagger](https://github.com/yvasiyarov/swagger) mas simplificámos a utilização e acrescentámos apoio a uma variedade de [frameworks web](#estruturas-web-suportadas). A fonte de imagem Gopher é [tenntenn/gopher-stickers](https://github.com/tenntenn/gopher-stickers). Tem licenças [creative commons licensing](http://creativecommons.org/licenses/by/3.0/deed.en).
|
||||
|
10
vendor/github.com/swaggo/swag/golist.go
generated
vendored
10
vendor/github.com/swaggo/swag/golist.go
generated
vendored
@@ -47,16 +47,20 @@ func listPackages(ctx context.Context, dir string, env []string, args ...string)
|
||||
return pkgs, nil
|
||||
}
|
||||
|
||||
func (parser *Parser) getAllGoFileInfoFromDepsByList(pkg *build.Package) error {
|
||||
func (parser *Parser) getAllGoFileInfoFromDepsByList(pkg *build.Package, parseFlag ParseFlag) error {
|
||||
ignoreInternal := pkg.Goroot && !parser.ParseInternal
|
||||
if ignoreInternal { // ignored internal
|
||||
return nil
|
||||
}
|
||||
|
||||
if parser.skipPackageByPrefix(pkg.ImportPath) {
|
||||
return nil // ignored by user-defined package path prefixes
|
||||
}
|
||||
|
||||
srcDir := pkg.Dir
|
||||
var err error
|
||||
for i := range pkg.GoFiles {
|
||||
err = parser.parseFile(pkg.ImportPath, filepath.Join(srcDir, pkg.GoFiles[i]), nil, ParseModels)
|
||||
err = parser.parseFile(pkg.ImportPath, filepath.Join(srcDir, pkg.GoFiles[i]), nil, parseFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -64,7 +68,7 @@ func (parser *Parser) getAllGoFileInfoFromDepsByList(pkg *build.Package) error {
|
||||
|
||||
// parse .go source files that import "C"
|
||||
for i := range pkg.CgoFiles {
|
||||
err = parser.parseFile(pkg.ImportPath, filepath.Join(srcDir, pkg.CgoFiles[i]), nil, ParseModels)
|
||||
err = parser.parseFile(pkg.ImportPath, filepath.Join(srcDir, pkg.CgoFiles[i]), nil, parseFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
21
vendor/github.com/swaggo/swag/operation.go
generated
vendored
21
vendor/github.com/swaggo/swag/operation.go
generated
vendored
@@ -381,7 +381,8 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
|
||||
return fmt.Errorf("%s is not supported paramType", paramType)
|
||||
}
|
||||
|
||||
err := operation.parseParamAttribute(commentLine, objectType, refType, ¶m)
|
||||
err := operation.parseParamAttribute(commentLine, objectType, refType, paramType, ¶m)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -436,7 +437,7 @@ var regexAttributes = map[string]*regexp.Regexp{
|
||||
schemaExampleTag: regexp.MustCompile(`(?i)\s+schemaExample\(.*\)`),
|
||||
}
|
||||
|
||||
func (operation *Operation) parseParamAttribute(comment, objectType, schemaType string, param *spec.Parameter) error {
|
||||
func (operation *Operation) parseParamAttribute(comment, objectType, schemaType, paramType string, param *spec.Parameter) error {
|
||||
schemaType = TransToValidSchemeType(schemaType)
|
||||
|
||||
for attrKey, re := range regexAttributes {
|
||||
@@ -447,7 +448,7 @@ func (operation *Operation) parseParamAttribute(comment, objectType, schemaType
|
||||
|
||||
switch attrKey {
|
||||
case enumsTag:
|
||||
err = setEnumParam(param, attr, objectType, schemaType)
|
||||
err = setEnumParam(param, attr, objectType, schemaType, paramType)
|
||||
case minimumTag, maximumTag:
|
||||
err = setNumberParam(param, attrKey, schemaType, attr, comment)
|
||||
case defaultTag:
|
||||
@@ -526,7 +527,7 @@ func setNumberParam(param *spec.Parameter, name, schemaType, attr, commentLine s
|
||||
}
|
||||
}
|
||||
|
||||
func setEnumParam(param *spec.Parameter, attr, objectType, schemaType string) error {
|
||||
func setEnumParam(param *spec.Parameter, attr, objectType, schemaType, paramType string) error {
|
||||
for _, e := range strings.Split(attr, ",") {
|
||||
e = strings.TrimSpace(e)
|
||||
|
||||
@@ -539,7 +540,12 @@ func setEnumParam(param *spec.Parameter, attr, objectType, schemaType string) er
|
||||
case ARRAY:
|
||||
param.Items.Enum = append(param.Items.Enum, value)
|
||||
default:
|
||||
param.Enum = append(param.Enum, value)
|
||||
switch paramType {
|
||||
case "body":
|
||||
param.Schema.Enum = append(param.Schema.Enum, value)
|
||||
default:
|
||||
param.Enum = append(param.Enum, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -715,6 +721,11 @@ func (operation *Operation) ParseRouterComment(commentLine string) error {
|
||||
|
||||
// ParseSecurityComment parses comment for given `security` comment string.
|
||||
func (operation *Operation) ParseSecurityComment(commentLine string) error {
|
||||
if len(commentLine) == 0 {
|
||||
operation.Security = []map[string][]string{}
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
securityMap = make(map[string][]string)
|
||||
securitySource = commentLine[strings.Index(commentLine, "@Security")+1:]
|
||||
|
33
vendor/github.com/swaggo/swag/package.go
generated
vendored
33
vendor/github.com/swaggo/swag/package.go
generated
vendored
@@ -5,6 +5,7 @@ import (
|
||||
"go/token"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PackageDefinitions files and definition in a package.
|
||||
@@ -94,22 +95,26 @@ func (pkg *PackageDefinitions) evaluateConstValue(file *ast.File, iota int, expr
|
||||
case *ast.BasicLit:
|
||||
switch valueExpr.Kind {
|
||||
case token.INT:
|
||||
// hexadecimal
|
||||
if len(valueExpr.Value) > 2 && valueExpr.Value[0] == '0' && valueExpr.Value[1] == 'x' {
|
||||
if x, err := strconv.ParseInt(valueExpr.Value[2:], 16, 64); err == nil {
|
||||
return int(x), nil
|
||||
} else if x, err := strconv.ParseUint(valueExpr.Value[2:], 16, 64); err == nil {
|
||||
return x, nil
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
// handle underscored number, such as 1_000_000
|
||||
if strings.ContainsRune(valueExpr.Value, '_') {
|
||||
valueExpr.Value = strings.Replace(valueExpr.Value, "_", "", -1)
|
||||
}
|
||||
|
||||
//octet
|
||||
if len(valueExpr.Value) > 1 && valueExpr.Value[0] == '0' {
|
||||
if x, err := strconv.ParseInt(valueExpr.Value[1:], 8, 64); err == nil {
|
||||
if len(valueExpr.Value) >= 2 && valueExpr.Value[0] == '0' {
|
||||
var start, base = 2, 8
|
||||
switch valueExpr.Value[1] {
|
||||
case 'x', 'X':
|
||||
//hex
|
||||
base = 16
|
||||
case 'b', 'B':
|
||||
//binary
|
||||
base = 2
|
||||
default:
|
||||
//octet
|
||||
start = 1
|
||||
}
|
||||
if x, err := strconv.ParseInt(valueExpr.Value[start:], base, 64); err == nil {
|
||||
return int(x), nil
|
||||
} else if x, err := strconv.ParseUint(valueExpr.Value[1:], 8, 64); err == nil {
|
||||
} else if x, err := strconv.ParseUint(valueExpr.Value[start:], base, 64); err == nil {
|
||||
return x, nil
|
||||
} else {
|
||||
panic(err)
|
||||
|
6
vendor/github.com/swaggo/swag/packages.go
generated
vendored
6
vendor/github.com/swaggo/swag/packages.go
generated
vendored
@@ -19,7 +19,7 @@ type PackagesDefinitions struct {
|
||||
files map[*ast.File]*AstFileInfo
|
||||
packages map[string]*PackageDefinitions
|
||||
uniqueDefinitions map[string]*TypeSpecDef
|
||||
parseDependency bool
|
||||
parseDependency ParseFlag
|
||||
debug Debugger
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ func (pkgDefs *PackagesDefinitions) EvaluateConstValueByName(file *ast.File, pkg
|
||||
}
|
||||
}
|
||||
}
|
||||
if pkgDefs.parseDependency {
|
||||
if pkgDefs.parseDependency > 0 {
|
||||
for _, pkgPath := range externalPkgPaths {
|
||||
if err := pkgDefs.loadExternalPackage(pkgPath); err == nil {
|
||||
if pkg, ok := pkgDefs.packages[pkgPath]; ok {
|
||||
@@ -513,7 +513,7 @@ func (pkgDefs *PackagesDefinitions) findTypeSpecFromPackagePaths(matchedPkgPaths
|
||||
}
|
||||
}
|
||||
|
||||
if pkgDefs.parseDependency {
|
||||
if pkgDefs.parseDependency > 0 {
|
||||
for _, pkgPath := range externalPkgPaths {
|
||||
if err := pkgDefs.loadExternalPackage(pkgPath); err == nil {
|
||||
typeDef = pkgDefs.findTypeSpec(pkgPath, name)
|
||||
|
161
vendor/github.com/swaggo/swag/parser.go
generated
vendored
161
vendor/github.com/swaggo/swag/parser.go
generated
vendored
@@ -74,10 +74,10 @@ type ParseFlag int
|
||||
const (
|
||||
// ParseNone parse nothing
|
||||
ParseNone ParseFlag = 0x00
|
||||
// ParseOperations parse operations
|
||||
ParseOperations = 0x01
|
||||
// ParseModels parse models
|
||||
ParseModels = 0x02
|
||||
ParseModels = 0x01
|
||||
// ParseOperations parse operations
|
||||
ParseOperations = 0x02
|
||||
// ParseAll parse operations and models
|
||||
ParseAll = ParseOperations | ParseModels
|
||||
)
|
||||
@@ -126,8 +126,8 @@ type Parser struct {
|
||||
// ParseVendor parse vendor folder
|
||||
ParseVendor bool
|
||||
|
||||
// ParseDependencies whether swag should be parse outside dependency folder
|
||||
ParseDependency bool
|
||||
// ParseDependencies whether swag should be parse outside dependency folder: 0 none, 1 models, 2 operations, 3 all
|
||||
ParseDependency ParseFlag
|
||||
|
||||
// ParseInternal whether swag should parse internal packages
|
||||
ParseInternal bool
|
||||
@@ -153,6 +153,10 @@ type Parser struct {
|
||||
// excludes excludes dirs and files in SearchDir
|
||||
excludes map[string]struct{}
|
||||
|
||||
// packagePrefix is a list of package path prefixes, packages that do not
|
||||
// match any one of them will be excluded when searching.
|
||||
packagePrefix []string
|
||||
|
||||
// tells parser to include only specific extension
|
||||
parseExtension string
|
||||
|
||||
@@ -237,11 +241,11 @@ func New(options ...func(*Parser)) *Parser {
|
||||
}
|
||||
|
||||
// SetParseDependency sets whether to parse the dependent packages.
|
||||
func SetParseDependency(parseDependency bool) func(*Parser) {
|
||||
func SetParseDependency(parseDependency int) func(*Parser) {
|
||||
return func(p *Parser) {
|
||||
p.ParseDependency = parseDependency
|
||||
p.ParseDependency = ParseFlag(parseDependency)
|
||||
if p.packages != nil {
|
||||
p.packages.parseDependency = parseDependency
|
||||
p.packages.parseDependency = p.ParseDependency
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,6 +277,20 @@ func SetExcludedDirsAndFiles(excludes string) func(*Parser) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetPackagePrefix sets a list of package path prefixes from a comma-separated
|
||||
// string, packages that do not match any one of them will be excluded when
|
||||
// searching.
|
||||
func SetPackagePrefix(packagePrefix string) func(*Parser) {
|
||||
return func(p *Parser) {
|
||||
for _, f := range strings.Split(packagePrefix, ",") {
|
||||
f = strings.TrimSpace(f)
|
||||
if f != "" {
|
||||
p.packagePrefix = append(p.packagePrefix, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetTags sets the tags to be included
|
||||
func SetTags(include string) func(*Parser) {
|
||||
return func(p *Parser) {
|
||||
@@ -343,6 +361,20 @@ func (parser *Parser) ParseAPI(searchDir string, mainAPIFile string, parseDepth
|
||||
return parser.ParseAPIMultiSearchDir([]string{searchDir}, mainAPIFile, parseDepth)
|
||||
}
|
||||
|
||||
// skipPackageByPrefix returns true the given pkgpath does not match
|
||||
// any user-defined package path prefixes.
|
||||
func (parser *Parser) skipPackageByPrefix(pkgpath string) bool {
|
||||
if len(parser.packagePrefix) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, prefix := range parser.packagePrefix {
|
||||
if strings.HasPrefix(pkgpath, prefix) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ParseAPIMultiSearchDir is like ParseAPI but for multiple search dirs.
|
||||
func (parser *Parser) ParseAPIMultiSearchDir(searchDirs []string, mainAPIFile string, parseDepth int) error {
|
||||
for _, searchDir := range searchDirs {
|
||||
@@ -365,7 +397,7 @@ func (parser *Parser) ParseAPIMultiSearchDir(searchDirs []string, mainAPIFile st
|
||||
}
|
||||
|
||||
// Use 'go list' command instead of depth.Resolve()
|
||||
if parser.ParseDependency {
|
||||
if parser.ParseDependency > 0 {
|
||||
if parser.parseGoList {
|
||||
pkgs, err := listPackages(context.Background(), filepath.Dir(absMainAPIFilePath), nil, "-deps")
|
||||
if err != nil {
|
||||
@@ -374,7 +406,7 @@ func (parser *Parser) ParseAPIMultiSearchDir(searchDirs []string, mainAPIFile st
|
||||
|
||||
length := len(pkgs)
|
||||
for i := 0; i < length; i++ {
|
||||
err := parser.getAllGoFileInfoFromDepsByList(pkgs[i])
|
||||
err := parser.getAllGoFileInfoFromDepsByList(pkgs[i], parser.ParseDependency)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -394,7 +426,7 @@ func (parser *Parser) ParseAPIMultiSearchDir(searchDirs []string, mainAPIFile st
|
||||
return fmt.Errorf("pkg %s cannot find all dependencies, %s", pkgName, err)
|
||||
}
|
||||
for i := 0; i < len(t.Root.Deps); i++ {
|
||||
err := parser.getAllGoFileInfoFromDeps(&t.Root.Deps[i])
|
||||
err := parser.getAllGoFileInfoFromDeps(&t.Root.Deps[i], parser.ParseDependency)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -569,6 +601,9 @@ func parseGeneralAPIInfo(parser *Parser, comments []string) error {
|
||||
|
||||
parser.swagger.SecurityDefinitions[value] = scheme
|
||||
|
||||
case securityAttr:
|
||||
parser.swagger.Security = append(parser.swagger.Security, parseSecurity(value))
|
||||
|
||||
case "@query.collection.format":
|
||||
parser.collectionFormatInQuery = TransToValidCollectionFormat(value)
|
||||
|
||||
@@ -768,6 +803,34 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur
|
||||
return scheme, nil
|
||||
}
|
||||
|
||||
func parseSecurity(commentLine string) map[string][]string {
|
||||
securityMap := make(map[string][]string)
|
||||
|
||||
for _, securityOption := range strings.Split(commentLine, "||") {
|
||||
securityOption = strings.TrimSpace(securityOption)
|
||||
|
||||
left, right := strings.Index(securityOption, "["), strings.Index(securityOption, "]")
|
||||
|
||||
if !(left == -1 && right == -1) {
|
||||
scopes := securityOption[left+1 : right]
|
||||
|
||||
var options []string
|
||||
|
||||
for _, scope := range strings.Split(scopes, ",") {
|
||||
options = append(options, strings.TrimSpace(scope))
|
||||
}
|
||||
|
||||
securityKey := securityOption[0:left]
|
||||
securityMap[securityKey] = append(securityMap[securityKey], options...)
|
||||
} else {
|
||||
securityKey := strings.TrimSpace(securityOption)
|
||||
securityMap[securityKey] = []string{}
|
||||
}
|
||||
}
|
||||
|
||||
return securityMap
|
||||
}
|
||||
|
||||
func initIfEmpty(license *spec.License) *spec.License {
|
||||
if license == nil {
|
||||
return new(spec.License)
|
||||
@@ -867,18 +930,29 @@ func getTagsFromComment(comment string) (tags []string) {
|
||||
}
|
||||
|
||||
func (parser *Parser) matchTags(comments []*ast.Comment) (match bool) {
|
||||
if len(parser.tags) != 0 {
|
||||
for _, comment := range comments {
|
||||
for _, tag := range getTagsFromComment(comment.Text) {
|
||||
if _, has := parser.tags["!"+tag]; has {
|
||||
return false
|
||||
}
|
||||
if _, has := parser.tags[tag]; has {
|
||||
match = true // keep iterating as it may contain a tag that is excluded
|
||||
}
|
||||
if len(parser.tags) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
match = false
|
||||
for _, comment := range comments {
|
||||
for _, tag := range getTagsFromComment(comment.Text) {
|
||||
if _, has := parser.tags["!"+tag]; has {
|
||||
return false
|
||||
}
|
||||
if _, has := parser.tags[tag]; has {
|
||||
match = true // keep iterating as it may contain a tag that is excluded
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
// If all tags are negation then we should return true
|
||||
for key := range parser.tags {
|
||||
if key[0] != '!' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -975,7 +1049,21 @@ func processRouterOperation(parser *Parser, operation *Operation) error {
|
||||
parser.debug.Printf("warning: %s\n", err)
|
||||
}
|
||||
|
||||
*op = &operation.Operation
|
||||
if len(operation.RouterProperties) > 1 {
|
||||
newOp := *operation
|
||||
var validParams []spec.Parameter
|
||||
for _, param := range newOp.Operation.OperationProps.Parameters {
|
||||
if param.In == "path" && !strings.Contains(routeProperties.Path, param.Name) {
|
||||
// This path param is not actually contained in the path, skip adding it to the final params
|
||||
continue
|
||||
}
|
||||
validParams = append(validParams, param)
|
||||
}
|
||||
newOp.Operation.OperationProps.Parameters = validParams
|
||||
*op = &newOp.Operation
|
||||
} else {
|
||||
*op = &operation.Operation
|
||||
}
|
||||
|
||||
parser.swagger.Paths.Paths[routeProperties.Path] = pathItem
|
||||
}
|
||||
@@ -1051,7 +1139,7 @@ func (parser *Parser) getTypeSchema(typeName string, file *ast.File, ref bool) (
|
||||
if err == ErrRecursiveParseStruct && ref {
|
||||
return parser.getRefTypeSchema(typeSpecDef, schema), nil
|
||||
}
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("%s: %w", typeName, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1285,7 +1373,7 @@ func (parser *Parser) parseStruct(file *ast.File, fields *ast.FieldList) (*spec.
|
||||
for _, field := range fields.List {
|
||||
fieldProps, requiredFromAnon, err := parser.parseStructField(file, field)
|
||||
if err != nil {
|
||||
if err == ErrFuncTypeField || err == ErrSkippedField {
|
||||
if errors.Is(err, ErrFuncTypeField) || errors.Is(err, ErrSkippedField) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1336,12 +1424,12 @@ func (parser *Parser) parseStructField(file *ast.File, field *ast.Field) (map[st
|
||||
if fieldName == "" {
|
||||
typeName, err := getFieldType(file, field.Type, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("%s: %w", fieldName, err)
|
||||
}
|
||||
|
||||
schema, err := parser.getTypeSchema(typeName, file, false)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("%s: %w", fieldName, err)
|
||||
}
|
||||
|
||||
if len(schema.Type) > 0 && schema.Type[0] == OBJECT {
|
||||
@@ -1363,7 +1451,7 @@ func (parser *Parser) parseStructField(file *ast.File, field *ast.Field) (map[st
|
||||
|
||||
schema, err := ps.CustomSchema()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("%s: %w", fieldName, err)
|
||||
}
|
||||
|
||||
if schema == nil {
|
||||
@@ -1377,20 +1465,20 @@ func (parser *Parser) parseStructField(file *ast.File, field *ast.Field) (map[st
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("%s: %w", fieldName, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = ps.ComplementSchema(schema)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("%s: %w", fieldName, err)
|
||||
}
|
||||
|
||||
var tagRequired []string
|
||||
|
||||
required, err := ps.IsRequired()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, fmt.Errorf("%s: %w", fieldName, err)
|
||||
}
|
||||
|
||||
if required {
|
||||
@@ -1567,6 +1655,9 @@ func defineTypeOfExample(schemaType, arrayType, exampleValue string) (interface{
|
||||
|
||||
// GetAllGoFileInfo gets all Go source files information for given searchDir.
|
||||
func (parser *Parser) getAllGoFileInfo(packageDir, searchDir string) error {
|
||||
if parser.skipPackageByPrefix(packageDir) {
|
||||
return nil // ignored by user-defined package path prefixes
|
||||
}
|
||||
return filepath.Walk(searchDir, func(path string, f os.FileInfo, _ error) error {
|
||||
err := parser.Skip(path, f)
|
||||
if err != nil {
|
||||
@@ -1586,12 +1677,16 @@ func (parser *Parser) getAllGoFileInfo(packageDir, searchDir string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (parser *Parser) getAllGoFileInfoFromDeps(pkg *depth.Pkg) error {
|
||||
func (parser *Parser) getAllGoFileInfoFromDeps(pkg *depth.Pkg, parseFlag ParseFlag) error {
|
||||
ignoreInternal := pkg.Internal && !parser.ParseInternal
|
||||
if ignoreInternal || !pkg.Resolved { // ignored internal and not resolved dependencies
|
||||
return nil
|
||||
}
|
||||
|
||||
if pkg.Raw != nil && parser.skipPackageByPrefix(pkg.Raw.ImportPath) {
|
||||
return nil // ignored by user-defined package path prefixes
|
||||
}
|
||||
|
||||
// Skip cgo
|
||||
if pkg.Raw == nil && pkg.Name == "C" {
|
||||
return nil
|
||||
@@ -1610,13 +1705,13 @@ func (parser *Parser) getAllGoFileInfoFromDeps(pkg *depth.Pkg) error {
|
||||
}
|
||||
|
||||
path := filepath.Join(srcDir, f.Name())
|
||||
if err := parser.parseFile(pkg.Name, path, nil, ParseModels); err != nil {
|
||||
if err := parser.parseFile(pkg.Name, path, nil, parseFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(pkg.Deps); i++ {
|
||||
if err := parser.getAllGoFileInfoFromDeps(&pkg.Deps[i]); err != nil {
|
||||
if err := parser.getAllGoFileInfoFromDeps(&pkg.Deps[i], parseFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
11
vendor/github.com/swaggo/swag/types.go
generated
vendored
11
vendor/github.com/swaggo/swag/types.go
generated
vendored
@@ -3,6 +3,7 @@ package swag
|
||||
import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
@@ -47,9 +48,15 @@ func (t *TypeSpecDef) TypeName() string {
|
||||
return t.TypeSpec.Name.Name[1:]
|
||||
} else if t.TypeSpec.Comment != nil {
|
||||
// get alias from comment '// @name '
|
||||
const regexCaseInsensitive = "(?i)"
|
||||
reTypeName, err := regexp.Compile(regexCaseInsensitive + `^@name\s+(\S+)`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, comment := range t.TypeSpec.Comment.List {
|
||||
texts := strings.Split(strings.TrimSpace(strings.TrimLeft(comment.Text, "/")), " ")
|
||||
if len(texts) > 1 && strings.ToLower(texts[0]) == "@name" {
|
||||
trimmedComment := strings.TrimSpace(strings.TrimLeft(comment.Text, "/"))
|
||||
texts := reTypeName.FindStringSubmatch(trimmedComment)
|
||||
if len(texts) > 1 {
|
||||
return texts[1]
|
||||
}
|
||||
}
|
||||
|
2
vendor/github.com/swaggo/swag/version.go
generated
vendored
2
vendor/github.com/swaggo/swag/version.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
package swag
|
||||
|
||||
// Version of swag.
|
||||
const Version = "v1.8.12"
|
||||
const Version = "v1.16.2"
|
||||
|
Reference in New Issue
Block a user