Setters: support for explicit setter typing

- ensure OpenAPI definitions always uses strings for setter values
- allow the field type to be defined -- integer,boolean,string
- format values using yaml 1.1 compatibility
This commit is contained in:
Phillip Wittrock
2020-02-27 11:49:59 -08:00
parent da548f65ea
commit fa507f782f
6 changed files with 167 additions and 21 deletions

View File

@@ -105,6 +105,9 @@ type SetterDefinition struct {
// Count is the number of fields set by this setter.
Count int `yaml:"count,omitempty"`
// Type is the type of the setter value.
Type string `yaml:"type,omitempty"`
// EnumValues is a map of possible setter values to actual field values.
// If EnumValues is specified, then the value set the by user 1) MUST
// be present in the enumValues map as a key, and 2) the map entry value
@@ -135,6 +138,15 @@ func (sd SetterDefinition) Filter(object *yaml.RNode) (*yaml.RNode, error) {
sd.Description = ""
}
if sd.Type != "" {
err = def.PipeE(yaml.FieldSetter{Name: "type", StringValue: sd.Type})
if err != nil {
return nil, err
}
// don't write the type to the extension
sd.Type = ""
}
ext, err := def.Pipe(yaml.LookupCreate(yaml.MappingNode, K8sCliExtensionKey))
if err != nil {
return nil, err