mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 09:51:23 +00:00
Library for getting Resource and field Schema from OpenAPI
This commit is contained in:
87
kyaml/openapi/example_test.go
Normal file
87
kyaml/openapi/example_test.go
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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]
|
||||
}
|
||||
Reference in New Issue
Block a user