api

package
v0.0.0-...-206ef24 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowErrors = flag.Bool("allow-errors", false, "If true, don't fail on errors.")
View Source
var AutoDetect = flag.Bool("auto-detect", false, "If true, auto-detect API groups and versions from swagger.json.")
View Source
var Backend = flag.String("backend", "html", "Output format for the generator. Supported values: 'html', 'markdown', or 'hugo-md'.")
View Source
var BuildDir string

Directory for backend output files

View Source
var BuildOps = flag.Bool("build-operations", true, "If true build operations in the docs.")
View Source
var ConfigDir string

Directory for configuration and data files

View Source
var EmptyExampleProviders = []ExampleProvider{
	EmptyExample{},
}
View Source
var ExampleProviders = []ExampleProvider{
	KubectlExample{},
	CurlExample{},
}
View Source
var IncludesDir string

Directory for temporary files that will eventually get merged into the HTML output file.

View Source
var KubernetesRelease = flag.String("kubernetes-release", "", "Kubernetes release version.")
View Source
var SectionsDir string

Directory for static sections

View Source
var UseTags = flag.Bool("use-tags", false, "If true, use the openapi tags instead of the config yaml.")
View Source
var VersionedConfigDir string

Directory for versioned configuration file and swagger.json

View Source
var WorkDir = flag.String("work-dir", "", "Working directory for the generator.")

Functions

func DetectGroupsFromSpec

func DetectGroupsFromSpec(specs []*loads.Document) (map[string]string, []string)

func EscapeAsterisks

func EscapeAsterisks(des string) string

handle '*', 'a/*', '*/b', '*/*' cases

func GetDefinitionVersionKind

func GetDefinitionVersionKind(s spec.Schema) (string, string, string)

GetDefinitionVersionKind returns the api version and kind for the spec. This is the primary key of a Definition.

func GetDefinitionVersionKindFromString

func GetDefinitionVersionKindFromString(s string) (string, string, string)

func GetTypeName

func GetTypeName(s spec.Schema) string

GetTypeName returns the display name of a Schema. This is the api kind for definitions and the type for primitive types. Arrays of objects have "array" appended.

func GuessGVK

func GuessGVK(name string) (group, version, kind string)

GuessGVK makes a guess about the (Group, Version, Kind) tuple based on resource name TODO: Rework this function because it is ugly

func IsArray

func IsArray(s spec.Schema) bool

IsArray returns true if the type is an array type.

func IsBlacklistedOperation

func IsBlacklistedOperation(o *spec.Operation) bool

func IsComplex

func IsComplex(schema spec.Schema) bool

IsComplex returns true if the schema is for a complex (non-primitive) definitions

func IsDefinition

func IsDefinition(s spec.Schema) bool

IsDefinition returns true if Schema is a complex type that should have a Definition.

func LoadDefinitions

func LoadDefinitions(config *Config, specs []*loads.Document, s *Definitions) error

func LoadOpenApiSpec

func LoadOpenApiSpec() ([]*loads.Document, error)

Loads all of the open-api documents

func ParseSpecInfo

func ParseSpecInfo(specs []*loads.Document, cfg *Config)

func VisitOperations

func VisitOperations(specs []*loads.Document, fn func(operation Operation))

VisitOperations calls fn once for each operation found in the collection of Documents VisitOperations calls fn once for each operation found in the collection of Documents

Types

type ApiGroup

type ApiGroup string

func (ApiGroup) LessThan

func (g ApiGroup) LessThan(other ApiGroup) bool

func (ApiGroup) String

func (g ApiGroup) String() string

type ApiGroups

type ApiGroups []ApiGroup

func (ApiGroups) Len

func (a ApiGroups) Len() int

func (ApiGroups) Less

func (a ApiGroups) Less(i, j int) bool

func (ApiGroups) Swap

func (a ApiGroups) Swap(i, j int)

type ApiKind

type ApiKind string

func (ApiKind) String

func (k ApiKind) String() string

type ApiVersion

type ApiVersion string

func (ApiVersion) LessThan

func (ver ApiVersion) LessThan(that ApiVersion) bool

func (ApiVersion) String

func (a ApiVersion) String() string

type ApiVersions

type ApiVersions []ApiVersion

func (ApiVersions) Len

func (a ApiVersions) Len() int

func (ApiVersions) Less

func (a ApiVersions) Less(i, j int) bool

func (ApiVersions) Swap

func (a ApiVersions) Swap(i, j int)

type Config

