Skip to content

Commit 4220847

Browse files
authored
Merge pull request #121 from zotoio/feat/openapi
feat(codegen): switch from swagger.yaml to openapi.json
2 parents 946906a + b9e57da commit 4220847

13 files changed

+29231
-1008
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ cache:
55
notifications:
66
email: false
77
node_js:
8-
- '12'
9-
before_install: npm install -g greenkeeper-lockfile@1 yarn
8+
- '14'
109
before_script:
11-
- greenkeeper-lockfile-update
1210
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
1311
- chmod +x ./cc-test-reporter
1412
- ./cc-test-reporter before-build
1513
install: yarn
1614
after_script:
17-
- greenkeeper-lockfile-upload
1815
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
1916
after_success:
2017
- yarn semantic-release

API.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
**Kind**: global class
2424
<a name="LaunchDarklyApiClient.create"></a>
2525

26-
### LaunchDarklyApiClient.create(API_TOKEN, log, swaggerYamlString) ⇒ <code>Promise</code>
26+
### LaunchDarklyApiClient.create(API_TOKEN, log, openapiJsonString) ⇒ <code>Promise</code>
2727
Used internally by LaunchDarklyUtils to create an instance of
2828
Swagger apiClient with interceptors configured
2929

@@ -35,7 +35,7 @@ Swagger apiClient with interceptors configured
3535
| --- | --- | --- |
3636
| API_TOKEN | <code>string</code> | from LaunchDarkly dashboard |
3737
| log | <code>Object</code> | logger implementation |
38-
| swaggerYamlString | <code>string</code> | optional serialized yaml |
38+
| openapiJsonString | <code>string</code> | optional serialized json |
3939

4040
<a name="LaunchDarklyLogger"></a>
4141

