-
Notifications
You must be signed in to change notification settings - Fork 181
Expose stage/release status in schema #5443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e500f48
d5673ef
e54bc98
b47043d
078472c
33fe412
bddbd3c
ea21ed6
6140ac3
e69435c
e6b64cd
4d3245f
34ac637
4d154e4
1e1d8e7
7ca85f7
dbedf1c
6d3a8e4
102150d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| package annotation | ||
|
|
||
| type Descriptor struct { | ||
| Description string `json:"description,omitempty"` | ||
| MarkdownDescription string `json:"markdown_description,omitempty"` | ||
| Title string `json:"title,omitempty"` | ||
| Default any `json:"default,omitempty"` | ||
| Enum []any `json:"enum,omitempty"` | ||
| MarkdownExamples string `json:"markdown_examples,omitempty"` | ||
| DeprecationMessage string `json:"deprecation_message,omitempty"` | ||
| Preview string `json:"x-databricks-preview,omitempty"` | ||
| OutputOnly *bool `json:"x-databricks-field-behaviors_output_only,omitempty"` | ||
| Description string `json:"description,omitempty"` | ||
| MarkdownDescription string `json:"markdown_description,omitempty"` | ||
| Title string `json:"title,omitempty"` | ||
| Default any `json:"default,omitempty"` | ||
| Enum []any `json:"enum,omitempty"` | ||
| MarkdownExamples string `json:"markdown_examples,omitempty"` | ||
| DeprecationMessage string `json:"deprecation_message,omitempty"` | ||
| Preview string `json:"x-databricks-preview,omitempty"` | ||
| LaunchStage string `json:"x-databricks-launch-stage,omitempty"` | ||
| EnumLaunchStages map[string]string `json:"x-databricks-enum-launch-stages,omitempty"` | ||
| EnumDescriptions map[string]string `json:"x-databricks-enum-descriptions,omitempty"` | ||
| OutputOnly *bool `json:"x-databricks-field-behaviors_output_only,omitempty"` | ||
| } | ||
|
|
||
| const Placeholder = "PLACEHOLDER" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package annotation | ||
|
|
||
| // PreviewTag returns the human-readable launch-stage prefix to prepend to a | ||
| // field's or enum value's description. Others are skipped. | ||
| func PreviewTag(launchStage string) string { | ||
| switch launchStage { | ||
| case "PRIVATE_PREVIEW": | ||
| return "[Private Preview]" | ||
| case "PUBLIC_BETA": | ||
| return "[Beta]" | ||
| case "PUBLIC_PREVIEW": | ||
| return "[Public Preview]" | ||
| } | ||
| return "" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package annotation_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/bundle/internal/annotation" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPreviewTag(t *testing.T) { | ||
| tests := []struct { | ||
| launchStage string | ||
| want string | ||
| }{ | ||
| {"PUBLIC_PREVIEW", "[Public Preview]"}, | ||
| {"PUBLIC_BETA", "[Beta]"}, | ||
| {"PRIVATE_PREVIEW", "[Private Preview]"}, | ||
| {"GA", ""}, | ||
| {"", ""}, | ||
| {"SOMETHING_ELSE", ""}, | ||
| } | ||
| for _, tc := range tests { | ||
| assert.Equal(t, tc.want, annotation.PreviewTag(tc.launchStage)) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,13 @@ func assignAnnotation(s *jsonschema.Schema, a annotation.Descriptor) { | |
| s.DeprecationMessage = a.DeprecationMessage | ||
| } | ||
|
|
||
| // The raw launch stage is intentionally not emitted into the published | ||
| // schema — nothing consumes it there. It surfaces only as the description | ||
| // prefix below and the per-value enumDescriptions labels. | ||
| // x-databricks-preview does stay: the parser derives it from launch_stage | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field Would be great if we make also downstream codegen use the launch stage exclusively. Can be a follow up.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good |
||
| // (PRIVATE iff PRIVATE_PREVIEW), and pydabs reads it from jsonschema.json | ||
| // to mark fields experimental, so this branch also covers hiding | ||
| // private-preview fields. | ||
| if a.Preview == "PRIVATE" { | ||
| s.DoNotSuggest = true | ||
| s.Preview = a.Preview | ||
|
|
@@ -146,6 +153,54 @@ func assignAnnotation(s *jsonschema.Schema, a annotation.Descriptor) { | |
| s.MarkdownDescription = convertLinksToAbsoluteUrl(a.MarkdownDescription) | ||
| s.Title = a.Title | ||
| s.Enum = a.Enum | ||
| s.EnumDescriptions = buildEnumDescriptions(a.Enum, a.EnumLaunchStages, a.EnumDescriptions) | ||
|
|
||
| // Surface launch stage in hover tooltips. Editors only render the standard | ||
| // description field, so the tag is baked into the text. | ||
| if tag := annotation.PreviewTag(a.LaunchStage); tag != "" { | ||
| s.Description = prefixWithPreviewTag(s.Description, tag) | ||
| } | ||
| } | ||
|
|
||
| // buildEnumDescriptions produces the parallel enumDescriptions array VSCode | ||
| // renders next to each enum value. Each entry combines the launch-stage tag | ||
| // and the per-value description text. Returns nil when every entry would be | ||
| // empty so the field is omitted from the schema. The enum slice is the same | ||
| // one assigned to s.Enum, so the arrays stay index-aligned. | ||
| func buildEnumDescriptions(enum []any, launchStages, descriptions map[string]string) []string { | ||
| if len(enum) == 0 || (len(launchStages) == 0 && len(descriptions) == 0) { | ||
| return nil | ||
| } | ||
| result := make([]string, len(enum)) | ||
| hasContent := false | ||
| for i, v := range enum { | ||
| key, ok := v.(string) | ||
| if !ok { | ||
| continue | ||
| } | ||
| result[i] = prefixWithPreviewTag(descriptions[key], annotation.PreviewTag(launchStages[key])) | ||
| if result[i] != "" { | ||
| hasContent = true | ||
| } | ||
| } | ||
| if !hasContent { | ||
| return nil | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| // prefixWithPreviewTag prepends the launch-stage tag to a description while | ||
| // guarding against double-tagging — if the description already starts with | ||
| // the tag, it is returned unchanged. An empty tag (GA) also takes the | ||
| // HasPrefix path, returning the description as-is. | ||
| func prefixWithPreviewTag(description, tag string) string { | ||
| if description == "" { | ||
| return tag | ||
| } | ||
| if strings.HasPrefix(description, tag) { | ||
| return description | ||
| } | ||
| return tag + " " + description | ||
| } | ||
|
|
||
| func saveYamlWithStyle(outputPath string, annotations annotation.File) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if we had a "LaunchStage" type we can use for this (for ex in
internal/clijson/types.go).Some kind of enforcement or check that if a new stage is added we don't forget to update this mapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do as follow-up