type Config struct {
	ApiGroups           []ApiGroup          `yaml:"api_groups,omitempty"`
	ExampleLocation     string              `yaml:"example_location,omitempty"`
	OperationCategories []OperationCategory `yaml:"operation_categories,omitempty"`
	ResourceCategories  []ResourceCategory  `yaml:"resource_categories,omitempty"`
	ExcludedOperations  []string            `yaml:"excluded_operations,omitempty"`

	// Used to map the group as the resource sees it to the group as the operation sees it
	OperationGroupMap map[string]string `yaml:"operation_group_map,omitempty"`

	GroupFullNames map[string]string `yaml:"group_full_names,omitempty"`

	Definitions Definitions
	Operations  Operations
	SpecTitle   string
	SpecVersion string
}

func LoadConfigFromYAML

func LoadConfigFromYAML() (*Config, error)

LoadConfigFromYAML reads the config yaml file into a struct

func NewConfig

func NewConfig() (*Config, error)

func (*Config) CleanUp

func (c *Config) CleanUp()

CleanUp sorts and dedups fields

func (*Config) OpExcluded

func (c *Config) OpExcluded(op string) bool

type CurlExample

type CurlExample struct{}

func (CurlExample) GetRequest

func (ce CurlExample) GetRequest(o *Operation) string

func (CurlExample) GetRequestMessage

func (ce CurlExample) GetRequestMessage() string

func (CurlExample) GetRequestType

func (ce CurlExample) GetRequestType() string

func (CurlExample) GetResponse

func (ce CurlExample) GetResponse(o *Operation) string

func (CurlExample) GetResponseMessage

func (ce CurlExample) GetResponseMessage() string

func (CurlExample) GetResponseType

func (ce CurlExample) GetResponseType() string

func (CurlExample) GetSample

func (ce CurlExample) GetSample(d *Definition) string

func (CurlExample) GetSampleType

func (ce CurlExample) GetSampleType() string

func (CurlExample) GetTab

func (ce CurlExample) GetTab() string

type Definition

type Definition struct {

	// Display name of the definition (e.g. Deployment)
	Name      string
	Group     ApiGroup
	ShowGroup bool

	// Api version of the definition (e.g. v1beta1)
	Version                 ApiVersion
	Kind                    ApiKind
	DescriptionWithEntities string
	GroupFullName           string

	// InToc is true if this definition should appear in the table of contents
	InToc        bool
	IsInlined    bool
	IsOldVersion bool

	FoundInField     bool
	FoundInOperation bool

	// Inline is a list of definitions that should appear inlined with this one in the documentations
	Inline SortDefinitionsByName

	// AppearsIn is a list of definition that this one appears in - e.g. PodSpec in Pod
	AppearsIn SortDefinitionsByName

	OperationCategories []*OperationCategory

	// Fields is a list of fields in this definition
	Fields Fields

	OtherVersions SortDefinitionsByName
	NewerVersions SortDefinitionsByName

	Sample SampleConfig

	FullName string
	Resource string

	// SwaggerKey is the raw, domain-reversed key under which this
	// definition appeared in the OpenAPI spec — e.g.
	// "io.k8s.api.apps.v1.Deployment". Preserved so downstream writers
	// can derive artefacts like Go import paths without re-parsing.
	SwaggerKey string
	// contains filtered or unexported fields
}

func (*Definition) Description

func (d *Definition) Description() string
func (d *Definition) FullHrefLink() string

func (*Definition) GetResourceName

func (d *Definition) GetResourceName() string

func (*Definition) GetSamples

func (d *Definition) GetSamples() []ExampleText

func (*Definition) GoImportPath

func (d *Definition) GoImportPath() string

GoImportPath returns the Go import path this definition's type lives at, derived from the swagger key. Returns "" when the key was not preserved (e.g. old specs parsed before SwaggerKey existed).

The swagger key is a domain-reversed, dotted identifier such as "io.k8s.api.apps.v1.Deployment". The transform swaps the first two segments into a slash-joined hostname ("io.k8s" -> "k8s.io") and joins the middle segments as path components, dropping the trailing kind. For the example above, the result is "k8s.io/api/apps/v1".

func (*Definition) GroupDisplayName

func (d *Definition) GroupDisplayName() string
func (d *Definition) HrefLink() string

func (*Definition) IsTopLevelResource

func (d *Definition) IsTopLevelResource() bool

IsTopLevelResource returns true if this definition represents a top-level API resource (one that has its own List endpoint), as opposed to a subresource (Scale, Eviction) or utility type (Status, WatchEvent).

func (*Definition) Key

func (d *Definition) Key() string

func (*Definition) LinkID

func (d *Definition) LinkID() string
func (d *Definition) MdLink() string

