feat: Format markdown links to absolute

This commit is contained in:
Ilya Kuznetsov 2024-12-10 16:13:51 +01:00
parent e15107fbcc
commit 9a5503755a
No known key found for this signature in database
GPG Key ID: 91F3DDCF5D21CDDF
2 changed files with 79 additions and 34 deletions

View File

@ -2,8 +2,10 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"os" "os"
"reflect" "reflect"
"regexp"
"strings" "strings"
yaml3 "gopkg.in/yaml.v3" yaml3 "gopkg.in/yaml.v3"
@ -141,7 +143,7 @@ func assingAnnotation(s *jsonschema.Schema, a annotation) {
if a.Default != nil { if a.Default != nil {
s.Default = a.Default s.Default = a.Default
} }
s.MarkdownDescription = a.MarkdownDescription s.MarkdownDescription = convertLinksToAbsoluteUrl(a.MarkdownDescription)
s.Title = a.Title s.Title = a.Title
s.Enum = a.Enum s.Enum = a.Enum
} }
@ -160,3 +162,46 @@ func saveYamlWithStyle(outputPath string, input dyn.Value) error {
} }
return nil return nil
} }
func convertLinksToAbsoluteUrl(s string) string {
if s == "" {
return s
}
base := "https://docs.databricks.com"
referencePage := "/dev-tools/bundles/reference.html"
// Regular expression to match Markdown-style links
re := regexp.MustCompile(`\[_\]\(([^)]+)\)`)
result := re.ReplaceAllStringFunc(s, func(match string) string {
// Extract the URL inside parentheses
matches := re.FindStringSubmatch(match)
if len(matches) < 2 {
return match // Return original if no match found
}
link := matches[1]
var text, absoluteURL string
if strings.HasPrefix(link, "#") {
text = strings.TrimPrefix(link, "#")
absoluteURL = fmt.Sprintf("%s%s%s", base, referencePage, link)
} else if strings.HasPrefix(link, "/") {
// Handle relative paths like /dev-tools/bundles/resources.html#dashboard
if strings.Contains(link, "#") {
parts := strings.Split(link, "#")
text = parts[1]
absoluteURL = fmt.Sprintf("%s%s", base, link)
} else {
text = "link"
absoluteURL = fmt.Sprintf("%s%s", base, link)
}
absoluteURL = strings.ReplaceAll(absoluteURL, ".md", ".html")
} else {
return match
}
return fmt.Sprintf("[%s](%s)", text, absoluteURL)
})
return result
}

View File

