Skip to content

Commit e38a8fc

Browse files
committed
update diagnostic api docs
1 parent 0322417 commit e38a8fc

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

docs/api/paths/diagnostic/keyspace-sync.yaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,39 @@
77
# the file licenses/APL2.txt.
88
parameters:
99
- $ref: ../../components/parameters.yaml#/keyspace
10-
get:
10+
post:
1111
summary: Run a doc body through the sync function and return sync data.
1212
description: |-
13-
Run a document body through the sync function and return document sync data.
13+
Runs a document body through the sync function and returns document sync
14+
data. If no custom sync function is provided in the request body, the
15+
default or user-defined sync function for the collection is used.
16+
| Document | DocID | Behaviour |
17+
| -------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
18+
| Yes | No | The document passed will be considered as newDoc and oldDoc will be empty |
19+
| Yes | Yes | The document passed in the body will be newDoc and DocID will be read from the bucket/collection and will be passed as the oldDoc. If DocID doesn't exist, then oldDoc will be empty |
20+
| No | No | Will throw an error |
21+
| No | Yes | The docID will be passed in as the newDoc and oldDoc will be empty. If the document is not found, an error will be returned |
22+
1423
* Sync Gateway Application Read Only
1524
requestBody:
1625
content:
1726
application/json:
1827
schema:
19-
$ref: ../../components/schemas.yaml#/Document
28+
type: object
29+
properties:
30+
sync_function:
31+
description: |-
32+
A JavaScript function that defines custom access, channel, and
33+
validation logic for documents. This function will be evaluated
34+
by the Sync Gateway to determine document routing, access
35+
grants, and validation outcomes during synchronization.
36+
type: string
37+
example: |-
38+
function (doc, oldDoc) {
39+
channel(doc.channels);
40+
}
41+
doc:
42+
$ref: ../../components/schemas.yaml#/Document
2043
responses:
2144
'200':
2245
description: Document Processed by sync function successfully

rest/diagnostic_doc_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (h *handler) handleSyncFnDryRun() error {
8787
// Only require a valid JSON payload if docid is not provided.
8888
// If docid is provided, the sync function will use the document from the bucket, and the payload is optional.
8989
if err != nil && docid == "" {
90-
return base.HTTPErrorf(http.StatusUnprocessableEntity, "Error reading sync function payload: %v", err)
90+
return base.HTTPErrorf(http.StatusBadRequest, "Error reading sync function payload: %v", err)
9191
}
9292

9393
oldDoc := &db.Document{ID: docid}

rest/diagnostic_doc_api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ func TestSyncFuncDryRun(t *testing.T) {
11711171
existingDocID: "doc",
11721172
existingDocBody: `{"user":{"num":123, "name":["user1"]}, "channel":"channel1"}`,
11731173
expectedOutput: SyncFnDryRun{},
1174-
expectedStatus: http.StatusUnprocessableEntity,
1174+
expectedStatus: http.StatusBadRequest,
11751175
},
11761176
{
11771177
name: "test_case_12",

0 commit comments

Comments
 (0)