diff --git a/internal/controllers/clustertemplate_controller.go b/internal/controllers/clustertemplate_controller.go index 1618d0d6..fb39c89d 100644 --- a/internal/controllers/clustertemplate_controller.go +++ b/internal/controllers/clustertemplate_controller.go @@ -369,7 +369,7 @@ func validateTemplateParameterSchema(object *provisioningv1alpha1.ClusterTemplat expectedType := param[1] aSubschema, err := utils.ExtractSubSchema(object.Spec.TemplateParameterSchema.Raw, expectedName) if err != nil { - if strings.HasPrefix(err.Error(), fmt.Sprintf("subSchema %s does not exist:", expectedName)) { + if strings.HasPrefix(err.Error(), fmt.Sprintf("subSchema '%s' does not exist:", expectedName)) { missingParameter = append(missingParameter, expectedName) continue } else { diff --git a/internal/controllers/utils/utils.go b/internal/controllers/utils/utils.go index bc9646ab..924b1387 100644 --- a/internal/controllers/utils/utils.go +++ b/internal/controllers/utils/utils.go @@ -1243,37 +1243,37 @@ func ExtractSubSchema(mainSchema []byte, subSchemaKey string) (subSchema map[str return subSchema, fmt.Errorf("failed to UnMarshall Main Schema: %w", err) } if _, ok := jsonObject[PropertiesString]; !ok { - return subSchema, fmt.Errorf("non compliant Main Schema, missing properties: %w", err) + return subSchema, fmt.Errorf("non compliant Main Schema, missing 'properties' section: %w", err) } properties, ok := jsonObject[PropertiesString].(map[string]any) if !ok { - return subSchema, fmt.Errorf("could not cast properties as map[string]any: %w", err) + return subSchema, fmt.Errorf("could not cast 'properties' section of schema as map[string]any: %w", err) } subSchemaValue, ok := properties[subSchemaKey] if !ok { - return subSchema, fmt.Errorf("subSchema %s does not exist: %w", subSchemaKey, err) + return subSchema, fmt.Errorf("subSchema '%s' does not exist: %w", subSchemaKey, err) } subSchema, ok = subSchemaValue.(map[string]any) if !ok { - return subSchema, fmt.Errorf("subSchema %s is not a valid map: %w", subSchemaKey, err) + return subSchema, fmt.Errorf("subSchema '%s' is not a valid map: %w", subSchemaKey, err) } return subSchema, nil } // ExtractMatchingInput extracts the portion of the input data that corresponds to a given subSchema key. -func ExtractMatchingInput(input []byte, subSchemaKey string) (any, error) { +func ExtractMatchingInput(parentSchema []byte, subSchemaKey string) (any, error) { inputData := make(map[string]any) - err := json.Unmarshal(input, &inputData) + err := json.Unmarshal(parentSchema, &inputData) if err != nil { - return nil, fmt.Errorf("failed to unmarshal input: %w", err) + return nil, fmt.Errorf("failed to unmarshal parent schema: %w", err) } // Check if the input contains the subSchema key matchingInput, ok := inputData[subSchemaKey] if !ok { - return nil, fmt.Errorf("input does not contain key %s: %w", subSchemaKey, err) + return nil, fmt.Errorf("parent schema does not contain key '%s': %w", subSchemaKey, err) } return matchingInput, nil } @@ -1282,16 +1282,16 @@ func ExtractMatchingInput(input []byte, subSchemaKey string) (any, error) { func ExtractSchemaRequired(mainSchema []byte) (required []string, err error) { requireListAny, err := ExtractMatchingInput(mainSchema, requiredString) if err != nil { - return required, fmt.Errorf("could not extract required fields: %w", err) + return required, fmt.Errorf("could not extract the 'required' section of schema: %w", err) } requiredAny, ok := requireListAny.([]any) if !ok { - return required, fmt.Errorf("could not cast required as []any") + return required, fmt.Errorf("could not cast 'required' section as []any") } for _, item := range requiredAny { itemString, ok := item.(string) if !ok { - return required, fmt.Errorf("could not cast []any item as string") + return required, fmt.Errorf(`could not cast 'required' section item as a string`) } required = append(required, itemString) }