Skip to content

Commit 5c37370

Browse files
committed
fix: Move function to bottom and add test
1 parent b20a1dc commit 5c37370

2 files changed

Lines changed: 61 additions & 12 deletions

File tree

internal/pkg/encoding/json/schema/schema.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ import (
2020
// pseudoSchemaFile - the validated schema is registered as this resource.
2121
const pseudoSchemaFile = "file:///schema.json"
2222

23-
// skipSchemaValidation returns true for components where schema validation should be skipped.
24-
func skipSchemaValidation(componentID keboola.ComponentID) bool {
25-
switch componentID {
26-
case "keboola.python-transformation-v2",
27-
"keboola.snowflake-transformation",
28-
"keboola.google-bigquery-transformation":
29-
return true
30-
default:
31-
return false
32-
}
33-
}
34-
3523
func ValidateObjects(ctx context.Context, logger log.Logger, objects model.ObjectStates) error {
3624
errs := errors.NewMultiError()
3725
for _, config := range objects.Configs() {
@@ -269,3 +257,15 @@ func compileSchema(s []byte, savePropertyOrder bool) (*jsonschema.Schema, error)
269257

270258
return schema, nil
271259
}
260+
261+
// skipSchemaValidation returns true for components where schema validation should be skipped.
262+
func skipSchemaValidation(componentID keboola.ComponentID) bool {
263+
switch componentID {
264+
case "keboola.python-transformation-v2",
265+
"keboola.snowflake-transformation",
266+
"keboola.google-bigquery-transformation":
267+
return true
268+
default:
269+
return false
270+
}
271+
}

internal/pkg/encoding/json/schema/schema_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,55 @@ func testInvalidComponentSchema(t *testing.T, invalidSchema []byte, expectedLogs
384384
assert.Equal(t, strings.TrimLeft(expectedLogs, "\n"), logger.AllMessagesTxt())
385385
}
386386

387+
func TestValidateConfig_SkipTransformationComponents(t *testing.T) {
388+
t.Parallel()
389+
390+
// Schema that requires "firstName" field
391+
schema := getTestSchema()
392+
393+
// Content that violates the schema (missing required "firstName")
394+
invalidContent := orderedmap.FromPairs([]orderedmap.Pair{
395+
{
396+
Key: "parameters",
397+
Value: orderedmap.FromPairs([]orderedmap.Pair{
398+
{Key: "lastName", Value: "Brown"},
399+
}),
400+
},
401+
})
402+
403+
// Test that validation is skipped for transformation components
404+
transformationComponents := []keboola.ComponentID{
405+
"keboola.python-transformation-v2",
406+
"keboola.snowflake-transformation",
407+
"keboola.google-bigquery-transformation",
408+
}
409+
410+
for _, componentID := range transformationComponents {
411+
component := &keboola.Component{
412+
ComponentKey: keboola.ComponentKey{ID: componentID},
413+
Type: "transformation",
414+
Name: "Test Transformation",
415+
Schema: schema,
416+
}
417+
config := &model.Config{Content: invalidContent}
418+
419+
// Should return nil because validation is skipped for transformation components
420+
err := ValidateConfig(component, config)
421+
require.NoError(t, err, "validation should be skipped for component %s", componentID)
422+
}
423+
424+
// Verify that a regular component still gets validated
425+
regularComponent := &keboola.Component{
426+
ComponentKey: keboola.ComponentKey{ID: "keboola.ex-generic"},
427+
Type: "extractor",
428+
Name: "Generic Extractor",
429+
Schema: schema,
430+
}
431+
config := &model.Config{Content: invalidContent}
432+
err := ValidateConfig(regularComponent, config)
433+
require.Error(t, err, "validation should NOT be skipped for regular component")
434+
}
435+
387436
func TestNormalizeSchema_RequiredTrue(t *testing.T) {
388437
t.Parallel()
389438

0 commit comments

Comments
 (0)