From e2a79ebbd68e7ff3bb7ce4e34d4de7147c890cca Mon Sep 17 00:00:00 2001
From: Johan de Klerk <jdeklerk00@gmail.com>
Date: Tue, 10 May 2022 10:07:18 +0200
Subject: [PATCH] get doc tags

---
 api_documentation/api_documentation.go | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/api_documentation/api_documentation.go b/api_documentation/api_documentation.go
index c155a8c..8dd3497 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)
-- 
GitLab