@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.
@@ -5,6 +5,7 @@ import fs from 'fs-extra';
5
5
  import path from 'path';
6
6
  import { ManifestUtil } from '@microsoft/teams-manifest';
7
7
  import { createHash } from 'crypto';
8
+ import { $RefParser } from '@apidevtools/json-schema-ref-parser';
8
9
 
9
10
  // Copyright (c) Microsoft Corporation.
10
11
  /**
@@ -126,6 +127,7 @@ ConstantString.ResponseCodeFor20X = [
126
127
  "207",
127
128
  "208",
128
129
  "226",
130
+ "2XX",
129
131
  "default",
130
132
  ];
131
133
  ConstantString.AllOperationMethods = [
@@ -203,6 +205,9 @@ class Utils {
203
205
  static isAPIKeyAuth(authScheme) {
204
206
  return authScheme.type === "apiKey";
205
207
  }
208
+ static isAPIKeyAuthButNotInCookie(authScheme) {
209
+ return authScheme.type === "apiKey" && authScheme.in !== "cookie";
210
+ }
206
211
  static isOAuthWithAuthCodeFlow(authScheme) {
207
212
  return !!(authScheme.type === "oauth2" &&
208
213
  authScheme.flows &&
@@ -218,7 +223,8 @@ class Utils {
218
223
  for (const auths of authSchemeArray) {
219
224
  if (auths.length === 1) {
220
225
  if (Utils.isOAuthWithAuthCodeFlow(auths[0].authScheme) ||
221
- Utils.isBearerTokenAuth(auths[0].authScheme)) {
226
+ Utils.isBearerTokenAuth(auths[0].authScheme) ||
227
+ Utils.isAPIKeyAuthButNotInCookie(auths[0].authScheme)) {
222
228
  return false;
223
229
  }
224
230
  }
@@ -1836,7 +1842,8 @@ class ManifestUpdater {
1836
1842
  key = "OAuthPluginVault";
1837
1843
  authName = authInfo.name;
1838
1844
  }
1839
- else if (Utils.isBearerTokenAuth(authInfo.authScheme)) {
1845
+ else if (Utils.isBearerTokenAuth(authInfo.authScheme) ||
1846
+ Utils.isAPIKeyAuthButNotInCookie(authInfo.authScheme)) {
1840
1847
  key = "ApiKeyPluginVault";
1841
1848
  authName = authInfo.name;
1842
1849
  }
@@ -2096,6 +2103,7 @@ class SpecParser {
2096
2103
  };
2097
2104
  this.pathOrSpec = pathOrDoc;
2098
2105
  this.parser = new SwaggerParser();
2106
+ this.refParser = new $RefParser();
2099
2107
  this.options = Object.assign(Object.assign({}, this.defaultOptions), (options !== null && options !== void 0 ? options : {}));
2100
2108
  }
2101
2109
  /**
@@ -2108,12 +2116,15 @@ class SpecParser {
2108
2116
  let hash = "";
2109
2117
  try {
2110
2118
  await this.loadSpec();
2111
- if (!this.parser.$refs.circular) {
2119
+ if (!this.refParser.$refs.circular) {
2112
2120
  await this.parser.validate(this.spec);
2113
2121
  }
2114
2122
  else {
2123
+ // The following code hangs for Graph API, support will be added when SwaggerParser is updated.
2124
+ /*
2115
2125
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
2116
2126
  await this.parser.validate(clonedUnResolveSpec);
2127
+ */
2117
2128
  }
2118
2129
  }
2119
2130
  catch (e) {
@@ -2141,7 +2152,7 @@ class SpecParser {
2141
2152
  };
2142
2153
  }
2143
2154
  // Remote reference not supported
2144
- const refPaths = this.parser.$refs.paths();
2155
+ const refPaths = this.refParser.$refs.paths();
2145
2156
  // refPaths [0] is the current spec file path
2146
2157
  if (refPaths.length > 1) {
2147
2158
  errors.push({
@@ -2270,7 +2281,7 @@ class SpecParser {
2270
2281
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
2271
2282
  }
2272
2283
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(newUnResolvedSpec));
2273
- const newSpec = (await this.parser.dereference(clonedUnResolveSpec));
2284
+ const newSpec = await this.deReferenceSpec(clonedUnResolveSpec);
2274
2285
  return [newUnResolvedSpec, newSpec];
2275
2286
  }
2276
2287
  catch (err) {
@@ -2280,6 +2291,10 @@ class SpecParser {
2280
2291
  throw new SpecParserError(err.toString(), ErrorType.GetSpecFailed);
2281
2292
  }
2282
2293
  }
2294
+ async deReferenceSpec(spec) {
2295
+ const result = await this.refParser.dereference(spec);
2296
+ return result;
2297
+ }
2283
2298
  /**
2284
2299
  * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
2285
2300
  * @param manifestPath A file path of the Teams app manifest file to update.
@@ -2420,7 +2435,7 @@ class SpecParser {
2420
2435
  this.isSwaggerFile = true;
2421
2436
  }
2422
2437
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
2423
- this.spec = (await this.parser.dereference(clonedUnResolveSpec));
2438
+ this.spec = await this.deReferenceSpec(clonedUnResolveSpec);
2424
2439
  }
2425
2440
  }
2426
2441
  getAPIs(spec) {