Skip to content
Snippets Groups Projects
Select Git revision
  • e7542b39d3d1c20ce526227a505c1769dca1d77a
  • dev default protected
  • prod protected
  • 1.0.58
  • 1.0.57
  • 1.0.52
  • 1.0.56
  • 1.0.51
  • 1.0.50
  • 1.0.33
  • 1.0.32
  • 1.0.31
  • 1.0.30
  • 1.0.29
  • 1.0.28
  • 1.0.27
  • 1.0.26
  • 1.0.25
  • 1.0.24
  • 1.0.23
  • 1.0.22
  • 1.0.21
  • 1.0.20
23 results

LayoutProcessorPlugin.php

Blame
  • api_documentation.go 10.03 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{