github.com/databricks/cli@v0.203.0/bundle/schema/docs_test.go (about)

     1  package schema
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/databricks/cli/libs/jsonschema"
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestSchemaToDocs(t *testing.T) {
    13  	jsonSchema := &jsonschema.Schema{
    14  		Type:        "object",
    15  		Description: "root doc",
    16  		Properties: map[string]*jsonschema.Schema{
    17  			"foo": {Type: "number", Description: "foo doc"},
    18  			"bar": {Type: "string"},
    19  			"octave": {
    20  				Type:                 "object",
    21  				AdditionalProperties: &jsonschema.Schema{Type: "number"},
    22  				Description:          "octave docs",
    23  			},
    24  			"scales": {
    25  				Type:        "object",
    26  				Description: "scale docs",
    27  				Items:       &jsonschema.Schema{Type: "string"},
    28  			},
    29  		},
    30  	}
    31  	docs := schemaToDocs(jsonSchema)
    32  	docsJson, err := json.MarshalIndent(docs, "		", "	")
    33  	require.NoError(t, err)
    34  
    35  	expected :=
    36  		`{
    37  			"description": "root doc",
    38  			"properties": {
    39  				"bar": {
    40  					"description": ""
    41  				},
    42  				"foo": {
    43  					"description": "foo doc"
    44  				},
    45  				"octave": {
    46  					"description": "octave docs",
    47  					"additionalproperties": {
    48  						"description": ""
    49  					}
    50  				},
    51  				"scales": {
    52  					"description": "scale docs",
    53  					"items": {
    54  						"description": ""
    55  					}
    56  				}
    57  			}
    58  		}`
    59  	t.Log("[DEBUG] actual: ", string(docsJson))
    60  	t.Log("[DEBUG] expected: ", expected)
    61  	assert.Equal(t, expected, string(docsJson))
    62  }