Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Remove dependency to the openapi package of the Go SDK #1676

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bundle/schema/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/libs/jsonschema"
"github.com/databricks/databricks-sdk-go/openapi"
)

// A subset of Schema struct
Expand Down Expand Up @@ -63,7 +62,7 @@ func UpdateBundleDescriptions(openapiSpecPath string) (*Docs, error) {
if err != nil {
return nil, err
}
spec := &openapi.Specification{}
spec := &Specification{}
err = json.Unmarshal(openapiSpec, spec)
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions bundle/schema/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"strings"

"github.com/databricks/cli/libs/jsonschema"
"github.com/databricks/databricks-sdk-go/openapi"
)

type OpenapiReader struct {
// OpenAPI spec to read schemas from.
OpenapiSpec *openapi.Specification
OpenapiSpec *Specification

// In-memory cache of schemas read from the OpenAPI spec.
memo map[string]jsonschema.Schema
Expand Down
19 changes: 9 additions & 10 deletions bundle/schema/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/databricks/cli/libs/jsonschema"
"github.com/databricks/databricks-sdk-go/openapi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -45,7 +44,7 @@ func TestReadSchemaForObject(t *testing.T) {
}
}
`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -103,7 +102,7 @@ func TestReadSchemaForArray(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestReadSchemaForMap(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -198,7 +197,7 @@ func TestRootReferenceIsResolved(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -248,7 +247,7 @@ func TestSelfReferenceLoopErrors(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -282,7 +281,7 @@ func TestCrossReferenceLoopErrors(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -327,7 +326,7 @@ func TestReferenceResolutionForMapInObject(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -397,7 +396,7 @@ func TestReferenceResolutionForArrayInObject(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down Expand Up @@ -460,7 +459,7 @@ func TestReferenceResolutionDoesNotOverwriteDescriptions(t *testing.T) {
}
}
}`
spec := &openapi.Specification{}
spec := &Specification{}
reader := &OpenapiReader{
OpenapiSpec: spec,
memo: make(map[string]jsonschema.Schema),
Expand Down
53 changes: 53 additions & 0 deletions bundle/schema/spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package schema
renaudhartert-db marked this conversation as resolved.
Show resolved Hide resolved

import "github.com/databricks/cli/libs/jsonschema"

type Node struct {
Description string `json:"description,omitempty"`
Preview string `json:"x-databricks-preview,omitempty"`
Ref string `json:"$ref,omitempty"`

// Currently it is only defined for top level schemas
JsonPath string `json:"-"`
}

type Specification struct {
renaudhartert-db marked this conversation as resolved.
Show resolved Hide resolved
Node
Components *Components `json:"components"`
}

type Components struct {
Node
Parameters map[string]*Parameter `json:"parameters,omitempty"`
Responses map[string]*Body `json:"responses,omitempty"`
Schemas map[string]*jsonschema.Schema `json:"schemas,omitempty"`
}

type Parameter struct {
Node
Required bool `json:"required,omitempty"`
In string `json:"in,omitempty"`
Name string `json:"name,omitempty"`
MultiSegment bool `json:"x-databricks-multi-segment,omitempty"`
Schema *jsonschema.Schema `json:"schema,omitempty"`
}

type MediaType struct {
Node
Schema *jsonschema.Schema `json:"schema,omitempty"`
}

type MimeType string

const (
MimeTypeJson MimeType = "application/json"
MimeTypeOctetStream MimeType = "application/octet-stream"
MimeTypeTextPlain MimeType = "text/plain"
)

type Body struct {
Node
Required bool `json:"required,omitempty"`
Content map[string]MediaType `json:"content,omitempty"`
Headers map[string]*Parameter `json:"headers,omitempty"`
}
Loading