diff --git a/api_documentation/api_documentation.go b/api_documentation/api_documentation.go index c155a8c5911133672aa833e534ef7b95b074feb8..8dd349751b2dfbbce2b6362821ca277abf2a9702 100644 --- a/api_documentation/api_documentation.go +++ b/api_documentation/api_documentation.go @@ -46,6 +46,7 @@ type DocParam struct { Name string `json:"name"` In string `json:"in"` Description string `json:"description"` + Required bool `json:"required,omitempty"` Schema interface{} `json:"schema"` } @@ -93,6 +94,11 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}, corePath string for i := 0; i < handler.RequestParamsType.NumField(); i++ { f := handler.RequestParamsType.Field(i) + shouldAddDoc := f.Tag.Get("doc") + if shouldAddDoc == "-" { + continue + } + name := f.Tag.Get("json") if name == "" { name = f.Name @@ -111,6 +117,10 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}, corePath string Schema: schema, } + if f.Tag.Get("doc_required") == "true" { + parameter.Required = true + } + docMethod.Parameters = append(docMethod.Parameters, parameter) } @@ -205,7 +215,7 @@ func StructSchema(t reflect.Type) (interface{}, error) { schema["format"] = fmt.Sprintf("%v", t) case reflect.Float64, reflect.Float32: schema["type"] = "number" - schema["format"] = fmt.Sprintf("%v", t) + schema["format"] = "float" case reflect.Bool: schema["type"] = "boolean" schema["format"] = fmt.Sprintf("%v", t)