Documentation ¶
Index ¶
- Constants
- func AddFlag(name, schemaType, description string, value any, flags *pflag.FlagSet) any
- func InitOpenAPI(sc *config.Config, skipCache bool) error
- func InitOpenAPIFromSchema(t openapi3.T) error
- type API
- type ArrayObjectFlag
- type BodyParam
- type BodyParams
- type DataFrom
- type ObjectFlag
- type ObjectIDFlag
- type Operation
- type Param
- type Version
- type VersionInfo
Constants ¶
const ( ValueTypeObjectID = "objectID" ValueTypeArrayObject = "array[object]" ValueTypeArrayString = "array[string]" ValueTypeArrayNumber = "array[number]" ValueTypeArrayInt = "array[integer]" ValueTypeArrayBoolean = "array[boolean]" ValueTypeMapStringInt64 = "map[string]int64" ValueTypeMapStringInt32 = "map[string]int32" ValueTypeMapStringInt = "map[string]int" ValueTypeMapStringString = "map[string]string" )
Value types extend the OpenAPI specification to support more types.
const (
// JsonMediaType is support request body media type.
JsonMediaType = "application/json"
)
Variables ¶
This section is empty.
Functions ¶
func AddFlag ¶
AddFlag create flag with name, type, description, default value, and add it to flagSet.
func InitOpenAPI ¶ added in v0.5.0
InitOpenAPI load from cache or remote and setup command.
func InitOpenAPIFromSchema ¶ added in v0.5.0
InitOpenAPIFromSchema load from schema and setup command.
Types ¶
type API ¶
type API struct { Version `json:",inline"` Short string `json:"short"` Long string `json:"long,omitempty"` Operations []Operation `json:"operations,omitempty"` }
API represents an abstracted API description, include details used to build CLI commands.
var OpenAPI *API
func LoadOpenAPIFromResp ¶ added in v0.5.0
LoadOpenAPIFromResp load OpenAPI schema from response body and generate API.
func LoadOpenAPIFromSchema ¶ added in v0.5.0
LoadOpenAPIFromSchema load the OpenAPI from schema.
func (*API) GenerateCommand ¶
GenerateCommand generate command from api and add to root command.
func (*API) GetOperation ¶ added in v0.5.0
type ArrayObjectFlag ¶
type ArrayObjectFlag []any
ArrayObjectFlag creates a custom flag for []interface.
func (*ArrayObjectFlag) Set ¶
func (i *ArrayObjectFlag) Set(value string) error
Set a new value on the flag.
func (*ArrayObjectFlag) String ¶
func (i *ArrayObjectFlag) String() string
String returns a string represent of this flag.
func (*ArrayObjectFlag) Type ¶
func (i *ArrayObjectFlag) Type() string
Type returns the type of this custom flag, which will be displayed in `--help` output.
type BodyParam ¶
type BodyParam struct { Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` Default any `json:"default,omitempty"` }
BodyParam represents each field in body.
func (BodyParam) AddFlag ¶
AddFlag adds a new option flag to a command's flag set for this body param.
func (BodyParam) OptionName ¶
OptionName returns the commandline option name for this parameter.
type BodyParams ¶
type BodyParams struct { Type string `json:"type,omitempty"` Params []*BodyParam `json:"params,omitempty"` }
BodyParams represent request body and params type.
type ObjectFlag ¶
ObjectFlag creates a custom flag for map[string]any.
func (*ObjectFlag) String ¶
func (i *ObjectFlag) String() string
String returns a string represent of this flag.
func (*ObjectFlag) Type ¶
func (i *ObjectFlag) Type() string
Type returns the type of this custom flag, which will be displayed in `--help` output.
type ObjectIDFlag ¶
ObjectIDFlag creates a custom flag for map[string]string{"id": "xxx"}.
func (ObjectIDFlag) Set ¶
func (i ObjectIDFlag) Set(value string) error
Set a new value on the flag.
func (ObjectIDFlag) String ¶
func (i ObjectIDFlag) String() string
String returns a string represent of this flag.
func (ObjectIDFlag) Type ¶
func (i ObjectIDFlag) Type() string
Type returns the type of this custom flag, which will be displayed in `--help` output.
type Operation ¶
type Operation struct { Name string `json:"name"` Group string `json:"group,omitempty"` Short string `json:"short,omitempty"` Long string `json:"long,omitempty"` Method string `json:"method,omitempty"` URITemplate string `json:"uriTemplate"` URIParams []string `json:"uriParams"` PathParams []*Param `json:"pathParams,omitempty"` QueryParams []*Param `json:"queryParams,omitempty"` HeaderParams []*Param `json:"headerParams,omitempty"` BodyParams *BodyParams `json:"bodyParams,omitempty"` BodyMediaType string `json:"bodyMediaType,omitempty"` Hidden bool `json:"hidden,omitempty"` Deprecated string `json:"deprecated,omitempty"` Formats []string `json:"formats,omitempty"` TableColumns []string `json:"tableColumns,omitempty"` // CmdIgnore is used to ignore the operation when generating CLI commands. CmdIgnore bool `json:"cmdIgnore,omitempty"` }
Operation represents an API action, e.g. list-things or create-user.
type Param ¶
type Param struct { Name string `json:"name"` Type string `json:"type"` Description string `json:"description,omitempty"` Style string `json:"style,omitempty"` Explode bool `json:"explode,omitempty"` Default any `json:"default,omitempty"` DataFrom DataFrom `json:"dataFrom,omitempty"` // CmdIgnore is used to ignore the operation when generating CLI commands. CmdIgnore bool `json:"cmdIgnore,omitempty"` }
Param represents an API operation input parameter.
func (Param) OptionName ¶
OptionName returns the formatted commandline option name for this parameter.
type Version ¶ added in v0.5.0
type Version struct { Version string `json:"version" yaml:"version"` GitCommit string `json:"gitCommit" yaml:"gitCommit"` IsDevVersion bool `json:"isDevVersion" yaml:"isDevVersion"` }
Version include the version and commit.
func GetAPIVersionFromCache ¶ added in v0.5.0
func GetAPIVersionFromCache() *Version
GetAPIVersionFromCache load api version from cache.
type VersionInfo ¶ added in v0.5.0
type VersionInfo struct { ClientVersion Version `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"` ServerVersion Version `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"` OpenAPIVersion Version `json:"openAPIVersion,omitempty" yaml:"-"` }
VersionInfo include the client, server and openapi version.
func GetVersion ¶ added in v0.5.0
func GetVersion(sc *config.Config) (*VersionInfo, error)
GetVersion get client, server and openapi version.