Skip to content

Commit 535a8ef

Browse files
Remove duplicate enum values for jsonschema.json (databricks#5839)
## Summary `catalog.SseEncryptionDetailsAlgorithm` published a duplicated `enum` in the generated bundle JSON schema: ```json "enum": ["AWS_SSE_S3", "AWS_SSE_KMS", "AWS_SSE_KMS", "AWS_SSE_S3"] ``` JSON Schema requires enum values to be unique, so strict validators (e.g. OPA) reject the entire schema at compile time. The duplicate has shipped since v0.290.0 (Feb 26 2026); the issue reports it "since v0.299.1" only because that is the first release where `jsonschema.json` was published as a downloadable release asset, so it is the earliest version an external consumer could inspect. Fixes databricks#5713. ## Root cause The enum was **hand-authored** for `catalog.SseEncryptionDetailsAlgorithm` in databricks#4484 (UC external locations, Feb 18 2026), in the hand-authored override annotation file, with order `[AWS_SSE_KMS, AWS_SSE_S3]`. At that point the SDK-derived annotations did not define this type, so the generated schema had the correct **2** entries. Two days later, databricks#4552 (Upgrade Go SDK to v0.110.0, Feb 20 2026) regenerated the SDK-derived annotation file, which now defined the same enum with order `[AWS_SSE_S3, AWS_SSE_KMS]`. From then on **both** annotation sources supplied the enum. The annotation merge concatenates sequences, so the two pairs combined into four entries — `[S3, KMS]` (SDK, merge base) followed by `[KMS, S3]` (override), producing `[S3, KMS, KMS, S3]`. The later consolidation of the annotation files into a single `annotations.yml` + `.codegen/cli.json` (databricks#5484 / databricks#5574) preserved this pre-existing duplicate rather than causing it; only the file names changed. `annotations.yml` is **not** generated from `cli.json` — `./task generate-schema` only syncs descriptions and placeholders and drops stale entries; it never rewrites hand-authored enums. So the redundant entry persisted silently across the refactor. ## Fix - Remove the redundant hand-authored `enum` from `annotations.yml`, leaving `cli.json` (SDK-derived) as the single source of truth. The `description` override there is intentional (it differs from cli.json's text) and is kept. - Regenerate `bundle/schema/jsonschema.json`; the enum is now `["AWS_SSE_S3", "AWS_SSE_KMS"]`. - Add `TestJsonSchemaEnumsAreUnique`, a whole-schema guard that walks every `enum` in the embedded schema and fails on any duplicate, so this class of bug cannot return regardless of source. ## Tests - `go test ./bundle/internal/schema ./bundle/schema -count=1` - Verified the new guard fails on the pre-fix schema, reporting the exact path `$defs/.../catalog.SseEncryptionDetailsAlgorithm/oneOf[0]`. - Confirmed the regenerated schema is reproducible via the schema generator. This pull request and its description were written by Isaac, an AI coding agent.
1 parent 353cb5a commit 535a8ef

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Bundles
1212

1313
* Fix permissions added to a job or pipeline by a Python (PyDABs) mutator failing to deploy with "must have exactly one owner"; the deploying identity is now set as owner, matching resources whose permissions are declared in YAML ([#5821](https://github.com/databricks/cli/pull/5821)).
14+
* Remove duplicate enum values for jsonschema.json ([#5839](https://github.com/databricks/cli/pull/5839)).
1415

1516
### Dependency updates
1617

bundle/internal/schema/annotations.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,6 @@ resources:
847847
"$type":
848848
"description": |-
849849
SSE algorithm to use for encrypting S3 objects
850-
"enum":
851-
- |-
852-
AWS_SSE_KMS
853-
- |-
854-
AWS_SSE_S3
855850
"grants":
856851
"description": |-
857852
The Unity Catalog privileges to grant to principals on this securable.

bundle/schema/embed_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema_test
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"testing"
67

78
"github.com/databricks/cli/bundle/schema"
@@ -64,3 +65,44 @@ func TestJsonSchema(t *testing.T) {
6465
assert.Contains(t, providers.OneOf[0].Enum, "gitHubEnterprise")
6566
assert.Contains(t, providers.OneOf[0].Enum, "bitbucketServer")
6667
}
68+
69+
// JSON Schema requires enum values to be unique; strict validators (e.g. OPA)
70+
// reject the whole schema otherwise. Duplicates slip in when an enum is
71+
// hand-authored in annotations.yml for a field cli.json also defines, since the
72+
// annotation merge concatenates the two sequences. Guard the whole schema.
73+
func TestJsonSchemaEnumsAreUnique(t *testing.T) {
74+
var s any
75+
err := json.Unmarshal(schema.Bytes, &s)
76+
require.NoError(t, err)
77+
78+
assert.Empty(t, duplicateEnumPaths(s, ""))
79+
}
80+
81+
func duplicateEnumPaths(v any, path string) []string {
82+
var duplicates []string
83+
switch v := v.(type) {
84+
case map[string]any:
85+
if enum, ok := v["enum"].([]any); ok {
86+
seen := map[string]struct{}{}
87+
for _, item := range enum {
88+
key := fmt.Sprintf("%v", item)
89+
if _, ok := seen[key]; ok {
90+
duplicates = append(duplicates, path)
91+
break
92+
}
93+
seen[key] = struct{}{}
94+
}
95+
}
96+
for key, value := range v {
97+
if path != "" {
98+
key = path + "/" + key
99+
}
100+
duplicates = append(duplicates, duplicateEnumPaths(value, key)...)
101+
}
102+
case []any:
103+
for i, value := range v {
104+
duplicates = append(duplicates, duplicateEnumPaths(value, fmt.Sprintf("%s[%d]", path, i))...)
105+
}
106+
}
107+
return duplicates
108+
}

bundle/schema/jsonschema.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)