@microsoft/m365-spec-parser 0.2.3-alpha.c59b92632.0 → 0.2.3-alpha.decc8f69b.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 +9 -32
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +9 -32
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +9 -32
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +9 -32
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/interfaces.d.ts +0 -2
- package/dist/src/utils.d.ts +1 -2
- package/package.json +3 -3
package/dist/index.esm2017.mjs
CHANGED
|
@@ -41,8 +41,6 @@ var ErrorType;
|
|
|
41
41
|
ErrorType["PostBodySchemaIsNotJson"] = "post-body-schema-is-not-json";
|
|
42
42
|
ErrorType["PostBodyContainsRequiredUnsupportedSchema"] = "post-body-contains-required-unsupported-schema";
|
|
43
43
|
ErrorType["ParamsContainRequiredUnsupportedSchema"] = "params-contain-required-unsupported-schema";
|
|
44
|
-
ErrorType["ParamsContainsNestedObject"] = "params-contains-nested-object";
|
|
45
|
-
ErrorType["RequestBodyContainsNestedObject"] = "request-body-contains-nested-object";
|
|
46
44
|
ErrorType["ExceededRequiredParamsLimit"] = "exceeded-required-params-limit";
|
|
47
45
|
ErrorType["NoParameter"] = "no-parameter";
|
|
48
46
|
ErrorType["NoAPIInfo"] = "no-api-info";
|
|
@@ -110,7 +108,7 @@ ConstantString.WrappedCardResponseLayout = "list";
|
|
|
110
108
|
ConstantString.GetMethod = "get";
|
|
111
109
|
ConstantString.PostMethod = "post";
|
|
112
110
|
ConstantString.AdaptiveCardVersion = "1.5";
|
|
113
|
-
ConstantString.AdaptiveCardSchema = "
|
|
111
|
+
ConstantString.AdaptiveCardSchema = "https://adaptivecards.io/schemas/adaptive-card.json";
|
|
114
112
|
ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
115
113
|
ConstantString.TextBlockType = "TextBlock";
|
|
116
114
|
ConstantString.ImageType = "Image";
|
|
@@ -197,17 +195,6 @@ class SpecParserError extends Error {
|
|
|
197
195
|
|
|
198
196
|
// Copyright (c) Microsoft Corporation.
|
|
199
197
|
class Utils {
|
|
200
|
-
static hasNestedObjectInSchema(schema) {
|
|
201
|
-
if (this.isObjectSchema(schema)) {
|
|
202
|
-
for (const property in schema.properties) {
|
|
203
|
-
const nestedSchema = schema.properties[property];
|
|
204
|
-
if (this.isObjectSchema(nestedSchema)) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
198
|
static isObjectSchema(schema) {
|
|
212
199
|
return schema.type === "object" || (!schema.type && !!schema.properties);
|
|
213
200
|
}
|
|
@@ -339,7 +326,7 @@ class Utils {
|
|
|
339
326
|
}
|
|
340
327
|
return newStr;
|
|
341
328
|
}
|
|
342
|
-
static checkServerUrl(servers) {
|
|
329
|
+
static checkServerUrl(servers, allowHttp = false) {
|
|
343
330
|
const errors = [];
|
|
344
331
|
let serverUrl;
|
|
345
332
|
try {
|
|
@@ -362,8 +349,7 @@ class Utils {
|
|
|
362
349
|
data: servers,
|
|
363
350
|
});
|
|
364
351
|
}
|
|
365
|
-
else if (protocol !== "https:") {
|
|
366
|
-
// Http server url is not supported
|
|
352
|
+
else if (protocol !== "https:" && !(protocol === "http:" && allowHttp)) {
|
|
367
353
|
const protocolString = protocol.slice(0, -1);
|
|
368
354
|
errors.push({
|
|
369
355
|
type: ErrorType.UrlProtocolNotSupported,
|
|
@@ -379,10 +365,11 @@ class Utils {
|
|
|
379
365
|
let hasTopLevelServers = false;
|
|
380
366
|
let hasPathLevelServers = false;
|
|
381
367
|
let hasOperationLevelServers = false;
|
|
368
|
+
const allowHttp = options.projectType === ProjectType.Copilot;
|
|
382
369
|
if (spec.servers && spec.servers.length >= 1) {
|
|
383
370
|
hasTopLevelServers = true;
|
|
384
371
|
// for multiple server, we only use the first url
|
|
385
|
-
const serverErrors = Utils.checkServerUrl(spec.servers);
|
|
372
|
+
const serverErrors = Utils.checkServerUrl(spec.servers, allowHttp);
|
|
386
373
|
errors.push(...serverErrors);
|
|
387
374
|
}
|
|
388
375
|
const paths = spec.paths;
|
|
@@ -390,7 +377,7 @@ class Utils {
|
|
|
390
377
|
const methods = paths[path];
|
|
391
378
|
if ((methods === null || methods === void 0 ? void 0 : methods.servers) && methods.servers.length >= 1) {
|
|
392
379
|
hasPathLevelServers = true;
|
|
393
|
-
const serverErrors = Utils.checkServerUrl(methods.servers);
|
|
380
|
+
const serverErrors = Utils.checkServerUrl(methods.servers, allowHttp);
|
|
394
381
|
errors.push(...serverErrors);
|
|
395
382
|
}
|
|
396
383
|
for (const method in methods) {
|
|
@@ -398,7 +385,7 @@ class Utils {
|
|
|
398
385
|
if (((_a = options.allowMethods) === null || _a === void 0 ? void 0 : _a.includes(method)) && operationObject) {
|
|
399
386
|
if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
|
|
400
387
|
hasOperationLevelServers = true;
|
|
401
|
-
const serverErrors = Utils.checkServerUrl(operationObject.servers);
|
|
388
|
+
const serverErrors = Utils.checkServerUrl(operationObject.servers, allowHttp);
|
|
402
389
|
errors.push(...serverErrors);
|
|
403
390
|
}
|
|
404
391
|
}
|
|
@@ -711,8 +698,8 @@ class Validator {
|
|
|
711
698
|
result.reason.push(ErrorType.NoServerInformation);
|
|
712
699
|
}
|
|
713
700
|
else {
|
|
714
|
-
|
|
715
|
-
const serverValidateResult = Utils.checkServerUrl([serverObj]);
|
|
701
|
+
const allowHttp = this.projectType === ProjectType.Copilot;
|
|
702
|
+
const serverValidateResult = Utils.checkServerUrl([serverObj], allowHttp);
|
|
716
703
|
result.reason.push(...serverValidateResult.map((item) => item.type));
|
|
717
704
|
}
|
|
718
705
|
return result;
|
|
@@ -760,11 +747,6 @@ class Validator {
|
|
|
760
747
|
}
|
|
761
748
|
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
762
749
|
const isCopilot = this.projectType === ProjectType.Copilot;
|
|
763
|
-
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
764
|
-
paramResult.isValid = false;
|
|
765
|
-
paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
|
|
766
|
-
return paramResult;
|
|
767
|
-
}
|
|
768
750
|
if (schema.type === "string" ||
|
|
769
751
|
schema.type === "integer" ||
|
|
770
752
|
schema.type === "boolean" ||
|
|
@@ -812,11 +794,6 @@ class Validator {
|
|
|
812
794
|
for (let i = 0; i < paramObject.length; i++) {
|
|
813
795
|
const param = paramObject[i];
|
|
814
796
|
const schema = param.schema;
|
|
815
|
-
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
816
|
-
paramResult.isValid = false;
|
|
817
|
-
paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
|
|
818
|
-
continue;
|
|
819
|
-
}
|
|
820
797
|
const isRequiredWithoutDefault = param.required && schema.default === undefined;
|
|
821
798
|
if (isCopilot) {
|
|
822
799
|
if (isRequiredWithoutDefault) {
|