From 02c5c504b5fda7bcd8ac6a1cacf6a3920b6cbffb Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Fri, 22 Nov 2024 12:31:12 -0500 Subject: [PATCH] Changed HTTP Post Index --- client/index.go | 12 ++++++++++ docs/website/references/http/openapi.json | 27 ++++++++++++++++++++++- http/handler_collection.go | 5 ++++- http/openapi.go | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/client/index.go b/client/index.go index b09b258224..03da11ee81 100644 --- a/client/index.go +++ b/client/index.go @@ -36,6 +36,18 @@ type IndexDescription struct { Unique bool } +// IndexCreateRequestDescription describes an index creation request. +// It does not contain the ID, as it is not a valid field for the request body. +// Instead it should be automatically generated. +type IndexCreateRequestDescription struct { + // Name contains the name of the index. + Name string + // Fields contains the fields that are being indexed. + Fields []IndexedFieldDescription + // Unique indicates whether the index is unique. + Unique bool +} + // CollectionIndex is an interface for indexing documents in a collection. type CollectionIndex interface { // Save indexes a document by storing indexed field values. diff --git a/docs/website/references/http/openapi.json b/docs/website/references/http/openapi.json index 1f28b84a92..c5c9fbc7b2 100644 --- a/docs/website/references/http/openapi.json +++ b/docs/website/references/http/openapi.json @@ -442,6 +442,31 @@ }, "type": "object" }, + "index_create_request": { + "properties": { + "Fields": { + "items": { + "properties": { + "Descending": { + "type": "boolean" + }, + "Name": { + "type": "string" + } + }, + "type": "object" + }, + "type": "array" + }, + "Name": { + "type": "string" + }, + "Unique": { + "type": "boolean" + } + }, + "type": "object" + }, "lens_config": { "properties": { "DestinationSchemaVersionID": { @@ -1245,7 +1270,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/index" + "$ref": "#/components/schemas/index_create_request" } } }, diff --git a/http/handler_collection.go b/http/handler_collection.go index ddade699e3..7b1d1a8a83 100644 --- a/http/handler_collection.go +++ b/http/handler_collection.go @@ -318,6 +318,9 @@ func (h *collectionHandler) bindRoutes(router *Router) { indexSchema := &openapi3.SchemaRef{ Ref: "#/components/schemas/index", } + indexCreateRequestSchema := &openapi3.SchemaRef{ + Ref: "#/components/schemas/index_create_request", + } collectionNamePathParam := openapi3.NewPathParameter("name"). WithDescription("Collection name"). @@ -389,7 +392,7 @@ func (h *collectionHandler) bindRoutes(router *Router) { createIndexRequest := openapi3.NewRequestBody(). WithRequired(true). - WithContent(openapi3.NewContentWithJSONSchemaRef(indexSchema)) + WithContent(openapi3.NewContentWithJSONSchemaRef(indexCreateRequestSchema)) createIndexResponse := openapi3.NewResponse(). WithDescription("Index description"). WithJSONSchemaRef(indexSchema) diff --git a/http/openapi.go b/http/openapi.go index b217036182..7695e0d55d 100644 --- a/http/openapi.go +++ b/http/openapi.go @@ -32,6 +32,7 @@ var openApiSchemas = map[string]any{ "schema": &client.SchemaDescription{}, "collection_definition": &client.CollectionDefinition{}, "index": &client.IndexDescription{}, + "index_create_request": &client.IndexCreateRequestDescription{}, "delete_result": &client.DeleteResult{}, "update_result": &client.UpdateResult{}, "lens_config": &client.LensConfig{},