// substituteUtil recursively parses nested substitutions in ext and sets the setter value
// returns error if cyclic substitution is detected or any other unexpected errors
substituteUtil recursively parses nested substitutions in ext and sets the setter value
returns error if cyclic substitution is detected or any other unexpected errors
// substituteUtil recursively parses nested substitutions in ext and sets the setter value // returns error if cyclic substitution is detected or any other unexpected errors
func (s *Set) substituteUtil(ext *CliExtension, visited sets.String, nameMatch *bool) (string, error) {
	if visited.Has(ext.Substitution.Name) {
		return "", errors.Errorf(
			"cyclic substitution detected with name " + ext.Substitution.Name)
	}
	visited.Insert(ext.Substitution.Name)
	pattern := ext.Substitution.Pattern
	for _, v := range ext.Substitution.Values {
		if v.Ref == "" {
			return "", errors.Errorf(
				"missing reference on substitution " + ext.Substitution.Name)
		}
		ref, err := spec.NewRef(v.Ref)
		if err != nil {
			return "", errors.Wrap(err)
		}
		def, err := openapi.Resolve(&ref, s.SettersSchema) 
		if err != nil {
			return "", errors.Wrap(err)
		}
		defExt, err := GetExtFromSchema(def) 
		if err != nil {
			return "", errors.Wrap(err)
		}
		if defExt.Substitution != nil {
			substVal, err := s.substituteUtil(defExt, visited, nameMatch)
			if err != nil {
				return "", err
			}
			pattern = strings.ReplaceAll(pattern, v.Marker, substVal)
			continue
		}
		if err := validateAgainstSchema(defExt, def); err != nil {
			return "", err
		}
		if s.isMatch(defExt.Setter.Name) {
			*nameMatch = true
		}
		if val, found := defExt.Setter.EnumValues[defExt.Setter.Value]; found {
			pattern = strings.ReplaceAll(pattern, v.Marker, val)
		} else {
			pattern = strings.ReplaceAll(pattern, v.Marker, defExt.Setter.Value)
		}
	}
	return pattern, nil
}
func ( s * Set ) substituteUtil ( ext * CliExtension , visited sets . String , nameMatch * bool ) ( string , error ) { if visited . Has ( ext . Substitution . Name ) { return " " , errors . Errorf ( " " + ext . Substitution . Name ) } visited . Insert ( ext . Substitution . Name ) pattern := ext . Substitution . Pattern for _ , v := range ext . Substitution . Values { if v . Ref == " " { return " " , errors . Errorf ( " " + ext . Substitution . Name ) } ref , err := spec . NewRef ( v . Ref ) if err != nil { return " " , errors . Wrap ( err ) } def , err := openapi . Resolve ( & ref , s . SettersSchema ) if err != nil { return " " , errors . Wrap ( err ) } defExt , err := GetExtFromSchema ( def ) if err != nil { return " " , errors . Wrap ( err ) } if defExt . Substitution != nil { substVal , err := s . substituteUtil ( defExt , visited , nameMatch ) if err != nil { return " " , err } pattern = strings . ReplaceAll ( pattern , v . Marker , substVal ) continue } if err := validateAgainstSchema ( defExt , def ) ; err != nil { return " " , err } if s . isMatch ( defExt . Setter . Name ) { * nameMatch = true } if val , found := defExt . Setter . EnumValues [ defExt . Setter . Value ] ; found { pattern = strings . ReplaceAll ( pattern , v . Marker , val ) } else { pattern = strings . ReplaceAll ( pattern , v . Marker , defExt . Setter . Value ) } } return pattern , nil }
substituteUtil recursively parses nested substitutions in ext and sets the setter value
returns error if cyclic substitution is detected or any other unexpected errors
substituteUtil recursively parses nested substitutions in ext and sets the setter value returns error if cyclic substitution is detected or any other unexpected errors
// check if the substitution has already been visited and throw error as cycles // are not allowed in nested substitutions // substitute each setter into the pattern to get the new value // if substitution references to another substitution, recursively // process the nested substitutions to replace the pattern with setter values // resolve the def to its openAPI def // parse the extension out of the openAPI // parse recursively if it reference is substitution // if code reaches this point, this is a setter, so validate the setter schema // the substitution depends on the specified setter // the setter has an enum-map.  we should replace the marker with the // enum value looked up from the map rather than the enum key