Repository: swaggo/swag
Pull request #1927 (2024-11-21 09:26:21)

Fix format by goimports
**Describe the PR**
This PR formats the command outputs using goimports.

goimports is a popular tool among Go users for formatting code. The code generated by swag can sometimes conflict with the formatting expected by goimports. This PR addresses that problem by ensuring the swag-generated code is formatted using goimports.

Fix https://github.com/swaggo/swag/issues/1929



Patch:
diff --git a/formatter.go b/formatter.go
index 511e3a8..1074a3b 100644
--- a/formatter.go
+++ b/formatter.go
@@ -12,6 +12,8 @@ import (
 	"sort"
 	"strings"
 	"text/tabwriter"
+
+	"golang.org/x/tools/imports"
 )
 
 // Check of @Param @Success @Failure @Response @Header
@@ -68,8 +70,11 @@ func (f *Formatter) Format(fileName string, contents []byte) ([]byte, error) {
 	for _, comment := range ast.Comments {
 		formatFuncDoc(fileSet, comment.List, &edits)
 	}
-
-	return edits.apply(contents), nil
+	formatted, err := imports.Process(fileName, edits.apply(contents), nil)
+	if err != nil {
+		return nil, err
+	}
+	return formatted, nil
 }
 
 type edit struct {
diff --git a/go.mod b/go.mod
index c8f7487..3a40bc1 100644
--- a/go.mod
+++ b/go.mod
@@ -25,6 +25,7 @@ require (
 	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/russross/blackfriday/v2 v2.0.1 // indirect
 	github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
+	golang.org/x/mod v0.9.0 // indirect
 	golang.org/x/net v0.23.0 // indirect
 	golang.org/x/sys v0.18.0 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
diff --git a/go.sum b/go.sum
index 4c16e3b..98185a3 100644
--- a/go.sum
+++ b/go.sum
@@ -48,6 +48,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
 github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
 github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
 golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
+golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
 golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
 golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
diff --git a/operation.go b/operation.go
index acb1d38..f7a3736 100644
--- a/operation.go
+++ b/operation.go
@@ -254,7 +254,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
 
 	name := matches[1]
 	paramType := matches[2]
-	refType := TransToValidSchemeType(matches[3])
+	refType, format := TransToValidSchemeTypeWithFormat(matches[3])
 
 	// Detect refType
 	objectType := OBJECT
@@ -262,7 +262,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
 	if strings.HasPrefix(refType, "[]") {
 		objectType = ARRAY
 		refType = strings.TrimPrefix(refType, "[]")
-		refType = TransToValidSchemeType(refType)
+		refType, format = TransToValidSchemeTypeWithFormat(refType)
 	} else if IsPrimitiveType(refType) ||
 		paramType == "formData" && refType == "file" {
 		objectType = PRIMITIVE
@@ -275,7 +275,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
 			if objectType == OBJECT {
 				objectType = PRIMITIVE
 			}
-			refType = TransToValidSchemeType(schema.Type[0])
+			refType, format = TransToValidSchemeTypeWithFormat(schema.Type[0])
 			enums = schema.Enum
 		}
 	}
@@ -284,7 +284,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
 	required := requiredText == "true" || requiredText == requiredLabel
 	description := strings.Join(strings.Split(matches[5], "\\n"), "\n")
 
-	param := createParameter(paramType, description, name, objectType, refType, required, enums, operation.parser.collectionFormatInQuery)
+	param := createParameter(paramType, description, name, objectType, refType, format, required, enums, operation.parser.collectionFormatInQuery)
 
 	switch paramType {
 	case "path", "header", "query", "formData":
@@ -344,10 +344,10 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
 					if !IsSimplePrimitiveType(itemSchema.Type[0]) {
 						continue
 					}
-					param = createParameter(paramType, prop.Description, name, prop.Type[0], itemSchema.Type[0], findInSlice(schema.Required, item.Name), itemSchema.Enum, operation.parser.collectionFormatInQuery)
+					param = createParameter(paramType, prop.Description, name, prop.Type[0], itemSchema.Type[0], format, findInSlice(schema.Required, item.Name), itemSchema.Enum, operation.parser.collectionFormatInQuery)
 
 				case IsSimplePrimitiveType(prop.Type[0]):
-					param = createParameter(paramType, prop.Description, name, PRIMITIVE, prop.Type[0], findInSlice(schema.Required, item.Name), nil, operation.parser.collectionFormatInQuery)
+					param = createParameter(paramType, prop.Description, name, PRIMITIVE, prop.Type[0], format, findInSlice(schema.Required, item.Name), nil, operation.parser.collectionFormatInQuery)
 				default:
 					operation.parser.debug.Printf("skip field [%s] in %s is not supported type for %s", name, refType, paramType)
 					continue
@@ -846,9 +846,7 @@ func parseObjectSchema(parser *Parser, refType string, astFile *ast.File) (*spec
 	case refType == ANY:
 		return &spec.Schema{}, nil
 	case IsGolangPrimitiveType(refType):
-		refType = TransToValidSchemeType(refType)
-
-		return PrimitiveSchema(refType), nil
+		return TransToValidPrimitiveSchema(refType), nil
 	case IsPrimitiveType(refType):
 		return PrimitiveSchema(refType), nil
 	case strings.HasPrefix(refType, "[]"):
@@ -1183,7 +1181,7 @@ func (operation *Operation) AddResponse(code int, response *spec.Response) {
 }
 
 // createParameter returns swagger spec.Parameter for given  paramType, description, paramName, schemaType, required.
-func createParameter(paramType, description, paramName, objectType, schemaType string, required bool, enums []interface{}, collectionFormat string) spec.Parameter {
+func createParameter(paramType, description, paramName, objectType, schemaType string, format string, required bool, enums []interface{}, collectionFormat string) spec.Parameter {
 	// //five possible parameter types. 	query, path, body, header, form
 	result := spec.Parameter{
 		ParamProps: spec.ParamProps{
@@ -1207,12 +1205,14 @@ func createParameter(paramType, description, paramName, objectType, schemaType s
 				Enum: enums,
 			},
 			SimpleSchema: spec.SimpleSchema{
-				Type: schemaType,
+				Type:   schemaType,
+				Format: format,
 			},
 		}
 	case PRIMITIVE, OBJECT:
 		result.Type = schemaType
 		result.Enum = enums
+		result.Format = format
 	}
 	return result
 }
diff --git a/packages.go b/packages.go
index 2032414..f63b112 100644
--- a/packages.go
+++ b/packages.go
@@ -146,7 +146,7 @@ func (pkgDefs *PackagesDefinitions) parseTypesFromFile(astFile *ast.File, packag
 						parsedSchemas[typeSpecDef] = &Schema{
 							PkgPath: typeSpecDef.PkgPath,
 							Name:    astFile.Name.Name,
-							Schema:  PrimitiveSchema(TransToValidSchemeType(idt.Name)),
+							Schema:  TransToValidPrimitiveSchema(idt.Name),
 						}
 					}
 
@@ -213,7 +213,7 @@ func (pkgDefs *PackagesDefinitions) parseFunctionScopedTypesFromFile(astFile *as
 									parsedSchemas[typeSpecDef] = &Schema{
 										PkgPath: typeSpecDef.PkgPath,
 										Name:    astFile.Name.Name,
-										Schema:  PrimitiveSchema(TransToValidSchemeType(idt.Name)),
+										Schema:  TransToValidPrimitiveSchema(idt.Name),
 									}
 								}
 
diff --git a/parser.go b/parser.go
index 2f658e9..6d1644a 100644
--- a/parser.go
+++ b/parser.go
@@ -1215,7 +1215,7 @@ func (parser *Parser) getTypeSchema(typeName string, file *ast.File, ref bool) (
 		return &spec.Schema{}, nil
 	}
 	if IsGolangPrimitiveType(typeName) {
-		return PrimitiveSchema(TransToValidSchemeType(typeName)), nil
+		return TransToValidPrimitiveSchema(typeName), nil
 	}
 
 	schemaType, err := convertFromSpecificToPrimitive(typeName)
diff --git a/schema.go b/schema.go
index b3a5b38..234eb3f 100644
--- a/schema.go
+++ b/schema.go
@@ -75,6 +75,44 @@ func IsNumericType(typeName string) bool {
 	return typeName == INTEGER || typeName == NUMBER
 }
 
+// TransToValidPrimitiveSchema transfer golang basic type to swagger schema with format considered.
+func TransToValidPrimitiveSchema(typeName string) *spec.Schema {
+	switch typeName {
+	case "int", "uint":
+		return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{INTEGER}}}
+	case "uint8", "int8", "uint16", "int16", "byte", "int32", "uint32", "rune":
+		return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{INTEGER}, Format: "int32"}}
+	case "uint64", "int64":
+		return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{INTEGER}, Format: "int64"}}
+	case "float32", "float64":
+		return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{NUMBER}, Format: typeName}}
+	case "bool":
+		return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{BOOLEAN}}}
+	case "string":
+		return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{STRING}}}
+	}
+	return &spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{typeName}}}
+}
+
+// TransToValidSchemeTypeWithFormat indicates type will transfer golang basic type to swagger supported type with format.
+func TransToValidSchemeTypeWithFormat(typeName string) (string, string) {
+	switch typeName {
+	case "int", "uint":
+		return INTEGER, ""
+	case "uint8", "int8", "uint16", "int16", "byte", "int32", "uint32", "rune":
+		return INTEGER, "int32"
+	case "uint64", "int64":
+		return INTEGER, "int64"
+	case "float32", "float64":
+		return NUMBER, typeName
+	case "bool":
+		return BOOLEAN, ""
+	case "string":
+		return STRING, ""
+	}
+	return typeName, ""
+}
+
 // TransToValidSchemeType indicates type will transfer golang basic type to swagger supported type.
 func TransToValidSchemeType(typeName string) string {
 	switch typeName {


Test patch:
diff --git a/formatter_test.go b/formatter_test.go
index 4c650a9..0e02fab 100644
--- a/formatter_test.go
+++ b/formatter_test.go
@@ -64,77 +64,80 @@ func Test_FormatMain(t *testing.T) {
 	func main() {}`
 
 	want := `package main
-	//	@title			Swagger Example API
-	//	@version		1.0
-	//	@description	This is a sample server Petstore server.
-	//	@termsOfService	http://swagger.io/terms/
-
-	//	@contact.name	API Support
-	//	@contact.url	http://www.swagger.io/support
-	//	@contact.email	support@swagger.io
-
-	//	@license.name	Apache 2.0
-	//	@license.url	http://www.apache.org/licenses/LICENSE-2.0.html
-
-	//	@host		petstore.swagger.io
-	//	@BasePath	/v2
-
-	//	@securityDefinitions.basic	BasicAuth
-
-	//	@securityDefinitions.apikey	ApiKeyAuth
-	//	@in							header
-	//	@name						Authorization
-
-	//	@securitydefinitions.oauth2.application	OAuth2Application
-	//	@tokenUrl								https://example.com/oauth/token
-	//	@scope.write							Grants write access
-	//	@scope.admin							Grants read and write access to administrative information
-
-	//	@securitydefinitions.oauth2.implicit	OAuth2Implicit
-	//	@authorizationurl						https://example.com/oauth/authorize
-	//	@scope.write							Grants write access
-	//	@scope.admin							Grants read and write access to administrative information
-
-	//	@securitydefinitions.oauth2.password	OAuth2Password
-	//	@tokenUrl								https://example.com/oauth/token
-	//	@scope.read								Grants read access
-	//	@scope.write							Grants write access
-	//	@scope.admin							Grants read and write access to administrative information
-
-	//	@securitydefinitions.oauth2.accessCode	OAuth2AccessCode
-	//	@tokenUrl								https://example.com/oauth/token
-	//	@authorizationurl						https://example.com/oauth/authorize
-	//	@scope.admin							Grants read and write access to administrative information
-	func main() {}`
+
+//	@title			Swagger Example API
+//	@version		1.0
+//	@description	This is a sample server Petstore server.
+//	@termsOfService	http://swagger.io/terms/
+
+//	@contact.name	API Support
+//	@contact.url	http://www.swagger.io/support
+//	@contact.email	support@swagger.io
+
+//	@license.name	Apache 2.0
+//	@license.url	http://www.apache.org/licenses/LICENSE-2.0.html
+
+//	@host		petstore.swagger.io
+//	@BasePath	/v2
+
+//	@securityDefinitions.basic	BasicAuth
+
+//	@securityDefinitions.apikey	ApiKeyAuth
+//	@in							header
+//	@name						Authorization
+
+//	@securitydefinitions.oauth2.application	OAuth2Application
+//	@tokenUrl								https://example.com/oauth/token
+//	@scope.write							Grants write access
+//	@scope.admin							Grants read and write access to administrative information
+
+//	@securitydefinitions.oauth2.implicit	OAuth2Implicit
+//	@authorizationurl						https://example.com/oauth/authorize
+//	@scope.write							Grants write access
+//	@scope.admin							Grants read and write access to administrative information
+
+//	@securitydefinitions.oauth2.password	OAuth2Password
+//	@tokenUrl								https://example.com/oauth/token
+//	@scope.read								Grants read access
+//	@scope.write							Grants write access
+//	@scope.admin							Grants read and write access to administrative information
+
+// @securitydefinitions.oauth2.accessCode	OAuth2AccessCode
+// @tokenUrl								https://example.com/oauth/token
+// @authorizationurl						https://example.com/oauth/authorize
+// @scope.admin							Grants read and write access to administrative information
+func main() {}
+`
 	testFormat(t, "main.go", contents, want)
 }
 
 func Test_FormatMultipleFunctions(t *testing.T) {
 	contents := `package main
 
-	// @Produce json
-	// @Success 200 {object} string
-	// @Failure 400 {object} string
+// @Produce json
+// @Success 200 {object} string
+// @Failure 400 {object} string
 	func A() {}
 
-	// @Description Description of B.
-	// @Produce json
-	// @Success 200 {array} string
-	// @Failure 400 {object} string
+// @Description Description of B.
+// @Produce json
+// @Success 200 {array} string
+// @Failure 400 {object} string
 	func B() {}`
 
 	want := `package main
 
-	//	@Produce	json
-	//	@Success	200	{object}	string
-	//	@Failure	400	{object}	string
-	func A() {}
+// @Produce	json
+// @Success	200	{object}	string
+// @Failure	400	{object}	string
+func A() {}
 
-	//	@Description	Description of B.
-	//	@Produce		json
-	//	@Success		200	{array}		string
-	//	@Failure		400	{object}	string
-	func B() {}`
+// @Description	Description of B.
+// @Produce		json
+// @Success		200	{array}		string
+// @Failure		400	{object}	string
+func B() {}
+`
 
 	testFormat(t, "main.go", contents, want)
 }
@@ -142,76 +145,86 @@ func Test_FormatMultipleFunctions(t *testing.T) {
 func Test_FormatApi(t *testing.T) {
 	contents := `package api
 
-	import "net/http"
-
-	// @Summary Add a new pet to the store
-	// @Description get string by ID
-	// @ID get-string-by-int
-	// @Accept  json
-	// @Produce  json
-	// @Param   some_id      path   int     true  "Some ID" Format(int64)
-	// @Param   some_id      body web.Pet true  "Some ID"
-	// @Success 200 {string} string	"ok"
-	// @Failure 400 {object} web.APIError "We need ID!!"
-	// @Failure 404 {object} web.APIError "Can not find ID"
-	// @Router /testapi/get-string-by-int/{some_id} [get]
+import "net/http"
+
+// @Summary Add a new pet to the store
+// @Description get string by ID
+// @ID get-string-by-int
+// @Accept  json
+// @Produce  json
+// @Param   some_id      path   int     true  "Some ID" Format(int64)
+// @Param   some_id      body web.Pet true  "Some ID"
+// @Success 200 {string} string	"ok"
+// @Failure 400 {object} web.APIError "We need ID!!"
+// @Failure 404 {object} web.APIError "Can not find ID"
+// @Router /testapi/get-string-by-int/{some_id} [get]
 	func GetStringByInt(w http.ResponseWriter, r *http.Request) {}`
 
 	want := `package api
 
-	import "net/http"
-
-	//	@Summary		Add a new pet to the store
-	//	@Description	get string by ID
-	//	@ID				get-string-by-int
-	//	@Accept			json
-	//	@Produce		json
-	//	@Param			some_id	path		int				true	"Some ID"	Format(int64)
-	//	@Param			some_id	body		web.Pet			true	"Some ID"
-	//	@Success		200		{string}	string			"ok"
-	//	@Failure		400		{object}	web.APIError	"We need ID!!"
-	//	@Failure		404		{object}	web.APIError	"Can not find ID"
-	//	@Router			/testapi/get-string-by-int/{some_id} [get]
-	func GetStringByInt(w http.ResponseWriter, r *http.Request) {}`
+import "net/http"
+
+// @Summary		Add a new pet to the store
+// @Description	get string by ID
+// @ID				get-string-by-int
+// @Accept			json
+// @Produce		json
+// @Param			some_id	path		int				true	"Some ID"	Format(int64)
+// @Param			some_id	body		web.Pet			true	"Some ID"
+// @Success		200		{string}	string			"ok"
+// @Failure		400		{object}	web.APIError	"We need ID!!"
+// @Failure		404		{object}	web.APIError	"Can not find ID"
+// @Router			/testapi/get-string-by-int/{some_id} [get]
+func GetStringByInt(w http.ResponseWriter, r *http.Request) {}
+`
 
 	testFormat(t, "api.go", contents, want)
 }
 
 func Test_NonSwagComment(t *testing.T) {
 	contents := `package api
-	// @Summary Add a new pet to the store
-	// @Description get string by ID
-	// @ID get-string-by-int
-	// @ Accept json
-	// This is not a @swag comment`
+
+// @Summary Add a new pet to the store
+// @Description get string by ID
+// @ID get-string-by-int
+// @ Accept json
+// This is not a @swag comment`
 	want := `package api
-	//	@Summary		Add a new pet to the store
-	//	@Description	get string by ID
-	//	@ID				get-string-by-int
-	// @ Accept json
-	// This is not a @swag comment`
+
+//	@Summary		Add a new pet to the store
+//	@Description	get string by ID
+//	@ID				get-string-by-int
+// @ Accept json
+// This is not a @swag comment
+`
 
 	testFormat(t, "non_swag.go", contents, want)
 }
 
 func Test_EmptyComment(t *testing.T) {
 	contents := `package empty
-	// @Summary Add a new pet to the store
-	// @Description  `
+
+// @Summary Add a new pet to the store
+// @Description  `
 	want := `package empty
-	//	@Summary	Add a new pet to the store
-	//	@Description`
+
+//	@Summary	Add a new pet to the store
+//	@Description
+`
 
 	testFormat(t, "empty.go", contents, want)
 }
 
 func Test_AlignAttribute(t *testing.T) {
 	contents := `package align
-	// @Summary Add a new pet to the store
-	//  @Description Description`
+
+// @Summary Add a new pet to the store
+//  @Description Description`
 	want := `package align
-	//	@Summary		Add a new pet to the store
-	//	@Description	Description`
+
+//	@Summary		Add a new pet to the store
+//	@Description	Description
+`
 
 	testFormat(t, "align.go", contents, want)
 
diff --git a/operation_test.go b/operation_test.go
index 0e24d6c..aa77a83 100644
--- a/operation_test.go
+++ b/operation_test.go
@@ -1619,6 +1619,7 @@ func TestParseParamCommentByFormDataTypeUint64(t *testing.T) {
 	expected := `[
     {
         "type": "integer",
+        "format": "int64",
         "description": "this is a test file",
         "name": "file",
         "in": "formData",
diff --git a/parser_test.go b/parser_test.go
index f0ca3b9..777d411 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -1332,7 +1332,8 @@ func TestParseSimpleApi_ForSnakecase(t *testing.T) {
                     "type": "integer"
                 },
                 "err": {
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int32"
                 },
                 "status": {
                     "type": "boolean"
@@ -1788,7 +1789,8 @@ func TestParseSimpleApi_ForLowerCamelcase(t *testing.T) {
                     "type": "integer"
                 },
                 "err": {
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int32"
                 },
                 "status": {
                     "type": "boolean"
@@ -1947,7 +1949,8 @@ func TestParseStructComment(t *testing.T) {
                 },
                 "errorNo": {
                     "description": "Error ` + "`" + `number` + "`" + ` tick comment",
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int64"
                 }
             }
         }
diff --git a/testdata/generics_basic/expected.json b/testdata/generics_basic/expected.json
index 58689cf..4dc8819 100644
--- a/testdata/generics_basic/expected.json
+++ b/testdata/generics_basic/expected.json
@@ -354,7 +354,8 @@
                 "originMapField": {
                     "type": "object",
                     "additionalProperties": {
-                        "type": "number"
+                        "type": "number",
+                        "format": "float64"
                     }
                 }
             }
@@ -362,7 +363,8 @@
         "types.MapField-string-float64": {
             "type": "object",
             "additionalProperties": {
-                "type": "number"
+                "type": "number",
+                "format": "float64"
             }
         },
         "types.MapFieldNestedStruct-string": {
@@ -375,7 +377,8 @@
             "type": "object",
             "properties": {
                 "f": {
-                    "type": "number"
+                    "type": "number",
+                    "format": "float64"
                 },
                 "s": {
                     "type": "string"
@@ -431,7 +434,8 @@
                 },
                 "errorNo": {
                     "description": "Error `number` tick comment",
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int64"
                 }
             }
         },
diff --git a/testdata/generics_names/expected.json b/testdata/generics_names/expected.json
index 5da1de5..e363892 100644
--- a/testdata/generics_names/expected.json
+++ b/testdata/generics_names/expected.json
@@ -304,7 +304,8 @@
                 },
                 "errorNo": {
                     "description": "Error `number` tick comment",
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int64"
                 }
             }
         },
diff --git a/testdata/generics_property/expected.json b/testdata/generics_property/expected.json
index fe67258..7d8858f 100644
--- a/testdata/generics_property/expected.json
+++ b/testdata/generics_property/expected.json
@@ -153,7 +153,8 @@
                     }
                 },
                 "items2": {
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int32"
                 },
                 "post": {
                     "$ref": "#/definitions/types.Field-array_types_Post"
@@ -444,7 +445,8 @@
                     }
                 },
                 "items2": {
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int32"
                 }
             }
         }
diff --git a/testdata/state/admin_expected.json b/testdata/state/admin_expected.json
index d5f3a3d..ef5e388 100644
--- a/testdata/state/admin_expected.json
+++ b/testdata/state/admin_expected.json
@@ -367,7 +367,8 @@
                     "type": "integer"
                 },
                 "err": {
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int32"
                 },
                 "status": {
                     "type": "boolean"
diff --git a/testdata/state/user_expected.json b/testdata/state/user_expected.json
index 18431c0..0dc8d25 100644
--- a/testdata/state/user_expected.json
+++ b/testdata/state/user_expected.json
@@ -367,7 +367,8 @@
                     "type": "integer"
                 },
                 "err": {
-                    "type": "integer"
+                    "type": "integer",
+                    "format": "int32"
                 },
                 "status": {
                     "type": "boolean"