@ -959,7 +959,7 @@
"files": { "files": {
"description": "The source files for the artifact.", "description": "The source files for the artifact.",
"$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config.ArtifactFile", "$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config.ArtifactFile",
"markdownDescription": "The source files for the artifact, defined as an [_](#artifact_file)." "markdownDescription": "The source files for the artifact, defined as an [artifact_file](https://docs.databricks.com/dev-tools/bundles/reference.html#artifact_file)."
}, },
"path": { "path": {
"description": "The location where the built artifact will be saved.", "description": "The location where the built artifact will be saved.",
@ -1013,7 +1013,7 @@
"cluster_id": { "cluster_id": {
"description": "The ID of a cluster to use to run the bundle.", "description": "The ID of a cluster to use to run the bundle.",
"$ref": "#/$defs/string", "$ref": "#/$defs/string",
"markdownDescription": "The ID of a cluster to use to run the bundle. See [_](/dev-tools/bundles/settings.md#cluster_id)." "markdownDescription": "The ID of a cluster to use to run the bundle. See [cluster_id](https://docs.databricks.com/dev-tools/bundles/settings.html#cluster_id)."
}, },
"compute_id": { "compute_id": {
"$ref": "#/$defs/string" "$ref": "#/$defs/string"
@ -1021,17 +1021,17 @@
"databricks_cli_version": { "databricks_cli_version": {
"description": "The Databricks CLI version to use for the bundle.", "description": "The Databricks CLI version to use for the bundle.",
"$ref": "#/$defs/string", "$ref": "#/$defs/string",
"markdownDescription": "The Databricks CLI version to use for the bundle. See [_](/dev-tools/bundles/settings.md#databricks_cli_version)." "markdownDescription": "The Databricks CLI version to use for the bundle. See [databricks_cli_version](https://docs.databricks.com/dev-tools/bundles/settings.html#databricks_cli_version)."
}, },
"deployment": { "deployment": {
"description": "The definition of the bundle deployment", "description": "The definition of the bundle deployment",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Deployment", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Deployment",
"markdownDescription": "The definition of the bundle deployment. For supported attributes, see [_](#deployment) and [_](/dev-tools/bundles/deployment-modes.md)." "markdownDescription": "The definition of the bundle deployment. For supported attributes, see [deployment](https://docs.databricks.com/dev-tools/bundles/reference.html#deployment) and [link](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html)."
}, },
"git": { "git": {
"description": "The Git version control details that are associated with your bundle.", "description": "The Git version control details that are associated with your bundle.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Git", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Git",
"markdownDescription": "The Git version control details that are associated with your bundle. For supported attributes, see [_](#git) and [_](/dev-tools/bundles/settings.md#git)." "markdownDescription": "The Git version control details that are associated with your bundle. For supported attributes, see [git](https://docs.databricks.com/dev-tools/bundles/reference.html#git) and [git](https://docs.databricks.com/dev-tools/bundles/settings.html#git)."
}, },
"name": { "name": {
"description": "The name of the bundle.", "description": "The name of the bundle.",
@ -1067,7 +1067,7 @@
"lock": { "lock": {
"description": "The deployment lock attributes.", "description": "The deployment lock attributes.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Lock", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Lock",
"markdownDescription": "The deployment lock attributes. See [_](#lock)." "markdownDescription": "The deployment lock attributes. See [lock](https://docs.databricks.com/dev-tools/bundles/reference.html#lock)."
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -1116,12 +1116,12 @@
"branch": { "branch": {
"description": "The Git branch name.", "description": "The Git branch name.",
"$ref": "#/$defs/string", "$ref": "#/$defs/string",
"markdownDescription": "The Git branch name. See [_](/dev-tools/bundles/settings.md#git)." "markdownDescription": "The Git branch name. See [git](https://docs.databricks.com/dev-tools/bundles/settings.html#git)."
}, },
"origin_url": { "origin_url": {
"description": "The origin URL of the repository.", "description": "The origin URL of the repository.",
"$ref": "#/$defs/string", "$ref": "#/$defs/string",
"markdownDescription": "The origin URL of the repository. See [_](/dev-tools/bundles/settings.md#git)." "markdownDescription": "The origin URL of the repository. See [git](https://docs.databricks.com/dev-tools/bundles/settings.html#git)."
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -1229,52 +1229,52 @@
"clusters": { "clusters": {
"description": "The cluster definitions for the bundle.", "description": "The cluster definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Cluster", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Cluster",
"markdownDescription": "The cluster definitions for the bundle. See [_](/dev-tools/bundles/resources.md#cluster)" "markdownDescription": "The cluster definitions for the bundle. See [cluster](https://docs.databricks.com/dev-tools/bundles/resources.html#cluster)"
}, },
"dashboards": { "dashboards": {
"description": "The dashboard definitions for the bundle.", "description": "The dashboard definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Dashboard", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Dashboard",
"markdownDescription": "The dashboard definitions for the bundle. See [_](/dev-tools/bundles/resources.md#dashboard)" "markdownDescription": "The dashboard definitions for the bundle. See [dashboard](https://docs.databricks.com/dev-tools/bundles/resources.html#dashboard)"
}, },
"experiments": { "experiments": {
"description": "The experiment definitions for the bundle.", "description": "The experiment definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.MlflowExperiment", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.MlflowExperiment",
"markdownDescription": "The experiment definitions for the bundle. See [_](/dev-tools/bundles/resources.md#experiment)" "markdownDescription": "The experiment definitions for the bundle. See [experiment](https://docs.databricks.com/dev-tools/bundles/resources.html#experiment)"
}, },
"jobs": { "jobs": {
"description": "The job definitions for the bundle.", "description": "The job definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Job", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Job",
"markdownDescription": "The job definitions for the bundle. See [_](/dev-tools/bundles/resources.md#job)" "markdownDescription": "The job definitions for the bundle. See [job](https://docs.databricks.com/dev-tools/bundles/resources.html#job)"
}, },
"model_serving_endpoints": { "model_serving_endpoints": {
"description": "The model serving endpoint definitions for the bundle.", "description": "The model serving endpoint definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.ModelServingEndpoint", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.ModelServingEndpoint",
"markdownDescription": "The model serving endpoint definitions for the bundle. See [_](/dev-tools/bundles/resources.md#model_serving_endpoint)" "markdownDescription": "The model serving endpoint definitions for the bundle. See [model_serving_endpoint](https://docs.databricks.com/dev-tools/bundles/resources.html#model_serving_endpoint)"
}, },
"models": { "models": {
"description": "The model definitions for the bundle.", "description": "The model definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.MlflowModel", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.MlflowModel",
"markdownDescription": "The model definitions for the bundle. See [_](/dev-tools/bundles/resources.md#model)" "markdownDescription": "The model definitions for the bundle. See [model](https://docs.databricks.com/dev-tools/bundles/resources.html#model)"
}, },
"pipelines": { "pipelines": {
"description": "The pipeline definitions for the bundle.", "description": "The pipeline definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Pipeline", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Pipeline",
"markdownDescription": "The pipeline definitions for the bundle. See [_](/dev-tools/bundles/resources.md#pipeline)" "markdownDescription": "The pipeline definitions for the bundle. See [pipeline](https://docs.databricks.com/dev-tools/bundles/resources.html#pipeline)"
}, },
"quality_monitors": { "quality_monitors": {
"description": "The quality monitor definitions for the bundle.", "description": "The quality monitor definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.QualityMonitor", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.QualityMonitor",
"markdownDescription": "The quality monitor definitions for the bundle. See [_](/dev-tools/bundles/resources.md#quality_monitor)" "markdownDescription": "The quality monitor definitions for the bundle. See [quality_monitor](https://docs.databricks.com/dev-tools/bundles/resources.html#quality_monitor)"
}, },
"registered_models": { "registered_models": {
"description": "The registered model definitions for the bundle.", "description": "The registered model definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.RegisteredModel", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.RegisteredModel",
"markdownDescription": "The registered model definitions for the bundle. See [_](/dev-tools/bundles/resources.md#registered_model)" "markdownDescription": "The registered model definitions for the bundle. See [registered_model](https://docs.databricks.com/dev-tools/bundles/resources.html#registered_model)"
}, },
"schemas": { "schemas": {
"description": "The schema definitions for the bundle.", "description": "The schema definitions for the bundle.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Schema", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Schema",
"markdownDescription": "The schema definitions for the bundle. See [_](/dev-tools/bundles/resources.md#schema)" "markdownDescription": "The schema definitions for the bundle. See [schema](https://docs.databricks.com/dev-tools/bundles/resources.html#schema)"
}, },
"volumes": { "volumes": {
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Volume" "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/resources.Volume"
@ -1322,7 +1322,7 @@
"artifacts": { "artifacts": {
"description": "The artifacts to include in the target deployment.", "description": "The artifacts to include in the target deployment.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.Artifact", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.Artifact",
"markdownDescription": "The artifacts to include in the target deployment. See [_](#artifact)" "markdownDescription": "The artifacts to include in the target deployment. See [artifact](https://docs.databricks.com/dev-tools/bundles/reference.html#artifact)"
}, },
"bundle": { "bundle": {
"description": "The name of the bundle when deploying to this target.", "description": "The name of the bundle when deploying to this target.",
@ -1343,47 +1343,47 @@
"git": { "git": {
"description": "The Git version control settings for the target.", "description": "The Git version control settings for the target.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Git", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Git",
"markdownDescription": "The Git version control settings for the target. See [_](#git)." "markdownDescription": "The Git version control settings for the target. See [git](https://docs.databricks.com/dev-tools/bundles/reference.html#git)."
}, },
"mode": { "mode": {
"description": "The deployment mode for the target. Valid values are development or production.", "description": "The deployment mode for the target. Valid values are development or production.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Mode", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Mode",
"markdownDescription": "The deployment mode for the target. Valid values are development or production. See [_](/dev-tools/bundles/deployment-modes.md)." "markdownDescription": "The deployment mode for the target. Valid values are development or production. See [link](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html)."
}, },
"permissions": { "permissions": {
"description": "The permissions for deploying and running the bundle in the target.", "description": "The permissions for deploying and running the bundle in the target.",
"$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config/resources.Permission", "$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config/resources.Permission",
"markdownDescription": "The permissions for deploying and running the bundle in the target. See [_](#permission)." "markdownDescription": "The permissions for deploying and running the bundle in the target. See [permission](https://docs.databricks.com/dev-tools/bundles/reference.html#permission)."
}, },
"presets": { "presets": {
"description": "The deployment presets for the target.", "description": "The deployment presets for the target.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Presets", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Presets",
"markdownDescription": "The deployment presets for the target. See [_](#preset)." "markdownDescription": "The deployment presets for the target. See [preset](https://docs.databricks.com/dev-tools/bundles/reference.html#preset)."
}, },
"resources": { "resources": {
"description": "The resource definitions for the target.", "description": "The resource definitions for the target.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Resources", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Resources",
"markdownDescription": "The resource definitions for the target. See [_](#resources)." "markdownDescription": "The resource definitions for the target. See [resources](https://docs.databricks.com/dev-tools/bundles/reference.html#resources)."
}, },
"run_as": { "run_as": {
"description": "The identity to use to run the bundle.", "description": "The identity to use to run the bundle.",
"$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/jobs.JobRunAs", "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/jobs.JobRunAs",
"markdownDescription": "The identity to use to run the bundle. See [_](#job_run_as) and [_](/dev-tools/bundles/run_as.md)." "markdownDescription": "The identity to use to run the bundle. See [job_run_as](https://docs.databricks.com/dev-tools/bundles/reference.html#job_run_as) and [link](https://docs.databricks.com/dev-tools/bundles/run_as.html)."
}, },
"sync": { "sync": {
"description": "The local paths to sync to the target workspace when a bundle is run or deployed.", "description": "The local paths to sync to the target workspace when a bundle is run or deployed.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync",
"markdownDescription": "The local paths to sync to the target workspace when a bundle is run or deployed. See [_](#sync)." "markdownDescription": "The local paths to sync to the target workspace when a bundle is run or deployed. See [sync](https://docs.databricks.com/dev-tools/bundles/reference.html#sync)."
}, },
"variables": { "variables": {
"description": "The custom variable definitions for the target.", "description": "The custom variable definitions for the target.",
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable", "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable",
"markdownDescription": "The custom variable definitions for the target. See [_](/dev-tools/bundles/settings.md#variables) and [_](/dev-tools/bundles/variables.md)." "markdownDescription": "The custom variable definitions for the target. See [variables](https://docs.databricks.com/dev-tools/bundles/settings.html#variables) and [link](https://docs.databricks.com/dev-tools/bundles/variables.html)."
}, },
"workspace": { "workspace": {
"description": "The Databricks workspace for the target. _.", "description": "The Databricks workspace for the target. _.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Workspace", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Workspace",
"markdownDescription": "The Databricks workspace for the target. [_](#workspace)" "markdownDescription": "The Databricks workspace for the target. [workspace](https://docs.databricks.com/dev-tools/bundles/reference.html#workspace)"
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -6275,7 +6275,7 @@
"bundle": { "bundle": {
"description": "The attributes of the bundle.", "description": "The attributes of the bundle.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Bundle", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Bundle",
"markdownDescription": "The attributes of the bundle. See [_](/dev-tools/bundles/settings.md#bundle)" "markdownDescription": "The attributes of the bundle. See [bundle](https://docs.databricks.com/dev-tools/bundles/settings.html#bundle)"
}, },
"experimental": { "experimental": {
"description": "Defines attributes for experimental features.", "description": "Defines attributes for experimental features.",
@ -6287,16 +6287,16 @@
"permissions": { "permissions": {
"description": "Defines the permissions to apply to experiments, jobs, pipelines, and models defined in the bundle", "description": "Defines the permissions to apply to experiments, jobs, pipelines, and models defined in the bundle",
"$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config/resources.Permission", "$ref": "#/$defs/slice/github.com/databricks/cli/bundle/config/resources.Permission",
"markdownDescription": "Defines the permissions to apply to experiments, jobs, pipelines, and models defined in the bundle. See [_](/dev-tools/bundles/settings.md#permissions) and [_](/dev-tools/bundles/permissions.md)." "markdownDescription": "Defines the permissions to apply to experiments, jobs, pipelines, and models defined in the bundle. See [permissions](https://docs.databricks.com/dev-tools/bundles/settings.html#permissions) and [link](https://docs.databricks.com/dev-tools/bundles/permissions.html)."
}, },
"presets": { "presets": {
"description": "Defines bundle deployment presets.", "description": "Defines bundle deployment presets.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Presets", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Presets",
"markdownDescription": "Defines bundle deployment presets. See [_](/dev-tools/bundles/deployment-modes.md#presets)." "markdownDescription": "Defines bundle deployment presets. See [presets](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html#presets)."
}, },
"resources": { "resources": {
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Resources", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Resources",
"markdownDescription": "See [_](/dev-tools/bundles/resources.md)." "markdownDescription": "See [link](https://docs.databricks.com/dev-tools/bundles/resources.html)."
}, },
"run_as": { "run_as": {
"$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/jobs.JobRunAs" "$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/jobs.JobRunAs"
@ -6304,7 +6304,7 @@
"sync": { "sync": {
"description": "The files and file paths to include or exclude in the bundle.", "description": "The files and file paths to include or exclude in the bundle.",
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync", "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync",
"markdownDescription": "The files and file paths to include or exclude in the bundle. See [_](/dev-tools/bundles/)" "markdownDescription": "The files and file paths to include or exclude in the bundle. See [link](https://docs.databricks.com/dev-tools/bundles/)"
}, },
"targets": { "targets": {
"description": "Defines deployment targets for the bundle.", "description": "Defines deployment targets for the bundle.",