Skip to content

Commit

Permalink
Changed HTTP Post Index
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBQu committed Nov 22, 2024
1 parent a61dcd7 commit 02c5c50
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 26 additions & 1 deletion docs/website/references/http/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -1245,7 +1270,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/index"
"$ref": "#/components/schemas/index_create_request"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion http/handler_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions http/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down

0 comments on commit 02c5c50

Please sign in to comment.