From 5a9aeb7949613e2f85d5d4e6154f4500ce776337 Mon Sep 17 00:00:00 2001 From: Evandro Pires da Silva Date: Sun, 3 May 2020 13:45:31 -0300 Subject: [PATCH] Removing package from namespace --- deploy/lib/deployApiGw.js | 7 ++++--- deploy/tests/deployApiGw.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/deploy/lib/deployApiGw.js b/deploy/lib/deployApiGw.js index 5548e06..81da377 100644 --- a/deploy/lib/deployApiGw.js +++ b/deploy/lib/deployApiGw.js @@ -34,14 +34,15 @@ module.exports = { const swaggerAction = operation['x-openwhisk'] const action = allActions.find(item => item.name === swaggerAction.action) - swaggerAction.namespace = action.namespace - swaggerAction.url = swaggerAction.url.replace(/web\/_/, `web/${action.namespace}`) + const namespace = `${action.namespace}`.replace(/\/.*/, '') + swaggerAction.namespace = namespace + swaggerAction.url = swaggerAction.url.replace(/web\/_/, `web/${namespace}`) const id = operation.operationId const stmts = swagger["x-ibm-configuration"].assembly.execute[0]['operation-switch'].case const stmt = stmts.find(stmt => stmt.operations[0] === id) const invoke = stmt.execute[stmt.execute.length -1].invoke - invoke['target-url'] = invoke['target-url'].replace(/web\/_/, `web/${action.namespace}`) + invoke['target-url'] = invoke['target-url'].replace(/web\/_/, `web/${namespace}`) } } } diff --git a/deploy/tests/deployApiGw.js b/deploy/tests/deployApiGw.js index 66a5b36..39e9714 100644 --- a/deploy/tests/deployApiGw.js +++ b/deploy/tests/deployApiGw.js @@ -72,6 +72,26 @@ describe('deployHttpEvents', () => { expect(result).to.be.deep.equal(converted) }) + it('should replace default namespace in swagger doc when namespace is with package', async () => { + const without_default_ns = fs.readFileSync('./deploy/tests/resources/swagger.json', 'utf-8') + const with_default_ns = fs.readFileSync('./deploy/tests/resources/swagger_default_ns.json', 'utf-8') + const source = JSON.parse(with_default_ns) + const converted = JSON.parse(without_default_ns) + + const actions = [{"name":"hello","namespace":"user@host.com_dev/default"}] + + sandbox.stub(openwhiskDeploy.provider, 'client', () => { + const list = params => { + return Promise.resolve(actions); + }; + + return Promise.resolve({ actions: { list } }); + }); + + let result = await openwhiskDeploy.replaceDefaultNamespace(source) + expect(result).to.be.deep.equal(converted) + }) + it('should return same swagger doc including path params', async () => { const without_default_ns = fs.readFileSync('./deploy/tests/resources/swagger_ns_paths.json', 'utf-8') const with_default_ns = fs.readFileSync('./deploy/tests/resources/swagger_paths.json', 'utf-8')