func (*Definition) RequiredFields

func (d *Definition) RequiredFields() []string

RequiredFields returns the names of required properties on this definition, sourced from the underlying OpenAPI schema. Used by writers that need to flag required fields on a per-name basis.

func (d *Definition) VersionLink() string

type DefinitionList

type DefinitionList []*Definition

func (DefinitionList) Len

func (a DefinitionList) Len() int

func (DefinitionList) Less

func (a DefinitionList) Less(i, j int) bool

func (DefinitionList) Swap

func (a DefinitionList) Swap(i, j int)

type Definitions

type Definitions struct {
	All           map[string]*Definition
	ByKind        map[byKindKey]SortDefinitionsByVersion
	GroupVersions GroupVersions
}

Definitions indexes open-api definitions

func NewDefinitions

func NewDefinitions(config *Config, specs []*loads.Document) (*Definitions, error)

func (*Definitions) FindNewestVersion

func (s *Definitions) FindNewestVersion(group, kind string) string

FindNewestVersion returns the newest known version for the given group/kind. Returns an empty string if no matching definition is found.

func (*Definitions) GetByVersionKind

func (s *Definitions) GetByVersionKind(group, version, kind string) (*Definition, bool)

GetByVersionKind looks up a definition using its primary key (version,kind)

func (*Definitions) GetForSchema

func (s *Definitions) GetForSchema(schema spec.Schema) (*Definition, bool)

func (*Definitions) InitializeFields

func (s *Definitions) InitializeFields(d *Definition)

Initializes the fields for a definition

type EmptyExample

type EmptyExample struct{}

func (EmptyExample) GetRequest

func (ce EmptyExample) GetRequest(o *Operation) string

func (EmptyExample) GetRequestMessage

func (ce EmptyExample) GetRequestMessage() string

func (EmptyExample) GetRequestType

func (ce EmptyExample) GetRequestType() string

func (EmptyExample) GetResponse

func (ce EmptyExample) GetResponse(o *Operation) string

func (EmptyExample) GetResponseMessage

func (ce EmptyExample) GetResponseMessage() string

func (EmptyExample) GetResponseType

func (ce EmptyExample) GetResponseType() string

func (EmptyExample) GetSample

func (ce EmptyExample) GetSample(d *Definition) string

func (EmptyExample) GetSampleType

func (ce EmptyExample) GetSampleType() string

func (EmptyExample) GetTab

func (ce EmptyExample) GetTab() string

type ExampleConfig

type ExampleConfig struct {
	Name         string `yaml:",omitempty"`
	Namespace    string `yaml:",omitempty"`
	Request      string `yaml:",omitempty"`
	Response     string `yaml:",omitempty"`
	RequestNote  string `yaml:",omitempty"`
	ResponseNote string `yaml:",omitempty"`
}

type ExampleProvider

type ExampleProvider interface {
	GetTab() string
	GetRequestMessage() string
	GetResponseMessage() string
	GetRequestType() string
	GetResponseType() string
	GetSampleType() string
	GetSample(d *Definition) string
	GetRequest(o *Operation) string
	GetResponse(o *Operation) string
}

func GetExampleProviders

func GetExampleProviders() []ExampleProvider

type ExampleText

type ExampleText struct {
	Tab  string
	Type string
	Text string
	Msg  string
}

type Field

type Field struct {
	Name                    string
	Type                    string
	Description             string
	DescriptionWithEntities string

	Definition *Definition // Optional Definition for complex types

	PatchStrategy string
	PatchMergeKey string
}
func (f Field) FullLink() string
func (f Field) Link() string

type Fields

type Fields []*Field

func (Fields) Len

func (a Fields) Len() int

func (Fields) Less

func (a Fields) Less(i, j int) bool

func (Fields) Swap

func (a Fields) Swap(i, j int)

type GroupVersions

type GroupVersions map[string]ApiVersions

type HttpResponse

type HttpResponse struct {
	Field
	Code string
}

type HttpResponses

type HttpResponses []*HttpResponse

func (HttpResponses) Len

func (a HttpResponses) Len() int

func (HttpResponses) Less

func (a HttpResponses) Less(i, j int) bool

func (HttpResponses) Swap

func (a HttpResponses) Swap(i, j int)

type KubectlExample

type KubectlExample struct{}

func (KubectlExample) GetRequest

func (ke KubectlExample) GetRequest(o *Operation) string

func (KubectlExample) GetRequestMessage

func (ke KubectlExample) GetRequestMessage() string

func (KubectlExample) GetRequestType

func (ke KubectlExample) GetRequestType() string

func (KubectlExample) GetResponse

