mirror of https://github.com/databricks/cli.git
feat: Yaml styles for open api overrides
This commit is contained in:
parent
073aeca5b7
commit
a6c45d5bf7
|
@ -110,32 +110,11 @@ func (d *annotationHandler) sync(outputPath string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
existing, err := yamlloader.LoadYAML(outputPath, bytes.NewBuffer(existingFile))
|
missingAnnotations, err := yaml.Marshal(d.empty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
emptyB, err := yaml.Marshal(d.empty)
|
err = saveYamlWithStyle(outputPath, existingFile, missingAnnotations)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -158,3 +137,33 @@ func assingAnnotation(s *jsonschema.Schema, a annotation) {
|
||||||
s.Title = a.Title
|
s.Title = a.Title
|
||||||
s.Enum = a.Enum
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1,112 +1,155 @@
|
||||||
github.com/databricks/cli/bundle/config/resources.Cluster:
|
github.com/databricks/cli/bundle/config/resources.Cluster:
|
||||||
data_security_mode:
|
"data_security_mode":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
docker_image:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"docker_image":
|
||||||
permissions:
|
"description": |-
|
||||||
description: PLACEHOLDER
|
PLACEHOLDER
|
||||||
runtime_engine:
|
"permissions":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
workload_type:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"runtime_engine":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
|
"workload_type":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.Dashboard:
|
github.com/databricks/cli/bundle/config/resources.Dashboard:
|
||||||
embed_credentials:
|
"embed_credentials":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
file_path:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"file_path":
|
||||||
permissions:
|
"description": |-
|
||||||
description: PLACEHOLDER
|
PLACEHOLDER
|
||||||
|
"permissions":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.Job:
|
github.com/databricks/cli/bundle/config/resources.Job:
|
||||||
health:
|
"health":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
permissions:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"permissions":
|
||||||
run_as:
|
"description": |-
|
||||||
description: PLACEHOLDER
|
PLACEHOLDER
|
||||||
|
"run_as":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.MlflowExperiment:
|
github.com/databricks/cli/bundle/config/resources.MlflowExperiment:
|
||||||
permissions:
|
"permissions":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.MlflowModel:
|
github.com/databricks/cli/bundle/config/resources.MlflowModel:
|
||||||
permissions:
|
"permissions":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.ModelServingEndpoint:
|
github.com/databricks/cli/bundle/config/resources.ModelServingEndpoint:
|
||||||
permissions:
|
"permissions":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.Pipeline:
|
github.com/databricks/cli/bundle/config/resources.Pipeline:
|
||||||
permissions:
|
"permissions":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.QualityMonitor:
|
github.com/databricks/cli/bundle/config/resources.QualityMonitor:
|
||||||
table_name:
|
"table_name":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.RegisteredModel:
|
github.com/databricks/cli/bundle/config/resources.RegisteredModel:
|
||||||
grants:
|
"grants":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.Schema:
|
github.com/databricks/cli/bundle/config/resources.Schema:
|
||||||
grants:
|
"grants":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
properties:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"properties":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/cli/bundle/config/resources.Volume:
|
github.com/databricks/cli/bundle/config/resources.Volume:
|
||||||
grants:
|
"grants":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
volume_type:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"volume_type":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/compute.AwsAttributes:
|
github.com/databricks/databricks-sdk-go/service/compute.AwsAttributes:
|
||||||
availability:
|
"availability":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
ebs_volume_type:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"ebs_volume_type":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/compute.AzureAttributes:
|
github.com/databricks/databricks-sdk-go/service/compute.AzureAttributes:
|
||||||
availability:
|
"availability":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/compute.ClusterSpec:
|
github.com/databricks/databricks-sdk-go/service/compute.ClusterSpec:
|
||||||
data_security_mode:
|
"data_security_mode":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
docker_image:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"docker_image":
|
||||||
runtime_engine:
|
"description": |-
|
||||||
description: PLACEHOLDER
|
PLACEHOLDER
|
||||||
workload_type:
|
"runtime_engine":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
|
"workload_type":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/compute.DockerImage:
|
github.com/databricks/databricks-sdk-go/service/compute.DockerImage:
|
||||||
basic_auth:
|
"basic_auth":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/compute.GcpAttributes:
|
github.com/databricks/databricks-sdk-go/service/compute.GcpAttributes:
|
||||||
availability:
|
"availability":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.GitSource:
|
github.com/databricks/databricks-sdk-go/service/jobs.GitSource:
|
||||||
git_snapshot:
|
"git_snapshot":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.JobEnvironment:
|
github.com/databricks/databricks-sdk-go/service/jobs.JobEnvironment:
|
||||||
spec:
|
"spec":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.JobsHealthRule:
|
github.com/databricks/databricks-sdk-go/service/jobs.JobsHealthRule:
|
||||||
metric:
|
"metric":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
op:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"op":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.JobsHealthRules:
|
github.com/databricks/databricks-sdk-go/service/jobs.JobsHealthRules:
|
||||||
rules:
|
"rules":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.RunJobTask:
|
github.com/databricks/databricks-sdk-go/service/jobs.RunJobTask:
|
||||||
python_named_params:
|
"python_named_params":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.Task:
|
github.com/databricks/databricks-sdk-go/service/jobs.Task:
|
||||||
health:
|
"health":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.TriggerSettings:
|
github.com/databricks/databricks-sdk-go/service/jobs.TriggerSettings:
|
||||||
table_update:
|
"table_update":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/jobs.Webhook:
|
github.com/databricks/databricks-sdk-go/service/jobs.Webhook:
|
||||||
id:
|
"id":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/pipelines.CronTrigger:
|
github.com/databricks/databricks-sdk-go/service/pipelines.CronTrigger:
|
||||||
quartz_cron_schedule:
|
"quartz_cron_schedule":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
timezone_id:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"timezone_id":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
github.com/databricks/databricks-sdk-go/service/pipelines.PipelineTrigger:
|
github.com/databricks/databricks-sdk-go/service/pipelines.PipelineTrigger:
|
||||||
cron:
|
"cron":
|
||||||
description: PLACEHOLDER
|
"description": |-
|
||||||
manual:
|
PLACEHOLDER
|
||||||
description: PLACEHOLDER
|
"manual":
|
||||||
|
"description": |-
|
||||||
|
PLACEHOLDER
|
||||||
|
|
|
@ -147,11 +147,10 @@ func (p *openapiParser) extractAnnotations(typ reflect.Type, outputPath, overrid
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = os.WriteFile(overridesPath, b, 0644)
|
err = saveYamlWithStyle(overridesPath, b, []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err = yaml.Marshal(annotations)
|
b, err = yaml.Marshal(annotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue