@microsoft/m365-spec-parser 0.2.2-alpha.2c5119322.0 → 0.2.2-alpha.2f6f18b3b.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.
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +29 -5
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +29 -5
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/interfaces.d.ts +5 -0
- package/dist/src/manifestUpdater.d.ts +3 -3
- package/dist/src/specParser.d.ts +1 -1
- package/package.json +3 -3
package/dist/index.esm2017.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import converter from 'swagger2openapi';
|
|
|
3
3
|
import jsyaml from 'js-yaml';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import path from 'path';
|
|
6
|
+
import { createHash } from 'crypto';
|
|
6
7
|
|
|
7
8
|
// Copyright (c) Microsoft Corporation.
|
|
8
9
|
/**
|
|
@@ -1599,7 +1600,7 @@ function inferProperties(card) {
|
|
|
1599
1600
|
|
|
1600
1601
|
// Copyright (c) Microsoft Corporation.
|
|
1601
1602
|
class ManifestUpdater {
|
|
1602
|
-
static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options, authInfo) {
|
|
1603
|
+
static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options, authInfo, existingPluginManifestInfo) {
|
|
1603
1604
|
const manifest = await fs.readJSON(manifestPath);
|
|
1604
1605
|
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
|
|
1605
1606
|
manifest.copilotExtensions = manifest.copilotExtensions || {};
|
|
@@ -1615,7 +1616,7 @@ class ManifestUpdater {
|
|
|
1615
1616
|
}
|
|
1616
1617
|
const appName = this.removeEnvs(manifest.name.short);
|
|
1617
1618
|
const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
|
|
1618
|
-
const [apiPlugin, warnings] = await ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options);
|
|
1619
|
+
const [apiPlugin, warnings] = await ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options, existingPluginManifestInfo);
|
|
1619
1620
|
return [manifest, apiPlugin, warnings];
|
|
1620
1621
|
}
|
|
1621
1622
|
static updateManifestDescription(manifest, spec) {
|
|
@@ -1637,7 +1638,7 @@ class ManifestUpdater {
|
|
|
1637
1638
|
throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), ErrorType.UpdateManifestFailed);
|
|
1638
1639
|
}
|
|
1639
1640
|
}
|
|
1640
|
-
static async generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options) {
|
|
1641
|
+
static async generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options, existingPluginManifestInfo) {
|
|
1641
1642
|
var _a, _b, _c, _d;
|
|
1642
1643
|
const warnings = [];
|
|
1643
1644
|
const functions = [];
|
|
@@ -1756,6 +1757,10 @@ class ManifestUpdater {
|
|
|
1756
1757
|
if (await fs.pathExists(apiPluginFilePath)) {
|
|
1757
1758
|
apiPlugin = await fs.readJSON(apiPluginFilePath);
|
|
1758
1759
|
}
|
|
1760
|
+
else if (existingPluginManifestInfo &&
|
|
1761
|
+
(await fs.pathExists(existingPluginManifestInfo.manifestPath))) {
|
|
1762
|
+
apiPlugin = await fs.readJSON(existingPluginManifestInfo.manifestPath);
|
|
1763
|
+
}
|
|
1759
1764
|
else {
|
|
1760
1765
|
apiPlugin = {
|
|
1761
1766
|
$schema: ConstantString.PluginManifestSchema,
|
|
@@ -1778,6 +1783,11 @@ class ManifestUpdater {
|
|
|
1778
1783
|
}
|
|
1779
1784
|
}
|
|
1780
1785
|
apiPlugin.runtimes = apiPlugin.runtimes || [];
|
|
1786
|
+
// Need to delete previous runtime since spec path has changed
|
|
1787
|
+
if (existingPluginManifestInfo) {
|
|
1788
|
+
const relativePath = ManifestUpdater.getRelativePath(existingPluginManifestInfo.manifestPath, existingPluginManifestInfo.specPath);
|
|
1789
|
+
apiPlugin.runtimes = apiPlugin.runtimes.filter((runtime) => runtime.spec.url !== relativePath);
|
|
1790
|
+
}
|
|
1781
1791
|
const index = apiPlugin.runtimes.findIndex((runtime) => {
|
|
1782
1792
|
var _a, _b;
|
|
1783
1793
|
return runtime.spec.url === specRelativePath &&
|
|
@@ -1974,6 +1984,7 @@ class SpecParser {
|
|
|
1974
1984
|
*/
|
|
1975
1985
|
async validate() {
|
|
1976
1986
|
try {
|
|
1987
|
+
let hash = "";
|
|
1977
1988
|
try {
|
|
1978
1989
|
await this.loadSpec();
|
|
1979
1990
|
if (!this.parser.$refs.circular) {
|
|
@@ -1989,8 +2000,13 @@ class SpecParser {
|
|
|
1989
2000
|
status: ValidationStatus.Error,
|
|
1990
2001
|
warnings: [],
|
|
1991
2002
|
errors: [{ type: ErrorType.SpecNotValid, content: e.toString() }],
|
|
2003
|
+
specHash: hash,
|
|
1992
2004
|
};
|
|
1993
2005
|
}
|
|
2006
|
+
if (this.unResolveSpec.servers) {
|
|
2007
|
+
const serverString = JSON.stringify(this.unResolveSpec.servers);
|
|
2008
|
+
hash = createHash("sha256").update(serverString).digest("hex");
|
|
2009
|
+
}
|
|
1994
2010
|
const errors = [];
|
|
1995
2011
|
const warnings = [];
|
|
1996
2012
|
if (!this.options.allowSwagger && this.isSwaggerFile) {
|
|
@@ -2000,6 +2016,7 @@ class SpecParser {
|
|
|
2000
2016
|
errors: [
|
|
2001
2017
|
{ type: ErrorType.SwaggerNotSupported, content: ConstantString.SwaggerNotSupported },
|
|
2002
2018
|
],
|
|
2019
|
+
specHash: hash,
|
|
2003
2020
|
};
|
|
2004
2021
|
}
|
|
2005
2022
|
// Remote reference not supported
|
|
@@ -2033,6 +2050,7 @@ class SpecParser {
|
|
|
2033
2050
|
status: status,
|
|
2034
2051
|
warnings: warnings,
|
|
2035
2052
|
errors: errors,
|
|
2053
|
+
specHash: hash,
|
|
2036
2054
|
};
|
|
2037
2055
|
}
|
|
2038
2056
|
catch (err) {
|
|
@@ -2148,7 +2166,7 @@ class SpecParser {
|
|
|
2148
2166
|
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
2149
2167
|
* @param pluginFilePath File path of the api plugin file to generate.
|
|
2150
2168
|
*/
|
|
2151
|
-
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, signal) {
|
|
2169
|
+
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, existingPluginFilePath, signal) {
|
|
2152
2170
|
const result = {
|
|
2153
2171
|
allSuccess: true,
|
|
2154
2172
|
warnings: [],
|
|
@@ -2162,7 +2180,13 @@ class SpecParser {
|
|
|
2162
2180
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
2163
2181
|
throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
|
|
2164
2182
|
}
|
|
2165
|
-
const
|
|
2183
|
+
const existingPluginManifestInfo = existingPluginFilePath
|
|
2184
|
+
? {
|
|
2185
|
+
manifestPath: existingPluginFilePath,
|
|
2186
|
+
specPath: this.pathOrSpec,
|
|
2187
|
+
}
|
|
2188
|
+
: undefined;
|
|
2189
|
+
const [updatedManifest, apiPlugin, warnings] = await ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options, authInfo, existingPluginManifestInfo);
|
|
2166
2190
|
result.warnings.push(...warnings);
|
|
2167
2191
|
await fs.outputJSON(manifestPath, updatedManifest, { spaces: 4 });
|
|
2168
2192
|
await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|