Skip to content
Snippets Groups Projects
Select Git revision
  • 2332f0397ab4af7d9a8c218fb5eec62ec4f7f721
  • main default protected
  • v1.298.0
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
22 results

string_utils.go

Blame
  • 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 {