1
0
mirror of https://github.com/rancher/steve.git synced 2025-06-04 12:50:12 +00:00
steve/pkg/schema/definitions/schema.go
Michael Bolot 40f6b10fc7 Adding schema definitions endpoint
Introduces new schema definitions endpoint, allowing the caller to get
the fields/types/descriptions for a given kubernetes resource.
2024-02-26 15:42:03 -06:00

52 lines
1.4 KiB
Go

package definitions
import (
"time"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/wrangler/v2/pkg/schemas"
"k8s.io/client-go/discovery"
)
const (
gvkExtensionName = "x-kubernetes-group-version-kind"
gvkExtensionGroup = "group"
gvkExtensionVersion = "version"
gvkExtensionKind = "kind"
defaultDuration = time.Second * 5
)
// Register registers the schemaDefinition schema.
func Register(baseSchema *types.APISchemas, client discovery.DiscoveryInterface) {
handler := schemaDefinitionHandler{
client: client,
refreshStale: defaultDuration,
}
baseSchema.MustAddSchema(types.APISchema{
Schema: &schemas.Schema{
ID: "schemaDefinition",
PluralName: "schemaDefinitions",
ResourceMethods: []string{"GET"},
},
ByIDHandler: handler.byIDHandler,
})
}
type schemaDefinition struct {
DefinitionType string `json:"definitionType"`
Definitions map[string]definition `json:"definitions"`
}
type definition struct {
ResourceFields map[string]definitionField `json:"resourceFields"`
Type string `json:"type"`
Description string `json:"description"`
}
type definitionField struct {
Type string `json:"type"`
SubType string `json:"subtype,omitempty"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}