From 52121bc4667b82b617dbacd882b84bf23b2b7ddf Mon Sep 17 00:00:00 2001 From: Lukasz Czajczyk Date: Mon, 2 Jan 2023 17:40:43 +0100 Subject: [PATCH] Support for multiple macros on the same page Hi, the current design assumes there is only one hardcoded swagger-ui div per page. When the macro is used multiple times, the content goes always to the 1st div. This proposed change is to parametrize the div name and script name using a simple global counter. --- lib/swagger-ui-block-macro.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/swagger-ui-block-macro.js b/lib/swagger-ui-block-macro.js index b8f8c68740..e1c8b859a5 100644 --- a/lib/swagger-ui-block-macro.js +++ b/lib/swagger-ui-block-macro.js @@ -1,7 +1,7 @@ -const buildSwaggerUi = ({ specUrl, bundleUrl }) => ` +const buildSwaggerUi = ({ specUrl, bundleUrl, divID }) => ` -` +var divID = 0; + function blockSwaggerUiMacro ({ file }) { return function () { this.process((parent, specUrl, attrs) => { @@ -64,9 +66,10 @@ function blockSwaggerUiMacro ({ file }) { const bundleUrl = specUrl.startsWith('https://s3.amazonaws.com/cb-docs-swagger/') ? 'https://cb-docs-swagger.s3.amazonaws.com/dist3' : 'https://couchbase-docs.s3.amazonaws.com/assets/swagger-ui-3.7' - const contentScripts = buildSwaggerUi({ specUrl, bundleUrl }) - file.asciidoc.attributes['page-content-scripts'] = contentScripts - return this.createBlock(parent, 'pass', '
') + divID++ + const contentScripts = buildSwaggerUi({ specUrl, bundleUrl, divID }) + file.asciidoc.attributes['page-content-scripts'] += contentScripts + return this.createBlock(parent, 'pass', '
') }) } }