Skip to content

Commit

Permalink
feat: Yaml styles for open api overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakuz-db committed Dec 10, 2024
1 parent 073aeca commit a6c45d5
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 111 deletions.
55 changes: 32 additions & 23 deletions bundle/internal/schema/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,11 @@ func (d *annotationHandler) sync(outputPath string) error {
return err
}

existing, err := yamlloader.LoadYAML(outputPath, bytes.NewBuffer(existingFile))
missingAnnotations, err := yaml.Marshal(d.empty)
if err != nil {
return err
}
emptyB, err := yaml.Marshal(d.empty)
if err != nil {
return err
}

empty, err := yamlloader.LoadYAML("", bytes.NewBuffer(emptyB))
if err != nil {
return err
}
mergedFile, err := merge.Merge(existing, empty)
if err != nil {
return err
}

style := map[string]yaml3.Style{}
file, _ := mergedFile.AsMap()
for _, v := range file.Keys() {
style[v.MustString()] = yaml3.LiteralStyle
}

saver := yamlsaver.NewSaverWithStyle(style)
err = saver.SaveAsYAML(file, outputPath, true)
err = saveYamlWithStyle(outputPath, existingFile, missingAnnotations)
if err != nil {
return err
}
Expand All @@ -158,3 +137,33 @@ func assingAnnotation(s *jsonschema.Schema, a annotation) {
s.Title = a.Title
s.Enum = a.Enum
}

func saveYamlWithStyle(outputPath string, input []byte, overrides []byte) error {
inputDyn, err := yamlloader.LoadYAML("", bytes.NewBuffer(input))
if err != nil {
return err
}
if len(overrides) != 0 {
overrideDyn, err := yamlloader.LoadYAML("", bytes.NewBuffer(overrides))
if err != nil {
return err
}
inputDyn, err = merge.Merge(inputDyn, overrideDyn)
if err != nil {
return err
}
}

style := map[string]yaml3.Style{}
file, _ := inputDyn.AsMap()
for _, v := range file.Keys() {
style[v.MustString()] = yaml3.LiteralStyle
}

saver := yamlsaver.NewSaverWithStyle(style)
err = saver.SaveAsYAML(file, outputPath, true)
if err != nil {
return err
}
return nil
}
215 changes: 129 additions & 86 deletions bundle/internal/schema/annotations_openapi_overrides.yml
Original file line number Diff line number Diff line change
@@ -1,112 +1,155 @@
github.com/databricks/cli/bundle/config/resources.Cluster:
data_security_mode:
description: PLACEHOLDER
docker_image:
description: PLACEHOLDER
permissions:
description: PLACEHOLDER
runtime_engine:
description: PLACEHOLDER
workload_type:
description: PLACEHOLDER
"data_security_mode":
"description": |-
PLACEHOLDER
"docker_image":
"description": |-
PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
"runtime_engine":
"description": |-
PLACEHOLDER
"workload_type":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.Dashboard:
embed_credentials:
description: PLACEHOLDER
file_path:
description: PLACEHOLDER
permissions:
description: PLACEHOLDER
"embed_credentials":
"description": |-
PLACEHOLDER
"file_path":
"description": |-
PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.Job:
health:
description: PLACEHOLDER
permissions:
description: PLACEHOLDER
run_as:
description: PLACEHOLDER
"health":
"description": |-
PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
"run_as":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.MlflowExperiment:
permissions:
description: PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.MlflowModel:
permissions:
description: PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.ModelServingEndpoint:
permissions:
description: PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.Pipeline:
permissions:
description: PLACEHOLDER
"permissions":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.QualityMonitor:
table_name:
description: PLACEHOLDER
"table_name":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.RegisteredModel:
grants:
description: PLACEHOLDER
"grants":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.Schema:
grants:
description: PLACEHOLDER
properties:
description: PLACEHOLDER
"grants":
"description": |-
PLACEHOLDER
"properties":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.Volume:
grants:
description: PLACEHOLDER
volume_type:
description: PLACEHOLDER
"grants":
"description": |-
PLACEHOLDER
"volume_type":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/compute.AwsAttributes:
availability:
description: PLACEHOLDER
ebs_volume_type:
description: PLACEHOLDER
"availability":
"description": |-
PLACEHOLDER
"ebs_volume_type":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/compute.AzureAttributes:
availability:
description: PLACEHOLDER
"availability":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/compute.ClusterSpec:
data_security_mode:
description: PLACEHOLDER
docker_image:
description: PLACEHOLDER
runtime_engine:
description: PLACEHOLDER
workload_type:
description: PLACEHOLDER
"data_security_mode":
"description": |-
PLACEHOLDER
"docker_image":
"description": |-
PLACEHOLDER
"runtime_engine":
"description": |-
PLACEHOLDER
"workload_type":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/compute.DockerImage:
basic_auth:
description: PLACEHOLDER
"basic_auth":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/compute.GcpAttributes:
availability:
description: PLACEHOLDER
"availability":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.GitSource:
git_snapshot:
description: PLACEHOLDER
"git_snapshot":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.JobEnvironment:
spec:
description: PLACEHOLDER
"spec":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.JobsHealthRule:
metric:
description: PLACEHOLDER
op:
description: PLACEHOLDER
"metric":
"description": |-
PLACEHOLDER
"op":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.JobsHealthRules:
rules:
description: PLACEHOLDER
"rules":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.RunJobTask:
python_named_params:
description: PLACEHOLDER
"python_named_params":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.Task:
health:
description: PLACEHOLDER
"health":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.TriggerSettings:
table_update:
description: PLACEHOLDER
"table_update":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/jobs.Webhook:
id:
description: PLACEHOLDER
"id":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/pipelines.CronTrigger:
quartz_cron_schedule:
description: PLACEHOLDER
timezone_id:
description: PLACEHOLDER
"quartz_cron_schedule":
"description": |-
PLACEHOLDER
"timezone_id":
"description": |-
PLACEHOLDER
github.com/databricks/databricks-sdk-go/service/pipelines.PipelineTrigger:
cron:
description: PLACEHOLDER
manual:
description: PLACEHOLDER
"cron":
"description": |-
PLACEHOLDER
"manual":
"description": |-
PLACEHOLDER
3 changes: 1 addition & 2 deletions bundle/internal/schema/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ func (p *openapiParser) extractAnnotations(typ reflect.Type, outputPath, overrid
if err != nil {
return err
}
err = os.WriteFile(overridesPath, b, 0644)
err = saveYamlWithStyle(overridesPath, b, []byte{})
if err != nil {
return err
}

b, err = yaml.Marshal(annotations)
if err != nil {
return err
Expand Down

0 comments on commit a6c45d5

Please sign in to comment.