Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .wsignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.codegen/_openapi_sha
.release_metadata.json
bundle/schema/jsonschema.json
bundle/schema/jsonschema_ref_only.json
python/docs/images/databricks-logo.svg
**/*.dist-info/METADATA
**/*.dist-info/WHEEL
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ snapshot-release:
schema:
go run ./bundle/internal/schema ./bundle/internal/schema ./bundle/schema/jsonschema.json

schema-ref-only:
go run ./bundle/internal/schema ./bundle/internal/schema ./bundle/schema/jsonschema_ref_only.json --skip-interpolation-pattern

docs:
go run ./bundle/docsgen ./bundle/internal/schema ./bundle/docsgen

Expand Down
22 changes: 14 additions & 8 deletions bundle/internal/schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func removeOutputOnlyFields(typ reflect.Type, s jsonschema.Schema) jsonschema.Sc
}

func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: go run main.go <work-dir> <output-file>")
if len(os.Args) < 3 {
fmt.Println("Usage: go run main.go <work-dir> <output-file> [--skip-interpolation-pattern]")
os.Exit(1)
}

Expand All @@ -193,10 +193,12 @@ func main() {
// Output file, where the generated JSON schema will be written to.
outputFile := os.Args[2]

generateSchema(workdir, outputFile)
skipInterpolationPattern := len(os.Args) >= 4 && os.Args[3] == "--skip-interpolation-pattern"

generateSchema(workdir, outputFile, skipInterpolationPattern)
}

func generateSchema(workdir, outputFile string) {
func generateSchema(workdir, outputFile string, skipInterpolationPattern bool) {
annotationsPath := filepath.Join(workdir, "annotations.yml")
annotationsOpenApiPath := filepath.Join(workdir, "annotations_openapi.yml")
annotationsOpenApiOverridesPath := filepath.Join(workdir, "annotations_openapi_overrides.yml")
Expand All @@ -220,15 +222,19 @@ func generateSchema(workdir, outputFile string) {
log.Fatal(err)
}

// Generate the JSON schema from the bundle Go struct.
s, err := jsonschema.FromType(reflect.TypeOf(config.Root{}), []func(reflect.Type, jsonschema.Schema) jsonschema.Schema{
transforms := []func(reflect.Type, jsonschema.Schema) jsonschema.Schema{
removeJobsFields,
removePipelineFields,
makeVolumeTypeOptional,
a.addAnnotations,
removeOutputOnlyFields,
addInterpolationPatterns,
})
}
if !skipInterpolationPattern {
transforms = append(transforms, addInterpolationPatterns)
}

// Generate the JSON schema from the bundle Go struct.
s, err := jsonschema.FromType(reflect.TypeOf(config.Root{}), transforms)

// AdditionalProperties is set to an empty schema to allow non-typed keys used as yaml-anchors
// Example:
Expand Down
2 changes: 1 addition & 1 deletion bundle/internal/schema/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestRequiredAnnotationsForNewFields(t *testing.T) {
err = copyFile("annotations_openapi_overrides.yml", annotationsOpenApiOverridesPath)
assert.NoError(t, err)

generateSchema(workdir, path.Join(t.TempDir(), "schema.json"))
generateSchema(workdir, path.Join(t.TempDir(), "schema.json"), false)

originalFile, err := os.ReadFile("annotations.yml")
assert.NoError(t, err)
Expand Down
Loading