@@ -78,7 +78,7 @@ as api grouping util classes are attached to this class.
7878
* [.getFeatureFlags(projectKey)](#LaunchDarklyUtilsFlags+getFeatureFlags) ⇒ <code>Promise</code>
7979
* [.getFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery)](#LaunchDarklyUtilsFlags+getFeatureFlag) ⇒ <code>Promise</code>
8080
* [.getFeatureFlagState(projectKey, featureFlagKey, environmentKeyQuery)](#LaunchDarklyUtilsFlags+getFeatureFlagState) ⇒ <code>Promise</code>
81-
* [.updateFeatureFlag(projectKey, featureFlagKey, patchComment)](#LaunchDarklyUtilsFlags+updateFeatureFlag) ⇒ <code>Promise</code>
81+
* [.updateFeatureFlag(projectKey, featureFlagKey, patch)](#LaunchDarklyUtilsFlags+updateFeatureFlag) ⇒ <code>Promise</code>
8282
* [.toggleFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery, value)](#LaunchDarklyUtilsFlags+toggleFeatureFlag) ⇒ <code>Promise</code>
8383
* [.migrateFeatureFlag(projectKey, featureFlagKey, fromEnv, toEnv, includeState)](#LaunchDarklyUtilsFlags+migrateFeatureFlag) ⇒ <code>Promise</code>
8484
* [.bulkMigrateFeatureFlags(projectKey, featureFlagKeys, fromEnv, toEnv, includeState)](#LaunchDarklyUtilsFlags+bulkMigrateFeatureFlags) ⇒ <code>Promise</code>
@@ -160,7 +160,7 @@ ldutils getFeatureFlagState my-project my-flag dev
160160
```
161161
<a name="LaunchDarklyUtilsFlags+updateFeatureFlag"></a>
162162

163-
### launchDarklyUtilsFlags.updateFeatureFlag(projectKey, featureFlagKey, patchComment) ⇒ <code>Promise</code>
163+
### launchDarklyUtilsFlags.updateFeatureFlag(projectKey, featureFlagKey, patch) ⇒ <code>Promise</code>
164164
patch a feature flag by key
165165

166166
**Kind**: instance method of [<code>LaunchDarklyUtilsFlags</code>](#LaunchDarklyUtilsFlags)
@@ -171,7 +171,7 @@ patch a feature flag by key
171171
| --- | --- | --- |
172172
| projectKey | <code>string</code> | project identifier |
173173
| featureFlagKey | <code>string</code> | feature flag identifier |
174-
| patchComment | <code>Array.&lt;Object&gt;</code> | array of valid json patch descriptors |
174+
| patch | <code>Array.&lt;Object&gt;</code> | array of valid json patch descriptors |
175175

176176
**Example**
177177
```js

openapi.json

Lines changed: 28608 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"ldutils": "./ldutils"
88
},
99
"scripts": {
10-
"build": "yarn lint && rimraf dist/ && babel ./src --out-dir dist/src --copy-files && babel ./test --out-dir dist/test --copy-files && babel ./*.js --out-dir dist/ --copy-files && cp swagger.yaml dist/",
10+
"build": "yarn lint && rimraf dist/ && babel ./src --out-dir dist/src --copy-files && babel ./test --out-dir dist/test --copy-files && babel ./*.js --out-dir dist/ --copy-files && cp openapi.json dist/",
1111
"commit": "./node_modules/.bin/git-cz",
1212
"lint": "prettier --write ./src/** *.js ldutils && node ./node_modules/.bin/eslint ./src ./test --fix --ext=.js --ignore-pattern node_modules/ --ignore-pattern coverage/ --quiet",
1313
"test": "yarn build && cross-env NODE_ENV=test nyc ./node_modules/.bin/mocha --timeout 10000 --require @babel/register --require @babel/polyfill './dist/test/**/*.spec.js' && yarn jsdoc2markdown",
@@ -34,19 +34,19 @@
3434
"app-root-path": "^3.0.0",
3535
"bunyan": "^1.8.12",
3636
"bunyan-format": "^0.2.1",
37+
"commander": "^6.1.0",
3738
"dotenv": "^8.2.0",
38-
"fast-json-patch": "^3.0.0-1",
39+
"fast-json-patch": "^3.1.1",
3940
"format-json": "^1.0.3",
4041
"globule": "^1.2.1",
4142
"https-proxy-agent": "^5.0.0",
42-
"commander": "^6.1.0",
4343
"js-yaml": "^3.13.1",
4444
"json-diff": "^0.5.4",
4545
"json-format": "^1.0.1",
4646
"lodash": "^4.17.21",
47-
"node-fetch": "^2.6.0",
48-
"swagger-client": "^3.9.6",
49-
"webpack": "^4.41.2"
47+
"node-fetch": "2.6.7",
48+
"swagger-client": "^3.18.5",
49+
"webpack": "^5.0.0"
5050
},
5151
"engines": {
5252
"node": ">=10.0.0"
@@ -96,6 +96,7 @@
9696
"supertest": "^4.0.2"
9797
},
9898
"resolutions": {
99-
"lodash": "4.17.20"
99+
"lodash": "4.17.20",
100+
"browserslist": "^4.21.4"
100101
}
101102
}

src/LaunchDarklyApiClient.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Swagger from 'swagger-client';
2-
import jsYaml from 'js-yaml';
32
import { default as fs } from 'fs';
43
import { default as json } from 'format-json';
54
import { default as HttpsProxyAgent } from 'https-proxy-agent';
@@ -14,12 +13,12 @@ export class LaunchDarklyApiClient {
1413
* Swagger apiClient with interceptors configured
1514
* @param {string} API_TOKEN - from LaunchDarkly dashboard
1615
* @param { Object } log - logger implementation
17-
* @param { string } swaggerYamlString - optional serialized yaml
16+
* @param { string } openapiJsonString - optional serialized json
1817
* @returns {Promise}
1918
* @fulfil {Swagger} apiClient generated by swagger-js
2019
* @reject {Error} object with message
2120
*/
22-
static async create(API_TOKEN, log, swaggerYamlString) {
21+
static async create(API_TOKEN, log, openapiJsonString) {
2322
log.debug(`creating api client with token: ${API_TOKEN}`);
2423

2524
let proxy = process.env.http_proxy || process.env.https_proxy || null;
@@ -29,13 +28,13 @@ export class LaunchDarklyApiClient {
2928
log.debug(`using proxy from env var https_proxy=${proxy}`);
3029
}
3130

32-
// swagger.yaml from https://launchdarkly.github.io/ld-openapi/swagger.yaml
33-
const swaggerYaml = swaggerYamlString || fs.readFileSync(__dirname + `/../swagger.yaml`, 'utf-8').toString();
34-
const swaggerJson = jsYaml.safeLoad(swaggerYaml);
31+
// openapi.json from https://static.launchdarkly.com/app/s/openapi.52aa3dc63.json
32+
const openapiJson = openapiJsonString || fs.readFileSync(__dirname + `/../openapi.json`, 'utf-8').toString();
3533

3634
return Swagger({
37-
spec: swaggerJson,
35+
spec: JSON.parse(openapiJson),
3836
usePromise: true,
37+
requestContentType: 'application/json',
3938
requestInterceptor: req => {
4039
req.userFetch = fetch;
4140
req.agent = agent;

src/LaunchDarklyUtilsFlags.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class LaunchDarklyUtilsFlags {
4949
throw {
5050
api: 'getFeatureFlags',
5151
message: e.message,
52-
docs: 'https://apidocs.launchdarkly.com/docs/list-feature-flags'
52+
docs: 'https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlags'
5353
};
5454
}
5555
}
@@ -79,7 +79,7 @@ export class LaunchDarklyUtilsFlags {
7979
throw {
8080
api: 'getFeatureFlag',
8181
message: e.message,
82-
docs: 'https://apidocs.launchdarkly.com/docs/get-feature-flag'
82+
docs: 'https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlag'
8383
};
8484
}
8585
}
@@ -104,28 +104,32 @@ export class LaunchDarklyUtilsFlags {
104104
* patch a feature flag by key
105105
* @param {string} projectKey - project identifier
106106
* @param {string} featureFlagKey - feature flag identifier
107-
* @param {Array<Object>} patchComment - array of valid json patch descriptors
107+
* @param {Array<Object>} patch - array of valid json patch descriptors
108108
* @returns {Promise}
109109
* @fulfil {Object} updated feature flag json
110110
* @reject {Error} object with message
111111
* @example ldutils updateFeatureFlag my-project my-flag {jsonPatch}
112112
*/
113-
async updateFeatureFlag(projectKey, featureFlagKey, patchComment) {
113+
async updateFeatureFlag(projectKey, featureFlagKey, patch) {
114114
try {
115115
return this.apiClient.apis[this.API_GROUP]
116-
.patchFeatureFlag({
117-
projectKey: projectKey,
118-
featureFlagKey: featureFlagKey,
119-
patchComment: patchComment
120-
})
116+
.patchFeatureFlag(
117+
{
118+
projectKey: projectKey,
119+
featureFlagKey: featureFlagKey
120+
},
121+
{
122+
requestBody: patch
123+
}
124+
)
121125
.then(response => {
122126
return response.body;
123127
});
124128
} catch (e) {
125129
throw {
126130
api: 'patchFeatureFlag',
127131
message: e.message,
128-
docs: 'https://apidocs.launchdarkly.com/docs/update-feature-flag'
132+
docs: 'https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag'
129133
};
130134
}
131135
}
@@ -170,15 +174,15 @@ export class LaunchDarklyUtilsFlags {
170174
return patchDelta;
171175
})
172176
.then(patchDelta => {
173-
let patchComment = this.assembleFlagPatch(patchDelta, toEnv, includeState);
177+
let patch = this.assembleFlagPatch(patchDelta, toEnv, includeState);
174178

175-
that.log.debug(`patchComment for '${featureFlagKey}' in ${toEnv} : ${json.plain(patchComment)}`);
176-
return this.updateFeatureFlag(projectKey, featureFlagKey, patchComment);
179+
that.log.debug(`patch for '${featureFlagKey}' in ${toEnv} : ${json.plain(patch)}`);
180+
return this.updateFeatureFlag(projectKey, featureFlagKey, patch);
177181
});
178182
}
179183

180184
assembleFlagPatch(patchDelta, targetEnv, includeState) {
181-
let patchComment = [];
185+
let patches = [];
182186
patchDelta.forEach(patch => {
183187
if (
184188
patch.path.startsWith('/targets') ||
@@ -190,10 +194,10 @@ export class LaunchDarklyUtilsFlags {
190194
) {
191195
// add target env obj path and push
192196
patch.path = `/environments/${targetEnv}${patch.path}`;
193-
patchComment.push(patch);
197+
patches.push(patch);
194198
}
195199
});
196-
return patchComment;
200+
return patches;
197201
}
198202

199203
/**
@@ -256,10 +260,10 @@ export class LaunchDarklyUtilsFlags {
256260
return patchDelta;
257261
})
258262
.then(patchDelta => {
259-
let patchComment = this.assembleFlagPatch(patchDelta, targetEnv, includeState);
263+
let patch = this.assembleFlagPatch(patchDelta, targetEnv, includeState);
260264

261-
that.log.debug(`patchComment for '${key}' in ${targetEnv} : ${json.plain(patchComment)}`);
262-
return this.updateFeatureFlag(projectKey, key, patchComment);
265+
that.log.debug(`patch for '${key}' in ${targetEnv} : ${json.plain(patch)}`);
266+
return this.updateFeatureFlag(projectKey, key, patch);
263267
})
264268
);
265269
});

src/LaunchDarklyUtilsMembers.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class LaunchDarklyUtilsMembers {
2626
* @returns {string}
2727
*/
2828
get API_GROUP() {
29-
return 'Team members';
29+
return 'Account members';
3030
}
3131

3232
/**
@@ -50,7 +50,7 @@ export class LaunchDarklyUtilsMembers {
5050
throw {
5151
api: 'getMembers',
5252
message: e.message,
53-
docs: 'https://apidocs.launchdarkly.com/docs/list-team-members'
53+
docs: 'https://apidocs.launchdarkly.com/tag/Account-members#operation/getMembers'
5454
};
5555
}
5656
}
@@ -65,14 +65,14 @@ export class LaunchDarklyUtilsMembers {
6565
*/
6666
async getTeamMember(memberId) {
6767
try {
68-
return this.apiClient.apis[this.API_GROUP].getMember({ memberId: memberId }).then(response => {
68+
return this.apiClient.apis[this.API_GROUP].getMember({ id: memberId }).then(response => {
6969
return response.body;
7070
});
7171
} catch (e) {
7272
throw {
7373
api: 'getMember',
7474
message: e.message,
75-
docs: 'https://apidocs.launchdarkly.com/docs/get-team-member'
75+
docs: 'https://apidocs.launchdarkly.com/tag/Account-members#operation/getMember'
7676
};
7777
}
7878
}
@@ -93,7 +93,7 @@ export class LaunchDarklyUtilsMembers {
9393
throw {
9494
api: 'getTeamMembers',
9595
message: `member not found for email ${emailAddress}`,
96-
docs: 'https://apidocs.launchdarkly.com/docs/list-team-members'
96+
docs: 'https://apidocs.launchdarkly.com/tag/Account-members#operation/getMembers'
9797
};
9898
}
9999

@@ -120,7 +120,7 @@ export class LaunchDarklyUtilsMembers {
120120
throw {
121121
api: 'getTeamMemberCustomRoles',
122122
message: `role not found for _id ${memberRoleId}`,
123-
docs: 'https://apidocs.launchdarkly.com/docs/list-team-members'
123+
docs: 'https://apidocs.launchdarkly.com/tag/Account-members#operation/getMembers'
124124
};
125125
}
126126
});
@@ -145,14 +145,14 @@ export class LaunchDarklyUtilsMembers {
145145
!defaultRoles.includes(initialRoleKey) ? (user.customRoles = [initialRoleKey]) : (user.role = initialRoleKey);
146146
members.membersBody.push(user);
147147
try {
148-
return this.apiClient.apis[this.API_GROUP].postMembers(members).then(response => {
148+
return this.apiClient.apis[this.API_GROUP].postMembers({}, { requestBody: members }).then(response => {
149149
return response.body;
150150
});
151151
} catch (e) {
152152
throw {
153153
api: 'postMembers',
154154
message: e.message,
155-
docs: 'https://apidocs.launchdarkly.com/docs/create-team-members-1'
155+
docs: 'https://apidocs.launchdarkly.com/tag/Account-members#operation/postMembers'
156156
};
157157
}
158158
}

src/LaunchDarklyUtilsProjects.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class LaunchDarklyUtilsProjects {
4545
throw {
4646
api: 'getProjects',
4747
message: e.message,
48-
docs: 'https://apidocs.launchdarkly.com/reference#list-projects'
48+
docs: 'https://apidocs.launchdarkly.com/tag/Projects#operation/getProjects'
4949
};
5050
});
5151
}
@@ -68,7 +68,7 @@ export class LaunchDarklyUtilsProjects {
6868
throw {
6969
api: 'getProject',
7070
message: e.message,
71-
docs: 'https://apidocs.launchdarkly.com/reference#get-project'
71+
docs: 'https://apidocs.launchdarkly.com/tag/Projects#operation/getProjects'
7272
};
7373
});
7474
}
@@ -132,15 +132,15 @@ export class LaunchDarklyUtilsProjects {
132132
defaultClientSideAvailability
133133
};
134134
return this.apiClient.apis[this.API_GROUP]
135-
.postProject({ projectBody: newProject })
135+
.postProject({}, { requestBody: newProject })
136136
.then(response => {
137137
return response.body;
138138
})
139139
.catch(e => {
140140
throw {
141141
api: 'createProject',
142142
message: e.message,
143-
docs: 'https://apidocs.launchdarkly.com/reference#create-project'
143+
docs: 'https://apidocs.launchdarkly.com/tag/Projects#operation/postProject'
144144
};
145145
});
146146
}
@@ -156,15 +156,15 @@ export class LaunchDarklyUtilsProjects {
156156
*/
157157
async updateProject(projectKey, jsonPatch) {
158158
return this.apiClient.apis[this.API_GROUP]
159-
.patchProject({ projectKey: projectKey, patchDelta: jsonPatch })
159+
.patchProject({ projectKey: projectKey }, { requestBody: jsonPatch })
160160
.then(response => {
161161
return response.body;
162162
})
163163
.catch(e => {
164164
throw {
165165
api: 'patchProject',
166166
message: e.message,
167-
docs: 'https://apidocs.launchdarkly.com/reference#update-project'
167+
docs: 'https://apidocs.launchdarkly.com/tag/Projects#operation/patchProject'
168168
};
169169
});
170170
}
@@ -186,7 +186,7 @@ export class LaunchDarklyUtilsProjects {
186186
throw {
187187
api: 'deleteProject',
188188
message: e.message,
189-
docs: 'https://apidocs.launchdarkly.com/reference#delete-project'
189+
docs: 'https://apidocs.launchdarkly.com/tag/Projects#operation/deleteProject'
190190
};
191191
});
192192
}

0 commit comments

Comments
 (0)