From 456edbb5805c40e92096a4f84cada47caa26e1d6 Mon Sep 17 00:00:00 2001 From: Tor Colvin Date: Tue, 6 Aug 2024 16:06:01 -0400 Subject: [PATCH] add public-capella target create decorators to do munging in https://github.com/couchbase/docs-capella/pull/58 --- .redocly.yaml | 11 ++++++- docs/api/admin-capella.yaml | 4 +-- docs/api/metric-capella.yaml | 4 +-- .../plugins/decorators/excise-rbac-capella.js | 32 +++++++++++++++++++ .../decorators/replace-description-capella.js | 30 +++++++++++++++++ .../decorators/replace-info-capella.js | 31 ++++++++++++++++++ .../decorators/replace-server-capella.js | 24 ++++++++++++++ .../decorators/replace-servers-capella.js | 9 ------ docs/api/plugins/plugin.js | 31 ++++++++++++------ docs/api/public.yaml | 1 + docs/api/replace-servers-capella.js | 10 ++++++ 11 files changed, 164 insertions(+), 23 deletions(-) create mode 100644 docs/api/plugins/decorators/excise-rbac-capella.js create mode 100644 docs/api/plugins/decorators/replace-description-capella.js create mode 100644 docs/api/plugins/decorators/replace-info-capella.js create mode 100644 docs/api/plugins/decorators/replace-server-capella.js delete mode 100644 docs/api/plugins/decorators/replace-servers-capella.js diff --git a/.redocly.yaml b/.redocly.yaml index 35cdc76909..f0318ba1ce 100644 --- a/.redocly.yaml +++ b/.redocly.yaml @@ -17,6 +17,8 @@ apis: root: "./docs/api/admin.yaml" admin-capella: root: "./docs/api/admin-capella.yaml" + decorators: + remove-x-internal: on public: root: "./docs/api/public.yaml" decorators: @@ -26,11 +28,14 @@ apis: public-capella: root: "./docs/api/public.yaml" decorators: + remove-x-internal: on filter-out: property: x-capella value: false - plugin/replace-servers-capella: + plugin/replace-server-capella: serverUrl: 'https://{hostname}:4984' + plugin/replace-info-capella: + title: "App Services Public API" metric: root: "./docs/api/metric.yaml" decorators: @@ -39,6 +44,10 @@ apis: root: "./docs/api/metric.yaml" metric-capella: root: "./docs/api/metric-capella.yaml" + decorators: + plugin/excise-rbac-capella: on + plugin/replace-description-capella: on + remove-x-internal: on diagnostic: root: "./docs/api/diagnostic.yaml" decorators: diff --git a/docs/api/admin-capella.yaml b/docs/api/admin-capella.yaml index 425f756975..8042a4f19b 100644 --- a/docs/api/admin-capella.yaml +++ b/docs/api/admin-capella.yaml @@ -8,8 +8,8 @@ openapi: 3.0.3 info: - title: Sync Gateway - description: Sync Gateway manages access and synchronization between Couchbase Lite and Couchbase Server + title: App Services Admin API + description: 'App Services manages access and synchronization between Couchbase Lite and Couchbase Capella' version: 3.3.0 license: name: Business Source License 1.1 (BSL) diff --git a/docs/api/metric-capella.yaml b/docs/api/metric-capella.yaml index d8446432f6..286ff63913 100644 --- a/docs/api/metric-capella.yaml +++ b/docs/api/metric-capella.yaml @@ -8,8 +8,8 @@ openapi: 3.0.3 info: - title: Sync Gateway - description: Sync Gateway manages access and synchronization between Couchbase Lite and Couchbase Server + title: App Services Metrics API + description: 'App Services manages access and synchronization between Couchbase Lite and Couchbase Capella' version: 3.3.0 license: name: Business Source License 1.1 (BSL) diff --git a/docs/api/plugins/decorators/excise-rbac-capella.js b/docs/api/plugins/decorators/excise-rbac-capella.js new file mode 100644 index 0000000000..49a9be4078 --- /dev/null +++ b/docs/api/plugins/decorators/excise-rbac-capella.js @@ -0,0 +1,32 @@ +/** + * Copyright 2024-Present Couchbase, Inc. + * + * Use of this software is governed by the Business Source License included + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified + * in that file, in accordance with the Business Source License, use of this + * software will be governed by the Apache License, Version 2.0, included in + * the file licenses/APL2.txt. + */ + +/** + * Removes the RBAC roles from capella API docs. This expects the RBAC information to be at the end of the documentation string. This is not a robust way of doing this. + * @module ExciseRBACCapella + */ + +module.exports = ExciseRBACCapella; + +const re = new RegExp("Required Sync Gateway RBAC roles"); + +/** @type {import('@redocly/cli').OasDecorator} */ +function ExciseRBACCapella() { + return { + Operation: { + leave(Operation) { + idx = Operation.description.search(re); + if (idx > 0) { + Operation.description = Operation.description.substr(0, idx); + } + }, + }, + }; +} diff --git a/docs/api/plugins/decorators/replace-description-capella.js b/docs/api/plugins/decorators/replace-description-capella.js new file mode 100644 index 0000000000..252d3947fb --- /dev/null +++ b/docs/api/plugins/decorators/replace-description-capella.js @@ -0,0 +1,30 @@ +/** + * Copyright 2024-Present Couchbase, Inc. + * + * Use of this software is governed by the Business Source License included + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified + * in that file, in accordance with the Business Source License, use of this + * software will be governed by the Apache License, Version 2.0, included in + * the file licenses/APL2.txt. + */ + +/** + * Does a string replacement on all operations (GET,PUT,POST,etc) to replace Sync Gateway with App Services. + * @module ReplaceDescriptionCapella + */ + +module.exports = ReplaceDescriptionCapella; + +/** @type {import('@redocly/cli').OasDecorator} */ +function ReplaceDescriptionCapella() { + return { + Operation: { + leave(Operation) { + Operation.description = Operation.description.replace( + "Sync Gateway", + "App Services", + ); + }, + }, + }; +} diff --git a/docs/api/plugins/decorators/replace-info-capella.js b/docs/api/plugins/decorators/replace-info-capella.js new file mode 100644 index 0000000000..189f804a04 --- /dev/null +++ b/docs/api/plugins/decorators/replace-info-capella.js @@ -0,0 +1,31 @@ +/** + * Copyright 2024-Present Couchbase, Inc. + * + * Use of this software is governed by the Business Source License included + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified + * in that file, in accordance with the Business Source License, use of this + * software will be governed by the Apache License, Version 2.0, included in + * the file licenses/APL2.txt. + */ + +/** + * Modifies the title of openapi object to value passed in. + * @module ReplaceInfoCapella + */ + +module.exports = ReplaceInfoCapella; + +/** @type {import('@redocly/cli').OasDecorator} */ +function ReplaceInfoCapella({ title }) { + return { + Info: { + leave(Info) { + if (title) { + Info.title = title; + } + Info.description = + "App Services manages access and synchronization between Couchbase Lite and Couchbase Capella"; + }, + }, + }; +} diff --git a/docs/api/plugins/decorators/replace-server-capella.js b/docs/api/plugins/decorators/replace-server-capella.js new file mode 100644 index 0000000000..6bd4808a38 --- /dev/null +++ b/docs/api/plugins/decorators/replace-server-capella.js @@ -0,0 +1,24 @@ +/** + * Copyright 2024-Present Couchbase, Inc. + * + * Use of this software is governed by the Business Source License included + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified + * in that file, in accordance with the Business Source License, use of this + * software will be governed by the Apache License, Version 2.0, included in + * the file licenses/APL2.txt. + */ + +module.exports = ReplaceServersCapella; + +/** @type {import('@redocly/cli').OasDecorator} */ +function ReplaceServersCapella({ serverUrl }) { + return { + Server: { + leave(Server) { + if (serverUrl) { + Server.url = serverUrl; + } + }, + }, + }; +} diff --git a/docs/api/plugins/decorators/replace-servers-capella.js b/docs/api/plugins/decorators/replace-servers-capella.js deleted file mode 100644 index 1d77ba1c16..0000000000 --- a/docs/api/plugins/decorators/replace-servers-capella.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = ReplaceServersCapella; -require("console"); -/** @type {import('@redocly/cli').OasDecorator} */ - -function ReplaceServersCapella({ serverUrl }) { - return Server: { - leave(Server) - }; -} diff --git a/docs/api/plugins/plugin.js b/docs/api/plugins/plugin.js index 503c44d899..2e422b5248 100644 --- a/docs/api/plugins/plugin.js +++ b/docs/api/plugins/plugin.js @@ -1,13 +1,26 @@ -const ReplaceServersCapella = import("./decorators/replace-servers-capella.js"); -const id = "plugin"; +/** + * Copyright 2024-Present Couchbase, Inc. + * + * Use of this software is governed by the Business Source License included + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified + * in that file, in accordance with the Business Source License, use of this + * software will be governed by the Apache License, Version 2.0, included in + * the file licenses/APL2.txt. + */ -const decorators = { - oas3: { - "replace-servers-capella": ReplaceServersCapella, - }, -}; +const ExciseRBACCapella = require("./decorators/excise-rbac-capella.js"); +const ReplaceDescriptionCapella = require("./decorators/replace-description-capella.js"); +const ReplaceInfoCapella = require("./decorators/replace-info-capella.js"); +const ReplaceServerCapella = require("./decorators/replace-server-capella.js"); module.exports = { - decorators, - id, + decorators: { + oas3: { + "excise-rbac-capella": ExciseRBACCapella, + "replace-description-capella": ReplaceDescriptionCapella, + "replace-info-capella": ReplaceInfoCapella, + "replace-server-capella": ReplaceServerCapella, + }, + }, + id: "plugin", }; diff --git a/docs/api/public.yaml b/docs/api/public.yaml index bddbc57a05..faba4520bb 100644 --- a/docs/api/public.yaml +++ b/docs/api/public.yaml @@ -103,6 +103,7 @@ tags: description: Create and manage document attachments - name: Replication description: Create and manage inter-Sync Gateway replications + x-capella: false - name: Unsupported description: Endpoints that are not supported by Sync Gateway x-capella: false diff --git a/docs/api/replace-servers-capella.js b/docs/api/replace-servers-capella.js index 493037b7f5..7bbadb9f1d 100644 --- a/docs/api/replace-servers-capella.js +++ b/docs/api/replace-servers-capella.js @@ -1,3 +1,13 @@ +/** + * Copyright 2024-Present Couchbase, Inc. + * + * Use of this software is governed by the Business Source License included + * in the file licenses/BSL-Couchbase.txt. As of the Change Date specified + * in that file, in accordance with the Business Source License, use of this + * software will be governed by the Apache License, Version 2.0, included in + * the file licenses/APL2.txt. + */ + module.exports = ReplaceServersCapella; /** @type {import('@redocly/cli').OasDecorator} */