func (ke KubectlExample) GetResponse(o *Operation) string

func (KubectlExample) GetResponseMessage

func (ke KubectlExample) GetResponseMessage() string

func (KubectlExample) GetResponseType

func (ke KubectlExample) GetResponseType() string

func (KubectlExample) GetSample

func (ke KubectlExample) GetSample(d *Definition) string

func (KubectlExample) GetSampleType

func (ke KubectlExample) GetSampleType() string

func (KubectlExample) GetTab

func (ke KubectlExample) GetTab() string

type Operation

type Operation struct {
	ID            string
	Type          OperationType
	Path          string
	HttpMethod    string
	Definition    *Definition
	BodyParams    Fields
	QueryParams   Fields
	PathParams    Fields
	HttpResponses HttpResponses

	ExampleConfig ExampleConfig
	// contains filtered or unexported fields
}

func (*Operation) Description

func (o *Operation) Description() string

func (*Operation) GetDisplayHttp

func (o *Operation) GetDisplayHttp() string

func (*Operation) GetExampleRequests

func (o *Operation) GetExampleRequests() []ExampleText

func (*Operation) GetExampleResponses

func (o *Operation) GetExampleResponses() []ExampleText

func (*Operation) GetGroupVersionKindSub

func (o *Operation) GetGroupVersionKindSub() (string, string, string, string)

func (*Operation) GetMethod

func (o *Operation) GetMethod() string

type OperationCategory

type OperationCategory struct {
	// Name is the display name of this group
	Name string `yaml:",omitempty"`
	// Operations are the collection of Operations in this group
	OperationTypes []OperationType `yaml:"operation_types,omitempty"`
	// Default is true if this is the default operation group for operations that do not match any other groups
	Default bool `yaml:",omitempty"`

	Operations []*Operation
}

OperationCategory defines a group of related operations

type OperationType

type OperationType struct {
	// Name is the display name of this operation
	Name string `yaml:",omitempty"`
	// Match is the regular expression of operation IDs that match this group where '${resource}' matches the resource name.
	Match string `yaml:",omitempty"`
}

Operation defines a highlevel operation type such as Read, Replace, Patch

func (OperationType) GetOperationId

func (ot OperationType) GetOperationId(d string) string

GetOperationId returns the ID of the operation for the given definition

type Operations

type Operations map[string]*Operation

type Resource

type Resource struct {
	// Name is the display name of this Resource
	Name    string `yaml:",omitempty"`
	Version string `yaml:",omitempty"`
	Group   string `yaml:",omitempty"`

	// DescriptionWarning is a warning message to show along side this resource when displaying it
	DescriptionWarning string `yaml:"description_warning,omitempty"`
	// DescriptionNote is a note message to show along side this resource when displaying it
	DescriptionNote string `yaml:"description_note,omitempty"`
	// ConceptGuide is a link to the concept guide for this resource if it exists
	ConceptGuide string `yaml:"concept_guide,omitempty"`
	// RelatedTasks is as list of tasks related to this concept
	RelatedTasks []string `yaml:"related_tasks,omitempty"`

	// Definition of the object
	Definition *Definition
}

type ResourceCategory

type ResourceCategory struct {
	// Name is the display name of this group
	Name string `yaml:",omitempty"`
	// Include is the name of the _<resource_category>.html file to include in the index.html
	Include string `yaml:",omitempty"`
	// Resources are the collection of Resources in this group
	Resources Resources `yaml:",omitempty"`
}

ResourceCategory defines a category of Concepts

type ResourceVisitor

type ResourceVisitor func(resource *Resource, d *Definition)

type Resources

type Resources []*Resource

type SampleConfig

type SampleConfig struct {
	Note   string `yaml:",omitempty"`
	Sample string `yaml:",omitempty"`
}

type SortDefinitionsByName

type SortDefinitionsByName []*Definition

func (SortDefinitionsByName) Len

func (a SortDefinitionsByName) Len() int

func (SortDefinitionsByName) Less

func (a SortDefinitionsByName) Less(i, j int) bool

func (SortDefinitionsByName) Swap

func (a SortDefinitionsByName) Swap(i, j int)

type SortDefinitionsByVersion

type SortDefinitionsByVersion []*Definition

func (SortDefinitionsByVersion) Len

func (a SortDefinitionsByVersion) Len() int

func (SortDefinitionsByVersion) Less

func (a SortDefinitionsByVersion) Less(i, j int) bool

func (SortDefinitionsByVersion) Swap

func (a SortDefinitionsByVersion) Swap(i, j int)

Jump to

Keyboard shortcuts

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