util

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgProperty

type ArgProperty struct {
	Name        string `json:"name" yaml:"name"`
	Description string `json:"description" yaml:"description"`
	Required    bool   `json:"required" yaml:"required"`
	Type        string `json:"type" yaml:"type"`
}

ArgProperty represents command argument properties

type CmdApiProps

type CmdApiProps struct {
	Use     string        `json:"use" yaml:"use"`
	Short   string        `json:"short" yaml:"short"`
	Long    string        `json:"long" yaml:"long"`
	Aliases []string      `json:"aliases,omitempty" yaml:"aliases,omitempty"`
	Path    string        `json:"path" yaml:"path"`
	Get     *Operation    `json:"get,omitempty" yaml:"get,omitempty"`
	Post    *Operation    `json:"post,omitempty" yaml:"post,omitempty"`
	HasArgs bool          `json:"hasArgs" yaml:"hasArgs"`
	Flags   []QueryParam  `json:"flags,omitempty" yaml:"flags,omitempty"`
	Args    []ArgProperty `json:"args,omitempty" yaml:"args,omitempty"`
}

CmdApiProps represents the API properties of a single command

func (*CmdApiProps) ExportToJSON

func (cmd *CmdApiProps) ExportToJSON(filename string) error

ExportCommandToJSON exports a single command to JSON format

func (*CmdApiProps) ExportToYAML

func (cmd *CmdApiProps) ExportToYAML(filename string) error

ExportCommandToYAML exports a single command to YAML format

type CommandNode

type CommandNode struct {
	Command  *CmdApiProps   `json:"command,omitempty" yaml:"command,omitempty"`
	Children []*CommandNode `json:"children,omitempty" yaml:"children,omitempty"`
}

CommandNode represents a node in the command tree

type CommandTree

type CommandTree struct {
	Root     *CommandNode   `json:"root" yaml:"root"`
	Commands []*CmdApiProps `json:"commands" yaml:"commands"`
}

CommandTree represents the complete command tree

func BuildCommandTree

func BuildCommandTree(rootCmd *cobra.Command) *CommandTree

BuildCommandTree generates a hierarchical structure of all cobra commands

Example
// Example usage of BuildCommandTree
tree := BuildCommandTree(cmd.RootCommand)

// Print basic info
println("Root command:", tree.Root.Command.Use)
println("Description:", tree.Root.Command.Short)
println("Number of flags:", len(tree.Root.Command.Flags))
println("Number of commands:", len(tree.Commands))

// Print command names and paths
for _, cmd := range tree.Commands {
	println("  -", cmd.Use, "at", cmd.Path)
}

func BuildCommandTreeFromSource

func BuildCommandTreeFromSource(rootDir string) (*CommandTree, error)

BuildCommandTreeFromSource analyzes cobra commands from source files

func (*CommandTree) ExportToJSON

func (ct *CommandTree) ExportToJSON(filename string) error

ExportToJSON exports a command tree to JSON format

func (*CommandTree) ExportToYAML

func (ct *CommandTree) ExportToYAML(filename string) error

ExportToYAML exports a command tree to YAML format

func (*CommandTree) GenerateCommandTemplates

func (ct *CommandTree) GenerateCommandTemplates(outputDir string) error

GenerateCommandTemplates generates API template files for commands with args

func (*CommandTree) GenerateOpenAPISpec

func (ct *CommandTree) GenerateOpenAPISpec(title, description, version string) *OpenAPISpec

GenerateOpenAPISpec generates a complete OpenAPI 3.0 specification

type ContentType

type ContentType struct {
	Schema   Schema                `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example  interface{}           `json:"example,omitempty" yaml:"example,omitempty"`
	Examples map[string]ExampleObj `json:"examples,omitempty" yaml:"examples,omitempty"`
	Encoding map[string]Encoding   `json:"encoding,omitempty" yaml:"encoding,omitempty"`
}

ContentType represents OpenAPI content type

type Encoding

type Encoding struct {
	ContentType   string            `json:"contentType,omitempty" yaml:"contentType,omitempty"`
	Headers       map[string]Header `json:"headers,omitempty" yaml:"headers,omitempty"`
	Style         string            `json:"style,omitempty" yaml:"style,omitempty"`
	Explode       bool              `json:"explode,omitempty" yaml:"explode,omitempty"`
	AllowReserved bool              `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}

Encoding represents OpenAPI encoding object

type ExampleObj

type ExampleObj struct {
	Summary       string      `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description   string      `json:"description,omitempty" yaml:"description,omitempty"`
	Value         interface{} `json:"value,omitempty" yaml:"value,omitempty"`
	ExternalValue string      `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
}

ExampleObj represents OpenAPI example object

type Header struct {
	Description string      `json:"description,omitempty" yaml:"description,omitempty"`
	Required    bool        `json:"required,omitempty" yaml:"required,omitempty"`
	Deprecated  bool        `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Schema      Schema      `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example     interface{} `json:"example,omitempty" yaml:"example,omitempty"`
}

Header represents OpenAPI header

type Link struct {
	OperationRef string            `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
	OperationId  string            `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Parameters   map[string]string `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody  interface{}       `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Description  string            `json:"description,omitempty" yaml:"description,omitempty"`
	Server       *OpenAPIServer    `json:"server,omitempty" yaml:"server,omitempty"`
}

Link represents OpenAPI link

type OAuthFlow

type OAuthFlow struct {
	AuthorizationUrl string            `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
	TokenUrl         string            `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
	RefreshUrl       string            `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes" yaml:"scopes"`
}

OAuthFlow represents OpenAPI OAuth flow

type OAuthFlows

