Skip to content

Commit eccb823

Browse files
committed
feat(swagger): add support for passed in serialized swagger.yaml
1 parent 3319fef commit eccb823

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

API.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
**Kind**: global class
2222
<a name="LaunchDarklyApiClient.create"></a>
2323

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

@@ -33,6 +33,7 @@ Swagger apiClient with interceptors configured
3333
| --- | --- | --- |
3434
| API_TOKEN | <code>string</code> | from LaunchDarkly dashboard |
3535
| log | <code>Object</code> | logger implementation |
36+
| swaggerYamlString | <code>string</code> | optional serialized yaml |
3637

3738
<a name="LaunchDarklyLogger"></a>
3839

@@ -50,7 +51,7 @@ Get handle on Bunyan logger. This is the default logger if not supplied to util
5051
**Kind**: global class
5152
<a name="LaunchDarklyUtils+create"></a>
5253

53-
### launchDarklyUtils.create(API_TOKEN, customLogger) ⇒ <code>Promise</code>
54+
### launchDarklyUtils.create(API_TOKEN, customLogger, swaggerYamlString) ⇒ <code>Promise</code>
5455
Create an instance of ldutils with api specific classes attached. This is the primary class used to access apis,
5556
as api grouping util classes are attached to this class.
5657

@@ -62,6 +63,7 @@ as api grouping util classes are attached to this class.
6263
| --- | --- | --- |
6364
| API_TOKEN | <code>string</code> | from LaunchDarkly dashboard |
6465
| customLogger | <code>Object</code> | logger implementation, or 'console'. If not supplied, defaults to Bunyan logger |
66+
| swaggerYamlString | <code>string</code> | optional serialized yaml |
6567

6668
<a name="LaunchDarklyUtilsFlags"></a>
6769

src/LaunchDarklyApiClient.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ export class LaunchDarklyApiClient {
1212
* Swagger apiClient with interceptors configured
1313
* @param {string} API_TOKEN - from LaunchDarkly dashboard
1414
* @param { Object } log - logger implementation
15+
* @param { string } swaggerYamlString - optional serialized yaml
1516
* @returns {Promise}
1617
* @fulfil {Swagger} apiClient generated by swagger-js
1718
* @reject {Error} object with message
1819
*/
19-
static async create(API_TOKEN, log) {
20+
static async create(API_TOKEN, log, swaggerYamlString) {
2021
log.debug(`creating api client with token: ${API_TOKEN}`);
2122

2223
// swagger.yaml from https://launchdarkly.github.io/ld-openapi/swagger.yaml
23-
const swaggerYaml = fs.readFileSync(__dirname + `/../swagger.yaml`, 'utf-8').toString();
24+
const swaggerYaml = swaggerYamlString || fs.readFileSync(__dirname + `/../swagger.yaml`, 'utf-8').toString();
2425
const swaggerJson = jsYaml.safeLoad(swaggerYaml);
2526

2627
return Swagger({

src/LaunchDarklyUtils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ export class LaunchDarklyUtils {
1515
* as api grouping util classes are attached to this class.
1616
* @param {string} API_TOKEN - from LaunchDarkly dashboard
1717
* @param { Object } customLogger - logger implementation, or 'console'. If not supplied, defaults to Bunyan logger
18+
* @param { string } swaggerYamlString - optional serialized yaml
1819
* @returns {Promise}
1920
* @fulfil {LaunchDarklyUtils}
2021
* @reject {Error} object with message
2122
*/
22-
async create(API_TOKEN, customLogger) {
23+
async create(API_TOKEN, customLogger, swaggerYamlString) {
2324
let that = this;
2425
return new Promise(async (resolve, reject) => {
2526
// setup logger
@@ -28,7 +29,7 @@ export class LaunchDarklyUtils {
2829

2930
// create LaunchDarkly apiClient
3031
try {
31-
that.apiClient = await LaunchDarklyApiClient.create(API_TOKEN, this.log);
32+
that.apiClient = await LaunchDarklyApiClient.create(API_TOKEN, this.log, swaggerYamlString);
3233
that.log.debug('api client instantiated..');
3334

3435
// attach utils

0 commit comments

Comments
 (0)