Browse Source

Merge pull request #458 from BusterMachine7/master

array的格式
tags/v1.10.0^2
astaxie 2 years ago
parent
commit
76a4feb17e
No account linked to committer's email address
1 changed files with 31 additions and 6 deletions
  1. 31
    6
      generate/swaggergen/g_docs.go

+ 31
- 6
generate/swaggergen/g_docs.go View File

@@ -614,10 +614,25 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error {
614 614
 				pp := strings.Split(p[2], ".")
615 615
 				typ := pp[len(pp)-1]
616 616
 				if len(pp) >= 2 {
617
+					isArray := false
618
+					if p[1] == "body" && strings.HasPrefix(p[2], "[]") {
619
+						p[2] = p[2][2:]
620
+						isArray = true
621
+					}
617 622
 					m, mod, realTypes := getModel(p[2])
618
-					para.Schema = &swagger.Schema{
619
-						Ref: "#/definitions/" + m,
623
+					if isArray {
624
+						para.Schema = &swagger.Schema{
625
+							Type: "array",
626
+							Items: &swagger.Schema{
627
+								Ref: "#/definitions/" + m,
628
+							},
629
+						}
630
+					} else {
631
+						para.Schema = &swagger.Schema{
632
+							Ref: "#/definitions/" + m,
633
+						}
620 634
 					}
635
+
621 636
 					if _, ok := modelsList[pkgpath+controllerName]; !ok {
622 637
 						modelsList[pkgpath+controllerName] = make(map[string]swagger.Schema)
623 638
 					}
@@ -766,10 +781,20 @@ func setParamType(para *swagger.Parameter, typ string, pkgpath, controllerName s
766 781
 		appendModels(pkgpath, controllerName, realTypes)
767 782
 	}
768 783
 	if isArray {
769
-		para.Type = "array"
770
-		para.Items = &swagger.ParameterItems{
771
-			Type:   paraType,
772
-			Format: paraFormat,
784
+		if para.In == "body" {
785
+			para.Schema = &swagger.Schema{
786
+				Type: "array",
787
+				Items: &swagger.Schema{
788
+					Type:   paraType,
789
+					Format: paraFormat,
790
+				},
791
+			}
792
+		} else {
793
+			para.Type = "array"
794
+			para.Items = &swagger.ParameterItems{
795
+				Type:   paraType,
796
+				Format: paraFormat,
797
+			}
773 798
 		}
774 799
 	} else {
775 800
 		para.Type = paraType

Loading…
Cancel
Save