Skip to content
Snippets Groups Projects
Select Git revision
  • e2a79ebbd68e7ff3bb7ce4e34d4de7147c890cca
  • 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

api_documentation.go

Blame
  • api_documentation.go 8.83 KiB
    package api_documentation
    
    import (
    	"fmt"
    	"gitlab.com/uafrica/go-utils/logs"
    	"go/doc"
    	"go/parser"
    	"go/token"
    	"os"
    	"path/filepath"
    	"reflect"
    	"runtime"
    	"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"`
    	Required bool `json:"required,omitempty"`
    	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{}, corePath string) (Docs, error) {
    	docs := Docs{
    		Paths:      map[string]DocPath{},
    		Components: DocSchemas{Schemas: map[string]interface{}{}},