Files
kustomize/kyaml/openapi/example_test.go
2020-01-08 10:47:11 -08:00

88 lines
2.4 KiB
Go

// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package openapi_test
import (
"fmt"
"sigs.k8s.io/kustomize/kyaml/openapi"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func Example() {
s := openapi.SchemaForResourceType(yaml.TypeMeta{APIVersion: "apps/v1", Kind: "Deployment"})
f := s.SchemaForField("spec").
SchemaForField("replicas")
fmt.Println(f.Schema.Description[:70] + "...")
fmt.Println(f.Schema.Type)
// Output:
// Number of desired pods. This is a pointer to distinguish between expli...
// [integer]
}
func Example_arrayMerge() {
s := openapi.SchemaForResourceType(yaml.TypeMeta{APIVersion: "apps/v1", Kind: "Deployment"})
f := s.SchemaForField("spec").
SchemaForField("template").
SchemaForField("spec").
SchemaForField("containers")
fmt.Println(f.Schema.Description[:70] + "...")
fmt.Println(f.Schema.Type)
fmt.Println(f.PatchStrategyAndKey()) // merge patch strategy on name
// Output:
// List of containers belonging to the pod. Containers cannot currently b...
// [array]
// merge name
}
func Example_arrayReplace() {
s := openapi.SchemaForResourceType(yaml.TypeMeta{APIVersion: "apps/v1", Kind: "Deployment"})
f := s.SchemaForField("spec").
SchemaForField("template").
SchemaForField("spec").
SchemaForField("containers").SchemaForElements().
SchemaForField("args")
fmt.Println(f.Schema.Description[:70] + "...")
fmt.Println(f.Schema.Type)
fmt.Println(f.PatchStrategyAndKey()) // no patch strategy or merge key
// Output:
// Arguments to the entrypoint. The docker image's CMD is used if this is...
// [array]
}
func Example_arrayElement() {
s := openapi.SchemaForResourceType(yaml.TypeMeta{APIVersion: "apps/v1", Kind: "Deployment"})
f := s.SchemaForField("spec").
SchemaForField("template").
SchemaForField("spec").
SchemaForField("containers").SchemaForElements().
SchemaForField("ports").SchemaForElements().
SchemaForField("containerPort")
fmt.Println(f.Schema.Description[:70] + "...")
fmt.Println(f.Schema.Type)
// Output:
// Number of port to expose on the pod's IP address. This must be a valid...
// [integer]
}
func Example_map() {
s := openapi.SchemaForResourceType(yaml.TypeMeta{APIVersion: "apps/v1", Kind: "Deployment"})
f := s.SchemaForField("metadata").SchemaForField("labels")
fmt.Println(f.Schema.Description[:70] + "...")
fmt.Println(f.Schema.Type)
// Output:
// Map of string keys and values that can be used to organize and categor...
// [object]
}