@microsoft/m365-spec-parser 0.2.4-rc-hotfix.0 → 0.2.4-rc.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 +42 -11
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +134 -63
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +42 -11
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +137 -64
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +2 -3
- package/dist/src/interfaces.d.ts +10 -0
- package/dist/src/manifestUpdater.d.ts +3 -3
- package/dist/src/specParser.d.ts +2 -0
- package/dist/src/utils.d.ts +4 -1
- package/package.json +4 -4
package/dist/index.esm2017.js
CHANGED
|
@@ -53,6 +53,7 @@ var WarningType;
|
|
|
53
53
|
WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
|
|
54
54
|
WarningType["FuncDescriptionTooLong"] = "function-description-too-long";
|
|
55
55
|
WarningType["OperationIdContainsSpecialCharacters"] = "operationid-contains-special-characters";
|
|
56
|
+
WarningType["UnsupportedAuthType"] = "unsupported-auth-type";
|
|
56
57
|
WarningType["GenerateJsonDataFailed"] = "generate-json-data-failed";
|
|
57
58
|
WarningType["Unknown"] = "unknown";
|
|
58
59
|
})(WarningType || (WarningType = {}));
|
|
@@ -100,6 +101,7 @@ ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please conve
|
|
|
100
101
|
ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
|
|
101
102
|
ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
|
|
102
103
|
ConstantString.OperationIdContainsSpecialCharacters = "Operation id '%s' in OpenAPI description document contained special characters and was renamed to '%s'.";
|
|
104
|
+
ConstantString.AuthTypeIsNotSupported = "Unsupported authorization type in API '%s'. No authorization will be used.";
|
|
103
105
|
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
104
106
|
ConstantString.FuncDescriptionTooLong = "The description of the function '%s' is too long. The current length is %s characters, while the maximum allowed length is %s characters.";
|
|
105
107
|
ConstantString.GenerateJsonDataFailed = "Failed to generate JSON data for api: %s due to %s.";
|
|
@@ -114,12 +116,7 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
114
116
|
ConstantString.TextBlockType = "TextBlock";
|
|
115
117
|
ConstantString.ImageType = "Image";
|
|
116
118
|
ConstantString.ContainerType = "Container";
|
|
117
|
-
ConstantString.RegistrationIdPostfix =
|
|
118
|
-
apiKey: "REGISTRATION_ID",
|
|
119
|
-
oauth2: "CONFIGURATION_ID",
|
|
120
|
-
http: "REGISTRATION_ID",
|
|
121
|
-
openIdConnect: "REGISTRATION_ID",
|
|
122
|
-
};
|
|
119
|
+
ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
|
|
123
120
|
ConstantString.ResponseCodeFor20X = [
|
|
124
121
|
"200",
|
|
125
122
|
"201",
|
|
@@ -131,6 +128,7 @@ ConstantString.ResponseCodeFor20X = [
|
|
|
131
128
|
"207",
|
|
132
129
|
"208",
|
|
133
130
|
"226",
|
|
131
|
+
"2XX",
|
|
134
132
|
"default",
|
|
135
133
|
];
|
|
136
134
|
ConstantString.AllOperationMethods = [
|
|
@@ -200,11 +198,32 @@ class Utils {
|
|
|
200
198
|
static isAPIKeyAuth(authScheme) {
|
|
201
199
|
return authScheme.type === "apiKey";
|
|
202
200
|
}
|
|
201
|
+
static isAPIKeyAuthButNotInCookie(authScheme) {
|
|
202
|
+
return authScheme.type === "apiKey" && authScheme.in !== "cookie";
|
|
203
|
+
}
|
|
203
204
|
static isOAuthWithAuthCodeFlow(authScheme) {
|
|
204
205
|
return !!(authScheme.type === "oauth2" &&
|
|
205
206
|
authScheme.flows &&
|
|
206
207
|
authScheme.flows.authorizationCode);
|
|
207
208
|
}
|
|
209
|
+
static isNotSupportedAuth(authSchemeArray) {
|
|
210
|
+
if (authSchemeArray.length === 0) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
if (authSchemeArray.length > 0 && authSchemeArray.every((auths) => auths.length > 1)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
for (const auths of authSchemeArray) {
|
|
217
|
+
if (auths.length === 1) {
|
|
218
|
+
if (Utils.isOAuthWithAuthCodeFlow(auths[0].authScheme) ||
|
|
219
|
+
Utils.isBearerTokenAuth(auths[0].authScheme) ||
|
|
220
|
+
Utils.isAPIKeyAuthButNotInCookie(auths[0].authScheme)) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
208
227
|
static getAuthArray(securities, spec) {
|
|
209
228
|
var _a;
|
|
210
229
|
const result = [];
|
|
@@ -229,6 +248,20 @@ class Utils {
|
|
|
229
248
|
result.sort((a, b) => a[0].name.localeCompare(b[0].name));
|
|
230
249
|
return result;
|
|
231
250
|
}
|
|
251
|
+
static getAuthMap(spec) {
|
|
252
|
+
const authMap = {};
|
|
253
|
+
for (const url in spec.paths) {
|
|
254
|
+
for (const method in spec.paths[url]) {
|
|
255
|
+
const operation = spec.paths[url][method];
|
|
256
|
+
const authArray = Utils.getAuthArray(operation.security, spec);
|
|
257
|
+
if (authArray && authArray.length > 0) {
|
|
258
|
+
const currentAuth = authArray[0][0];
|
|
259
|
+
authMap[operation.operationId] = currentAuth;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return authMap;
|
|
264
|
+
}
|
|
232
265
|
static getAuthInfo(spec) {
|
|
233
266
|
let authInfo = undefined;
|
|
234
267
|
for (const url in spec.paths) {
|
|
@@ -699,6 +732,9 @@ class Validator {
|
|
|
699
732
|
reason: [ErrorType.MultipleAuthNotSupported],
|
|
700
733
|
};
|
|
701
734
|
}
|
|
735
|
+
if (this.projectType === ProjectType.Copilot) {
|
|
736
|
+
return { isValid: true, reason: [] };
|
|
737
|
+
}
|
|
702
738
|
for (const auths of authSchemeArray) {
|
|
703
739
|
if (auths.length === 1) {
|
|
704
740
|
if ((this.options.allowAPIKeyAuth && Utils.isAPIKeyAuth(auths[0].authScheme)) ||
|
|
@@ -720,7 +756,6 @@ class CopilotValidator extends Validator {
|
|
|
720
756
|
this.projectType = ProjectType.Copilot;
|
|
721
757
|
this.options = options;
|
|
722
758
|
this.spec = spec;
|
|
723
|
-
this.checkCircularReference();
|
|
724
759
|
}
|
|
725
760
|
validateSpec() {
|
|
726
761
|
const result = { errors: [], warnings: [] };
|
|
@@ -746,10 +781,6 @@ class CopilotValidator extends Validator {
|
|
|
746
781
|
if (!methodAndPathResult.isValid) {
|
|
747
782
|
return methodAndPathResult;
|
|
748
783
|
}
|
|
749
|
-
const circularReferenceResult = this.validateCircularReference(method, path);
|
|
750
|
-
if (!circularReferenceResult.isValid) {
|
|
751
|
-
return circularReferenceResult;
|
|
752
|
-
}
|
|
753
784
|
const operationObject = this.spec.paths[path][method];
|
|
754
785
|
// validate auth
|
|
755
786
|
const authCheckResult = this.validateAuth(method, path);
|