Skip to content

Commit a3a19af

Browse files
bbrksCopilot
andauthored
CBG-4750: Remove show_cv parameter and always return _cv in documents on REST API (#7654)
Co-authored-by: Copilot <[email protected]>
1 parent 9b4f99b commit a3a19af

13 files changed

+79
-66
lines changed

db/revision.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Body map[string]interface{}
2727
const (
2828
BodyDeleted = "_deleted"
2929
BodyRev = "_rev"
30+
BodyCV = "_cv"
3031
BodyId = "_id"
3132
BodyRevisions = "_revisions"
3233
BodyAttachments = "_attachments"

db/revision_cache_interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (rev *DocumentRevision) Mutable1xBody(ctx context.Context, db *DatabaseColl
301301
}
302302

303303
if showCV && rev.CV != nil {
304-
b["_cv"] = rev.CV.String()
304+
b[BodyCV] = rev.CV.String()
305305
}
306306

307307
if rev.Deleted {

docs/api/paths/admin/keyspace-docid.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ get:
2121
- $ref: ../../components/parameters.yaml#/rev
2222
- $ref: ../../components/parameters.yaml#/open_revs
2323
- $ref: ../../components/parameters.yaml#/show_exp
24-
- $ref: ../../components/parameters.yaml#/show_cv
2524
- $ref: ../../components/parameters.yaml#/revs_from
2625
- $ref: ../../components/parameters.yaml#/atts_since
2726
- $ref: ../../components/parameters.yaml#/revs_limit

docs/api/paths/public/keyspace-docid.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ get:
1515
- $ref: ../../components/parameters.yaml#/rev
1616
- $ref: ../../components/parameters.yaml#/open_revs
1717
- $ref: ../../components/parameters.yaml#/show_exp
18-
- $ref: ../../components/parameters.yaml#/show_cv
1918
- $ref: ../../components/parameters.yaml#/revs_from
2019
- $ref: ../../components/parameters.yaml#/atts_since
2120
- $ref: ../../components/parameters.yaml#/revs_limit

rest/api_collections_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,32 @@ func TestNoCollectionsPutDocWithKeyspace(t *testing.T) {
184184
})
185185
defer rt.Close()
186186

187+
const docBody = `{"foo":"bar"}`
188+
187189
// can't put doc into invalid keyspaces
188-
response := rt.SendAdminRequest("PUT", "/db.invalidScope.invalidCollection/doc1", "{}")
190+
response := rt.SendAdminRequest(http.MethodPut, "/db.invalidScope.invalidCollection/doc1", docBody)
189191
RequireStatus(t, response, http.StatusNotFound)
190192

191-
response = rt.SendAdminRequest("PUT", "/db.invalidCollection/doc1", "{}")
193+
response = rt.SendAdminRequest(http.MethodPut, "/db.invalidCollection/doc1", docBody)
192194
RequireStatus(t, response, http.StatusNotFound)
193195

194196
// can put doc into _default scope/collection explicitly ... or implicitly (tested elsewhere e.g: TestPutEmptyDoc)
195-
response = rt.SendAdminRequest("PUT", "/db._default._default/doc1", "{}")
197+
response = rt.SendAdminRequest(http.MethodPut, "/db._default._default/doc1", docBody)
196198
RequireStatus(t, response, http.StatusCreated)
197199

198-
// retrieve doc in both ways (_default._default and no fully-qualified keyspace)
199-
response = rt.SendAdminRequest("GET", "/db._default._default/doc1", "")
200-
RequireStatus(t, response, http.StatusOK)
201-
assert.Equal(t, `{"_id":"doc1","_rev":"1-ca9ad22802b66f662ff171f226211d5c"}`, string(response.BodyBytes()))
202-
203-
response = rt.SendAdminRequest("GET", "/db/doc1", "")
204-
RequireStatus(t, response, http.StatusOK)
205-
assert.Equal(t, `{"_id":"doc1","_rev":"1-ca9ad22802b66f662ff171f226211d5c"}`, string(response.BodyBytes()))
200+
version, _ := rt.GetDoc("doc1")
201+
202+
// retrieve doc in both ways (explicit and implicit _default scope/collection)
203+
for _, keyspace := range []string{
204+
"db._default._default", // fully qualified
205+
"db", // implicit
206+
} {
207+
body := rt.GetDocBodyFromKeyspace(keyspace, "doc1")
208+
assert.Equal(t, "bar", body["foo"])
209+
assert.Equal(t, "doc1", body["_id"])
210+
assert.Equal(t, version.RevTreeID, body["_rev"])
211+
assert.Equal(t, version.CV.String(), body["_cv"])
212+
}
206213
}
207214

208215
func TestSingleCollectionDCP(t *testing.T) {

rest/api_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,19 +2349,22 @@ func TestPutEmptyDoc(t *testing.T) {
23492349
rt := NewRestTester(t, nil)
23502350
defer rt.Close()
23512351

2352-
response := rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc", "{}")
2352+
const docID = "doc"
2353+
2354+
response := rt.SendAdminRequest("PUT", "/{{.keyspace}}/"+docID, "{}")
23532355
RequireStatus(t, response, http.StatusCreated)
23542356

2355-
response = rt.SendAdminRequest("GET", "/{{.keyspace}}/doc", "")
2356-
RequireStatus(t, response, http.StatusOK)
2357-
assert.Equal(t, `{"_id":"doc","_rev":"1-ca9ad22802b66f662ff171f226211d5c"}`, string(response.BodyBytes()))
2357+
body := rt.GetDocBody(docID)
2358+
assert.NotEmpty(t, body[db.BodyId])
2359+
assert.NotEmpty(t, body[db.BodyRev])
23582360

2359-
response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc?rev=1-ca9ad22802b66f662ff171f226211d5c", `{"val": "newval"}`)
2361+
response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/"+docID+"?rev="+body[db.BodyRev].(string), `{"val": "newval"}`)
23602362
RequireStatus(t, response, http.StatusCreated)
23612363

2362-
response = rt.SendAdminRequest("GET", "/{{.keyspace}}/doc", "")
2363-
RequireStatus(t, response, http.StatusOK)
2364-
assert.Equal(t, `{"_id":"doc","_rev":"2-2f981cadffde70e8a1d9dc386a410e0d","val":"newval"}`, string(response.BodyBytes()))
2364+
body = rt.GetDocBody(docID)
2365+
assert.NotEmpty(t, body[db.BodyId])
2366+
assert.NotEmpty(t, body[db.BodyRev])
2367+
assert.Equal(t, "newval", body["val"].(string))
23652368
}
23662369

23672370
func TestTombstonedBulkDocs(t *testing.T) {

rest/attachment_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ func TestManualAttachmentNewDoc(t *testing.T) {
400400
response = rt.SendAdminRequest("GET", "/{{.keyspace}}/notexistyet", "")
401401
RequireStatus(t, response, 200)
402402
require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body))
403-
// body should only have 3 top-level entries _id, _rev, _attachments
404-
base.RequireKeysEqual(t, []string{"_id", "_rev", "_attachments"}, body)
403+
// body should only have metadata entries - no actual document body contents
404+
base.RequireKeysEqual(t, []string{db.BodyCV, db.BodyId, db.BodyRev, db.BodyAttachments}, body)
405405
require.Equal(t, db.AttachmentMap{
406406
"attach1": {
407407
ContentType: "text/plain",
@@ -2978,6 +2978,7 @@ func TestBlipPushRevWithAttachment(t *testing.T) {
29782978
},
29792979
"_id": docID,
29802980
"_rev": rtVersion.RevTreeID,
2981+
"_cv": rtVersion.CV.String(),
29812982
}, body)
29822983

29832984
response := rt.SendAdminRequest(http.MethodGet, fmt.Sprintf("/{{.keyspace}}/%s/%s", docID, attachmentName), "")

rest/blip_api_delta_sync_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ func TestBlipDeltaSyncNewAttachmentPull(t *testing.T) {
356356
assert.Equal(t, doc1ID, respBody[db.BodyId])
357357
require.Equal(t, db.Body{
358358
"_id": doc1ID,
359-
"_rev": "2-10000d5ec533b29b117e60274b1e3653",
359+
"_rev": version2.RevTreeID,
360+
"_cv": version2.CV.String(),
360361
"greetings": []any{
361362
map[string]any{"hello": "world!"},
362363
map[string]any{"hi": "alice"},

rest/bootstrap_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ func TestBootstrapRESTAPISetup(t *testing.T) {
7272
require.Equal(t, uint32(1234), *dbConfigResp.CacheConfig.RevCacheConfig.MaxItemCount)
7373

7474
// Sanity check to use the database
75+
resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/doc1", ``)
76+
resp.RequireStatus(http.StatusNotFound)
7577
resp = BootstrapAdminRequest(t, sc, http.MethodPut, "/db1/doc1", `{"foo":"bar"}`)
7678
resp.RequireResponse(http.StatusCreated, `{"id":"doc1","ok":true,"rev":"1-cd809becc169215072fd567eebd8b8de"}`)
7779
resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/doc1", ``)
78-
resp.RequireResponse(http.StatusOK, `{"_id":"doc1","_rev":"1-cd809becc169215072fd567eebd8b8de","foo":"bar"}`)
80+
resp.RequireStatus(http.StatusOK)
81+
assert.Contains(t, resp.Body, `"foo":"bar"`)
7982

8083
// Restart Sync Gateway
8184
closeFn()
@@ -107,7 +110,8 @@ func TestBootstrapRESTAPISetup(t *testing.T) {
107110

108111
// Ensure it's _actually_ the same bucket
109112
resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/doc1", ``)
110-
resp.RequireResponse(http.StatusOK, `{"_id":"doc1","_rev":"1-cd809becc169215072fd567eebd8b8de","foo":"bar"}`)
113+
resp.RequireStatus(http.StatusOK)
114+
assert.Contains(t, resp.Body, `"foo":"bar"`)
111115
}
112116

113117
// TestBootstrapDuplicateBucket will attempt to create two databases sharing the same collections and ensure this isn't allowed.

rest/bulk_api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ func (h *handler) handleBulkGet() error {
479479
HistoryFrom: revsFrom,
480480
AttachmentsSince: attsSince,
481481
ShowExp: showExp,
482-
ShowCV: showCV})
482+
ShowCV: showCV,
483+
})
483484
}
484485

485486
if err != nil {

0 commit comments

Comments
 (0)