From e09b4ee08553105a26862faad342521a0775cbc9 Mon Sep 17 00:00:00 2001 From: Silas Boyd-Wickizer Date: Thu, 15 Mar 2018 18:24:56 -0700 Subject: [PATCH] feat(CustomResourceDefinitions): add support for watch paths (#233) --- lib/swagger-client.js | 33 +++++++++++++++++++-------------- test/swagger-client.test.js | 5 ++++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/swagger-client.js b/lib/swagger-client.js index 88bd5bda..8e333e43 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -155,31 +155,36 @@ class Component { const group = manifest.spec.group; const version = manifest.spec.version; const name = manifest.spec.names.plural; + const spec = { paths: {}}; // // Make just enough of Swagger spec to generate some useful endpoints. // const templatePath = `/apis/${ group }/${ version }/namespaces/{namespace}/${ name }/{name}`; - const templateOperations = ['delete', 'get', 'patch', 'post', 'put'].reduce((acc, method) => { - acc[method] = { - operationId: `${ method }${ name }` - }; + spec.paths[templatePath] = ['delete', 'get', 'patch', 'put'].reduce((acc, method) => { + acc[method] = { operationId: `${ method }Template${ name }` }; return acc; }, {}); const path = `/apis/${ group }/${ version }/namespaces/{namespace}/${ name }`; - const operations = { - get: { - operationId: `list${ name }` - } - }; + spec.paths[path] = ['get', 'post'].reduce((acc, method) => { + acc[method] = { operationId: `${ method }${ name }` }; + return acc; + }, {}); - const spec = { - paths: { - [path]: operations, - [templatePath]: templateOperations - } + const watchPaths = { + watchCluster: `/apis/${ group }/${ version }/watch/${ name }`, + watchNamespace: `/apis/${ group }/${ version }/namespaces/{namespace}/watch/${ name }`, + watchResource: `/apis/${ group }/${ version }/namespaces/{namespace}/watch/${ name }/{name}` }; + Object.keys(watchPaths).forEach(operationId => { + const watchPath = watchPaths[operationId]; + spec.paths[watchPath] = { + get: { + operationId: `operationId${ name }` + } + }; + }); this._addSpec(spec); } diff --git a/test/swagger-client.test.js b/test/swagger-client.test.js index e94e3423..4b59acd3 100644 --- a/test/swagger-client.test.js +++ b/test/swagger-client.test.js @@ -203,12 +203,15 @@ describe('lib.swagger-client', () => { }; client.addCustomResourceDefinition(crd); assume(client.apis['stable.example.com'].v1.namespaces('default').foos.get).is.a('function'); + assume(client.apis['stable.example.com'].v1.namespaces('default').foos.post).is.a('function'); assume(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').get).is.a('function'); assume(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').delete).is.a('function'); assume(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').get).is.a('function'); assume(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').patch).is.a('function'); - assume(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').post).is.a('function'); assume(client.apis['stable.example.com'].v1.namespaces('default').foos('blah').put).is.a('function'); + assume(client.apis['stable.example.com'].v1.watch.foos.getStream).is.a('function'); + assume(client.apis['stable.example.com'].v1.namespaces('default').watch.foos.getStream).is.a('function'); + assume(client.apis['stable.example.com'].v1.namespaces('default').watch.foos('blah').getStream).is.a('function'); }); }); });