@microsoft/m365-spec-parser 0.2.4-alpha.396238b05.0 → 0.2.4-alpha.4a4474697.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 = [
@@ -2101,6 +2103,7 @@ class SpecParser {
2101
2103
  };
2102
2104
  this.pathOrSpec = pathOrDoc;
2103
2105
  this.parser = new SwaggerParser();
2106
+ this.refParser = new $RefParser();
2104
2107
  this.options = Object.assign(Object.assign({}, this.defaultOptions), (options !== null && options !== void 0 ? options : {}));
2105
2108
  }
2106
2109
  /**
@@ -2113,12 +2116,15 @@ class SpecParser {
2113
2116
  let hash = "";
2114
2117
  try {
2115
2118
  await this.loadSpec();
2116
- if (!this.parser.$refs.circular) {
2119
+ if (!this.refParser.$refs.circular) {
2117
2120
  await this.parser.validate(this.spec);
2118
2121
  }
2119
2122
  else {
2123
+ // The following code hangs for Graph API, support will be added when SwaggerParser is updated.
2124
+ /*
2120
2125
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
2121
2126
  await this.parser.validate(clonedUnResolveSpec);
2127
+ */
2122
2128
  }
2123
2129
  }
2124
2130
  catch (e) {
@@ -2146,7 +2152,7 @@ class SpecParser {
2146
2152
  };
2147
2153
  }
2148
2154
  // Remote reference not supported
2149
- const refPaths = this.parser.$refs.paths();
2155
+ const refPaths = this.refParser.$refs.paths();
2150
2156
  // refPaths [0] is the current spec file path
2151
2157
  if (refPaths.length > 1) {
2152
2158
  errors.push({
@@ -2275,7 +2281,7 @@ class SpecParser {
2275
2281
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
2276
2282
  }
2277
2283
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(newUnResolvedSpec));
2278
- const newSpec = (await this.parser.dereference(clonedUnResolveSpec));
2284
+ const newSpec = await this.deReferenceSpec(clonedUnResolveSpec);
2279
2285
  return [newUnResolvedSpec, newSpec];
2280
2286
  }
2281
2287
  catch (err) {
@@ -2285,6 +2291,10 @@ class SpecParser {
2285
2291
  throw new SpecParserError(err.toString(), ErrorType.GetSpecFailed);
2286
2292
  }
2287
2293
  }
2294
+ async deReferenceSpec(spec) {
2295
+ const result = await this.refParser.dereference(spec);
2296
+ return result;
2297
+ }
2288
2298
  /**
2289
2299
  * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
2290
2300
  * @param manifestPath A file path of the Teams app manifest file to update.
@@ -2425,7 +2435,7 @@ class SpecParser {
2425
2435
  this.isSwaggerFile = true;
2426
2436
  }
2427
2437
  const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
2428
- this.spec = (await this.parser.dereference(clonedUnResolveSpec));
2438
+ this.spec = await this.deReferenceSpec(clonedUnResolveSpec);
2429
2439
  }
2430
2440
  }
2431
2441
  getAPIs(spec) {