From 2820d509afda13b1f3f74827e0950294d09420d0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:18:33 +0000 Subject: [PATCH 1/2] Bump github.com/getkin/kin-openapi from 0.123.0 to 0.125.0 Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.123.0 to 0.125.0. - [Release notes](https://github.com/getkin/kin-openapi/releases) - [Commits](https://github.com/getkin/kin-openapi/compare/v0.123.0...v0.125.0) --- updated-dependencies: - dependency-name: github.com/getkin/kin-openapi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index dfab16b..811a054 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/charmbracelet/bubbletea v0.24.2 github.com/charmbracelet/lipgloss v0.8.0 github.com/cli/browser v1.3.0 - github.com/getkin/kin-openapi v0.123.0 + github.com/getkin/kin-openapi v0.125.0 github.com/mattn/go-isatty v0.0.20 github.com/replicate/replicate-go v0.18.1 github.com/schollz/progressbar/v3 v3.13.1 diff --git a/go.sum b/go.sum index a79eb14..d4de14f 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= -github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8= -github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= +github.com/getkin/kin-openapi v0.125.0 h1:jyQCyf2qXS1qvs2U00xQzkGCqYPhEhZDmSmVt65fXno= +github.com/getkin/kin-openapi v0.125.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q= github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs= github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw= From 5e8ed5bcbf5bad422b7cc489f2f3fbc90801432f Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 17 Jun 2024 10:59:50 -0700 Subject: [PATCH 2/2] Update to new kin-openapi APIs --- internal/cmd/model/schema.go | 2 +- internal/cmd/prediction/create.go | 4 +-- internal/util/schema.go | 42 +++++++++++++++++-------------- internal/util/util_test.go | 14 +++++------ 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/internal/cmd/model/schema.go b/internal/cmd/model/schema.go index c0995f2..e69ffab 100644 --- a/internal/cmd/model/schema.go +++ b/internal/cmd/model/schema.go @@ -93,7 +93,7 @@ func printModelVersionSchema(version *replicate.ModelVersion) error { if outputSchema != nil { fmt.Println("Output:") fmt.Printf("- type: %s\n", outputSchema.Type) - if outputSchema.Type == "array" { + if outputSchema.Type.Is("array") { fmt.Printf("- items: %s %s\n", outputSchema.Items.Value.Type, outputSchema.Items.Value.Format) } fmt.Println() diff --git a/internal/cmd/prediction/create.go b/internal/cmd/prediction/create.go index 52b6d1b..3e4c2d4 100644 --- a/internal/cmd/prediction/create.go +++ b/internal/cmd/prediction/create.go @@ -82,8 +82,8 @@ var CreateCmd = &cobra.Command{ shouldWait := (cmd.Flags().Changed("wait") || !cmd.Flags().Changed("no-wait")) canStream := (outputSchema != nil && - outputSchema.Type == "array" && - outputSchema.Items.Value.Type == "string" && + outputSchema.Type.Is("array") && + outputSchema.Items.Value.Type.Is("string") && outputSchema.Extensions["x-cog-array-type"] == "iterator" && outputSchema.Extensions["x-cog-array-display"] == "concatenate") shouldStream := canStream && !cmd.Flags().Changed("wait") && diff --git a/internal/util/schema.go b/internal/util/schema.go index 2b00b52..c074aec 100644 --- a/internal/util/schema.go +++ b/internal/util/schema.go @@ -99,16 +99,19 @@ func coerceType(input string, schema *openapi3.Schema) (interface{}, error) { return input, nil } - switch schema.Type { - case "integer": + if schema.Type.Is("integer") { return convertToInt(input) - case "number": + } + if schema.Type.Is("number") { return convertToFloat(input) - case "boolean": + } + if schema.Type.Is("boolean") { return convertToBool(input) - case "string": + } + if schema.Type.Is("string") { return convertToString(input) - case "array": + } + if schema.Type.Is("array") { var value []interface{} err := json.Unmarshal([]byte(input), &value) if err != nil { @@ -130,21 +133,22 @@ func coerceType(input string, schema *openapi3.Schema) (interface{}, error) { } return value, nil - default: - // If the property has a default value, attempt to convert to that type - switch schema.Default.(type) { - case int: - return convertToInt(input) - case float64: - return convertToFloat(input) - case bool: - return convertToBool(input) - case string: - return convertToString(input) - } + } - return nil, fmt.Errorf("unknown type %s", schema.Type) + // If the property has a default value, attempt to convert to that type + switch schema.Default.(type) { + case int: + return convertToInt(input) + case float64: + return convertToFloat(input) + case bool: + return convertToBool(input) + case string: + return convertToString(input) } + + return nil, fmt.Errorf("unknown type %s", schema.Type) + } // convertToString is a no-op diff --git a/internal/util/util_test.go b/internal/util/util_test.go index 4ab3642..c9bdb92 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -94,34 +94,34 @@ func TestParseInputs(t *testing.T) { func TestCoerceTypesWithSchema(t *testing.T) { schema := openapi3.NewSchema() - schema.Type = "object" + schema.Type = &openapi3.Types{openapi3.TypeObject} schema.Properties = map[string]*openapi3.SchemaRef{ "integer": { Value: &openapi3.Schema{ - Type: "integer", + Type: &openapi3.Types{openapi3.TypeInteger}, }, }, "number": { Value: &openapi3.Schema{ - Type: "number", + Type: &openapi3.Types{openapi3.TypeNumber}, }, }, "boolean": { Value: &openapi3.Schema{ - Type: "boolean", + Type: &openapi3.Types{openapi3.TypeBoolean}, }, }, "string": { Value: &openapi3.Schema{ - Type: "string", + Type: &openapi3.Types{openapi3.TypeString}, }, }, "array_of_integers": { Value: &openapi3.Schema{ - Type: "array", + Type: &openapi3.Types{openapi3.TypeArray}, Items: &openapi3.SchemaRef{ Value: &openapi3.Schema{ - Type: "integer", + Type: &openapi3.Types{openapi3.TypeInteger}, }, }, },