From 633f8c85002de38eea147e523274e8fb0cb8283a Mon Sep 17 00:00:00 2001 From: Hayden Date: Fri, 11 Oct 2024 14:01:16 +0700 Subject: [PATCH] fix: unwrap import parameter --- typesense/api/client_gen.go | 8 ++++---- typesense/api/generator/generator.yml | 8 ++++---- typesense/api/generator/main.go | 11 ++++++++++- typesense/api/generator/openapi.yml | 12 ++++-------- typesense/api/types_gen.go | 2 +- typesense/test/import_test.go | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/typesense/api/client_gen.go b/typesense/api/client_gen.go index 2695586..d6e94d1 100644 --- a/typesense/api/client_gen.go +++ b/typesense/api/client_gen.go @@ -2089,9 +2089,9 @@ func NewImportDocumentsRequestWithBody(server string, collectionName string, par } - if params.DirtyValues != nil { + if params.BatchSize != nil { - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "dirty_values", runtime.ParamLocationQuery, *params.DirtyValues); err != nil { + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "batch_size", runtime.ParamLocationQuery, *params.BatchSize); err != nil { return nil, err } else if parsed, err := url.ParseQuery(queryFrag); err != nil { return nil, err @@ -2105,9 +2105,9 @@ func NewImportDocumentsRequestWithBody(server string, collectionName string, par } - if params.BatchSize != nil { + if params.DirtyValues != nil { - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "batch_size", runtime.ParamLocationQuery, *params.BatchSize); err != nil { + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "dirty_values", runtime.ParamLocationQuery, *params.DirtyValues); err != nil { return nil, err } else if parsed, err := url.ParseQuery(queryFrag); err != nil { return nil, err diff --git a/typesense/api/generator/generator.yml b/typesense/api/generator/generator.yml index 804f2cf..4abad64 100644 --- a/typesense/api/generator/generator.yml +++ b/typesense/api/generator/generator.yml @@ -2242,14 +2242,14 @@ paths: name: action schema: $ref: '#/components/schemas/IndexAction' - - in: query - name: dirty_values - schema: - $ref: '#/components/schemas/DirtyValues' - in: query name: batch_size schema: type: integer + - in: query + name: dirty_values + schema: + $ref: '#/components/schemas/DirtyValues' - in: query name: remote_embedding_batch_size schema: diff --git a/typesense/api/generator/main.go b/typesense/api/generator/main.go index ced3ccc..470947b 100644 --- a/typesense/api/generator/main.go +++ b/typesense/api/generator/main.go @@ -190,7 +190,16 @@ func unwrapImportDocuments(m *yml) { newMap["name"] = obj.Key newMap["in"] = query newMap["schema"] = make(yml) - newMap["schema"].(yml)["type"] = obj.Value.(yml)["type"].(string) + switch { + // if the param is referencing a schema + case obj.Value.(yml)["type"] == nil: + newMap["schema"].(yml)["$ref"] = obj.Value.(yml)["$ref"].(string) + case obj.Value.(yml)["type"].(string) == array: + newMap["schema"].(yml)["type"] = array + newMap["schema"].(yml)["items"] = obj.Value.(yml)["items"] + default: + newMap["schema"].(yml)["type"] = obj.Value.(yml)["type"].(string) + } if obj.Value.(yml)["enum"] != nil { newMap["schema"].(yml)["enum"] = obj.Value.(yml)["enum"] } diff --git a/typesense/api/generator/openapi.yml b/typesense/api/generator/openapi.yml index 296c508..65b0702 100644 --- a/typesense/api/generator/openapi.yml +++ b/typesense/api/generator/openapi.yml @@ -744,14 +744,10 @@ paths: type: integer return_doc: type: boolean - - name: action - in: query - schema: - $ref: "#/components/schemas/IndexAction" - - name: dirty_values - in: query - schema: - $ref: "#/components/schemas/DirtyValues" + action: + $ref: "#/components/schemas/IndexAction" + dirty_values: + $ref: "#/components/schemas/DirtyValues" requestBody: description: The json array of documents or the JSONL file to import content: diff --git a/typesense/api/types_gen.go b/typesense/api/types_gen.go index b425961..5993c83 100644 --- a/typesense/api/types_gen.go +++ b/typesense/api/types_gen.go @@ -1361,8 +1361,8 @@ type ExportDocumentsParams struct { // ImportDocumentsParams defines parameters for ImportDocuments. type ImportDocumentsParams struct { Action *IndexAction `form:"action,omitempty" json:"action,omitempty"` - DirtyValues *DirtyValues `form:"dirty_values,omitempty" json:"dirty_values,omitempty"` BatchSize *int `form:"batch_size,omitempty" json:"batch_size,omitempty"` + DirtyValues *DirtyValues `form:"dirty_values,omitempty" json:"dirty_values,omitempty"` RemoteEmbeddingBatchSize *int `form:"remote_embedding_batch_size,omitempty" json:"remote_embedding_batch_size,omitempty"` ReturnDoc *bool `form:"return_doc,omitempty" json:"return_doc,omitempty"` ReturnId *bool `form:"return_id,omitempty" json:"return_id,omitempty"` diff --git a/typesense/test/import_test.go b/typesense/test/import_test.go index c30a21a..9cb5d91 100644 --- a/typesense/test/import_test.go +++ b/typesense/test/import_test.go @@ -29,7 +29,7 @@ func TestDocumentsImport(t *testing.T) { newDocument("127", withCompanyName("Company3")), } - params := &api.ImportDocumentsParams{Action: pointer.Any(api.Create)} + params := &api.ImportDocumentsParams{Action: pointer.Any(api.Create), DirtyValues: pointer.Any(api.CoerceOrDrop)} responses, err := typesenseClient.Collection(collectionName).Documents().Import(context.Background(), documents, params) require.NoError(t, err)