Select Git revision
string_utils.go
api_documentation.go 7.19 KiB
package api_documentation
import (
"fmt"
"reflect"
"strings"
"gitlab.com/uafrica/go-utils/errors"
"gitlab.com/uafrica/go-utils/handler_utils"
)
type NoParams struct{}
type DocPath map[string]DocMethodInfo
type Docs struct {
Paths map[string]DocPath `json:"paths"`
Components DocSchemas `json:"components"`
}
type DocSchemas struct {
Schemas map[string]interface{} `json:"schemas"`
}
type DocMethodInfo struct {
Description string `json:"description"`
Tags []string `json:"tags"`
RequestBody *DocRequestBody `json:"requestBody,omitempty"`
Parameters []DocParam `json:"parameters,omitempty"`
Responses *map[string]DocResponseValue `json:"responses,omitempty"`
}
type DocRequestBody struct {
Description string `json:"description"`
Required bool `json:"required"`
Content map[string]interface{} `json:"content"`
}
type DocParam struct {
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description"`
Schema interface{} `json:"schema"`
}
type DocSchema struct {
Ref string `json:"$ref"`
}
type DocResponseValue struct {
Description string `json:"description"`
Content *map[string]interface{} `json:"content,omitempty"`
}
type DocSchemaResponse struct {
Type *string `json:"type,omitempty"`
Items DocSchema `json:"items"`
}
func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
docs := Docs{
Paths: map[string]DocPath{},
Components: DocSchemas{Schemas: map[string]interface{}{}},
}
var validationError error
if endpointHandlers, validationError = handler_utils.ValidateAPIEndpoints(endpointHandlers); validationError != nil {
return Docs{}, validationError
}
for path, methods := range endpointHandlers {