mirror of https://github.com/databricks/cli.git
[Internal] Remove dependency to the `openapi` package of the Go SDK (#1676)
## Changes This PR removes the dependency to the `databricks-sdk-go/openapi` package by copying the struct and functions that are needed in a new `schema/spec.go` file. The reason to remove this dependency is that it is being deprecated. Copying the code in the `cli` repo seems reasonable given that it only uses a couple of very small structs. ## Tests Verified that CLI code can be properly generated after this change.
This commit is contained in:
parent
f32902dc04
commit
7aaaee2512
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"github.com/databricks/cli/libs/jsonschema"
|
||||||
"github.com/databricks/databricks-sdk-go/openapi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A subset of Schema struct
|
// A subset of Schema struct
|
||||||
|
@ -63,7 +62,7 @@ func UpdateBundleDescriptions(openapiSpecPath string) (*Docs, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
err = json.Unmarshal(openapiSpec, spec)
|
err = json.Unmarshal(openapiSpec, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -6,12 +6,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"github.com/databricks/cli/libs/jsonschema"
|
||||||
"github.com/databricks/databricks-sdk-go/openapi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type OpenapiReader struct {
|
type OpenapiReader struct {
|
||||||
// OpenAPI spec to read schemas from.
|
// OpenAPI spec to read schemas from.
|
||||||
OpenapiSpec *openapi.Specification
|
OpenapiSpec *Specification
|
||||||
|
|
||||||
// In-memory cache of schemas read from the OpenAPI spec.
|
// In-memory cache of schemas read from the OpenAPI spec.
|
||||||
memo map[string]jsonschema.Schema
|
memo map[string]jsonschema.Schema
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"github.com/databricks/cli/libs/jsonschema"
|
||||||
"github.com/databricks/databricks-sdk-go/openapi"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -45,7 +44,7 @@ func TestReadSchemaForObject(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -103,7 +102,7 @@ func TestReadSchemaForArray(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -149,7 +148,7 @@ func TestReadSchemaForMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -198,7 +197,7 @@ func TestRootReferenceIsResolved(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -248,7 +247,7 @@ func TestSelfReferenceLoopErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -282,7 +281,7 @@ func TestCrossReferenceLoopErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -327,7 +326,7 @@ func TestReferenceResolutionForMapInObject(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -397,7 +396,7 @@ func TestReferenceResolutionForArrayInObject(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
@ -460,7 +459,7 @@ func TestReferenceResolutionDoesNotOverwriteDescriptions(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
spec := &openapi.Specification{}
|
spec := &Specification{}
|
||||||
reader := &OpenapiReader{
|
reader := &OpenapiReader{
|
||||||
OpenapiSpec: spec,
|
OpenapiSpec: spec,
|
||||||
memo: make(map[string]jsonschema.Schema),
|
memo: make(map[string]jsonschema.Schema),
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package schema
|
||||||
|
|
||||||
|
import "github.com/databricks/cli/libs/jsonschema"
|
||||||
|
|
||||||
|
type Specification struct {
|
||||||
|
Components *Components `json:"components"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Components struct {
|
||||||
|
Schemas map[string]*jsonschema.Schema `json:"schemas,omitempty"`
|
||||||
|
}
|
Loading…
Reference in New Issue