type OAuthFlows struct {
	Implicit          *OAuthFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty" yaml:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}

OAuthFlows represents OpenAPI OAuth flows

type OpenAPIComponents

type OpenAPIComponents struct {
	Schemas         map[string]Schema         `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Responses       map[string]Response       `json:"responses,omitempty" yaml:"responses,omitempty"`
	Parameters      map[string]QueryParam     `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBodies   map[string]RequestBody    `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
}

OpenAPIComponents represents OpenAPI components section

type OpenAPIContact

type OpenAPIContact struct {
	Name  string `json:"name,omitempty" yaml:"name,omitempty"`
	URL   string `json:"url,omitempty" yaml:"url,omitempty"`
	Email string `json:"email,omitempty" yaml:"email,omitempty"`
}

OpenAPIContact represents OpenAPI contact information

type OpenAPIInfo

type OpenAPIInfo struct {
	Title          string          `json:"title" yaml:"title"`
	Description    string          `json:"description" yaml:"description"`
	Version        string          `json:"version" yaml:"version"`
	Contact        *OpenAPIContact `json:"contact,omitempty" yaml:"contact,omitempty"`
	License        *OpenAPILicense `json:"license,omitempty" yaml:"license,omitempty"`
	TermsOfService string          `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
}

OpenAPIInfo represents OpenAPI info section

type OpenAPILicense

type OpenAPILicense struct {
	Name string `json:"name" yaml:"name"`
	URL  string `json:"url,omitempty" yaml:"url,omitempty"`
}

OpenAPILicense represents OpenAPI license information

type OpenAPIServer

type OpenAPIServer struct {
	URL         string                    `json:"url" yaml:"url"`
	Description string                    `json:"description,omitempty" yaml:"description,omitempty"`
	Variables   map[string]ServerVariable `json:"variables,omitempty" yaml:"variables,omitempty"`
}

OpenAPIServer represents OpenAPI server object

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI    string                          `json:"openapi" yaml:"openapi"`
	Info       OpenAPIInfo                     `json:"info" yaml:"info"`
	Servers    []OpenAPIServer                 `json:"servers,omitempty" yaml:"servers,omitempty"`
	Paths      map[string]map[string]Operation `json:"paths" yaml:"paths"`
	Components *OpenAPIComponents              `json:"components,omitempty" yaml:"components,omitempty"`
}

OpenAPISpec represents a complete OpenAPI 3.0 specification

func (*OpenAPISpec) ExportToJSON

func (spec *OpenAPISpec) ExportToJSON(filename string) error

ExportOpenAPISpec exports OpenAPI specification to JSON or YAML

func (*OpenAPISpec) ExportToYAML

func (spec *OpenAPISpec) ExportToYAML(filename string) error

type Operation

type Operation struct {
	Summary     string                `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string                `json:"description,omitempty" yaml:"description,omitempty"`
	OperationId string                `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Tags        []string              `json:"tags,omitempty" yaml:"tags,omitempty"`
	Parameters  []QueryParam          `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody *RequestBody          `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses   map[string]Response   `json:"responses" yaml:"responses"`
	Deprecated  bool                  `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Security    []map[string][]string `json:"security,omitempty" yaml:"security,omitempty"`
	Servers     []OpenAPIServer       `json:"servers,omitempty" yaml:"servers,omitempty"`
}

Operation represents OpenAPI operation

type QueryParam

type QueryParam struct {
	Name        string `json:"name" yaml:"name"`
	In          string `json:"in" yaml:"in"`
	Description string `json:"description" yaml:"description"`
	Required    bool   `json:"required" yaml:"required"`
	Schema      Schema `json:"schema" yaml:"schema"`
}

QueryParam represents a query parameter for OpenAPI

type RequestBody

type RequestBody struct {
	Description string                 `json:"description" yaml:"description"`
	Required    bool                   `json:"required" yaml:"required"`
	Content     map[string]ContentType `json:"content" yaml:"content"`
}

RequestBody represents OpenAPI request body

type Response

type Response struct {
	Description string                 `json:"description" yaml:"description"`
	Headers     map[string]Header      `json:"headers,omitempty" yaml:"headers,omitempty"`
	Content     map[string]ContentType `json:"content,omitempty" yaml:"content,omitempty"`
	Links       map[string]Link        `json:"links,omitempty" yaml:"links,omitempty"`
}

Response represents OpenAPI response

type Schema

type Schema struct {
	Type        string            `json:"type" yaml:"type"`
	Format      string            `json:"format,omitempty" yaml:"format,omitempty"`
	Default     interface{}       `json:"default,omitempty" yaml:"default,omitempty"`
	Enum        []string          `json:"enum,omitempty" yaml:"enum,omitempty"`
	Items       *Schema           `json:"items,omitempty" yaml:"items,omitempty"`
	Properties  map[string]Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	Required    []string          `json:"required,omitempty" yaml:"required,omitempty"`
	Example     interface{}       `json:"example,omitempty" yaml:"example,omitempty"`
	Description string            `json:"description,omitempty" yaml:"description,omitempty"`
}

Schema represents an OpenAPI schema

type SecurityScheme

type SecurityScheme struct {
	Type             string      `json:"type" yaml:"type"`
	Description      string      `json:"description,omitempty" yaml:"description,omitempty"`
	Name             string      `json:"name,omitempty" yaml:"name,omitempty"`
	In               string      `json:"in,omitempty" yaml:"in,omitempty"`
	Scheme           string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`
	BearerFormat     string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
	Flows            *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
	OpenIdConnectUrl string      `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
}

SecurityScheme represents OpenAPI security scheme

type ServerVariable

type ServerVariable struct {
	Enum        []string `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default     string   `json:"default" yaml:"default"`
	Description string   `json:"description,omitempty" yaml:"description,omitempty"`
}

ServerVariable represents OpenAPI server variable

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL