@microsoft/m365-spec-parser 0.2.4-alpha.5577464e2.0 → 0.2.4-alpha.59a7e76c4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ var fs = require('fs-extra');
9
9
  var path = require('path');
10
10
  var teamsManifest = require('@microsoft/teams-manifest');
11
11
  var crypto = require('crypto');
12
+ var jsonSchemaRefParser = require('@apidevtools/json-schema-ref-parser');
12
13
 
13
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
15
 
@@ -168,6 +169,7 @@ ConstantString.ResponseCodeFor20X = [
168
169
  "207",
169
170
  "208",
170
171
  "226",
172
+ "2XX",
171
173
  "default",
172
174
  ];
173
175
  ConstantString.AllOperationMethods = [
@@ -245,6 +247,9 @@ class Utils {
245
247
  static isAPIKeyAuth(authScheme) {
246
248
  return authScheme.type === "apiKey";
247
249
  }
250
+ static isAPIKeyAuthButNotInCookie(authScheme) {
251
+ return authScheme.type === "apiKey" && authScheme.in !== "cookie";
252
+ }
248
253
  static isOAuthWithAuthCodeFlow(authScheme) {
249
254
  return !!(authScheme.type === "oauth2" &&
250
255
  authScheme.flows &&
@@ -260,7 +265,8 @@ class Utils {
260
265
  for (const auths of authSchemeArray) {
261
266
  if (auths.length === 1) {
262
267
  if (Utils.isOAuthWithAuthCodeFlow(auths[0].authScheme) ||
263
- Utils.isBearerTokenAuth(auths[0].authScheme)) {
268
+ Utils.isBearerTokenAuth(auths[0].authScheme) ||
269
+ Utils.isAPIKeyAuthButNotInCookie(auths[0].authScheme)) {
264
270
  return false;
265
271
  }
266
272
  }
@@ -1881,7 +1887,8 @@ class ManifestUpdater {
1881
1887
  key = "OAuthPluginVault";
1882
1888
  authName = authInfo.name;
1883
1889
  }
1884
- else if (Utils.isBearerTokenAuth(authInfo.authScheme)) {
1890
+ else if (Utils.isBearerTokenAuth(authInfo.authScheme) ||
1891
+ Utils.isAPIKeyAuthButNotInCookie(authInfo.authScheme)) {
1885
1892
  key = "ApiKeyPluginVault";
1886
1893
  authName = authInfo.name;
1887
1894
  }
@@ -2146,6 +2153,7 @@ class SpecParser {
2146
2153
  };
2147
2154
  this.pathOrSpec = pathOrDoc;
2148
2155
  this.parser = new SwaggerParser__default['default']();
2156
+ this.refParser = new jsonSchemaRefParser.$RefParser();
2149
2157
  this.options = Object.assign(Object.assign({}, this.defaultOptions), (options !== null && options !== void 0 ? options : {}));
2150
2158
  }
2151
2159
  /**
@@ -2159,12 +2167,15 @@ class SpecParser {
2159
2167
  let hash = "";
2160
2168
  try {
2161
2169
  yield this.loadSpec();
2162
- if (!this.parser.$refs.circular) {
2170
+ if (!this.refParser.$refs.circular) {
2163
2171
  yield this.parser.validate(this.spec);
2164
2172
  }
2165
2173
  else {
2174
+ // The following code hangs for Graph API, support will be added when SwaggerParser is updated.
2175
+ /*
2166
2176
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
2167
- yield this.parser.validate(clonedUnResolveSpec);
2177
+ await this.parser.validate(clonedUnResolveSpec);
2178
+ */
2168
2179
  }
2169
2180
  }
2170
2181
  catch (e) {
@@ -2192,7 +2203,7 @@ class SpecParser {
2192
2203
  };
2193
2204
  }
2194
2205
  // Remote reference not supported
2195
- const refPaths = this.parser.$refs.paths();
2206
+ const refPaths = this.refParser.$refs.paths();
2196
2207
  // refPaths [0] is the current spec file path
2197
2208
  if (refPaths.length > 1) {
2198
2209
  errors.push({
@@ -2327,7 +2338,7 @@ class SpecParser {
2327
2338
  throw new SpecParserError(ConstantString.CancelledMessage, exports.ErrorType.Cancelled);
2328
2339
  }
2329
2340
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(newUnResolvedSpec));
2330
- const newSpec = (yield this.parser.dereference(clonedUnResolveSpec));
2341
+ const newSpec = yield this.deReferenceSpec(clonedUnResolveSpec);
2331
2342
  return [newUnResolvedSpec, newSpec];
2332
2343
  }
2333
2344
  catch (err) {
@@ -2338,6 +2349,12 @@ class SpecParser {
2338
2349
  }
2339
2350
  });
2340
2351
  }
2352
+ deReferenceSpec(spec) {
2353
+ return __awaiter(this, void 0, void 0, function* () {
2354
+ const result = yield this.refParser.dereference(spec);
2355
+ return result;
2356
+ });
2357
+ }
2341
2358
  /**
2342
2359
  * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
2343
2360
  * @param manifestPath A file path of the Teams app manifest file to update.
@@ -2483,7 +2500,7 @@ class SpecParser {
2483
2500
  this.isSwaggerFile = true;
2484
2501
  }
2485
2502
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
2486
- this.spec = (yield this.parser.dereference(clonedUnResolveSpec));
2503
+ this.spec = yield this.deReferenceSpec(clonedUnResolveSpec);
2487
2504
  }
2488
2505
  });
2489
2506
  }