Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Removing package from namespace #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions deploy/lib/deployApiGw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions deploy/tests/deployApiGw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":"[email protected]_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')
Expand Down