From ecbb8cb4bf92a52f2eaa86dd6f70937289a95525 Mon Sep 17 00:00:00 2001 From: sdghchj Date: Wed, 11 Dec 2024 18:26:09 +0800 Subject: [PATCH] fix --- schema.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/schema.go b/schema.go index 9b2df0c99..234eb3fc5 100644 --- a/schema.go +++ b/schema.go @@ -78,9 +78,11 @@ func IsNumericType(typeName string) bool { // TransToValidPrimitiveSchema transfer golang basic type to swagger schema with format considered. func TransToValidPrimitiveSchema(typeName string) *spec.Schema { switch typeName { - case "uint", "int", "uint8", "int8", "uint16", "int16", "byte", "int32", "rune": + 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", "uint32": + 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}} @@ -95,9 +97,11 @@ func TransToValidPrimitiveSchema(typeName string) *spec.Schema { // TransToValidSchemeTypeWithFormat indicates type will transfer golang basic type to swagger supported type with format. func TransToValidSchemeTypeWithFormat(typeName string) (string, string) { switch typeName { - case "uint", "int", "uint8", "int8", "uint16", "int16", "byte", "int32", "rune": + case "int", "uint": + return INTEGER, "" + case "uint8", "int8", "uint16", "int16", "byte", "int32", "uint32", "rune": return INTEGER, "int32" - case "uint64", "int64", "uint32": + case "uint64", "int64": return INTEGER, "int64" case "float32", "float64": return NUMBER, typeName