@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.
@@ -83,8 +83,6 @@ exports.ErrorType = void 0;
83
83
  ErrorType["PostBodySchemaIsNotJson"] = "post-body-schema-is-not-json";
84
84
  ErrorType["PostBodyContainsRequiredUnsupportedSchema"] = "post-body-contains-required-unsupported-schema";
85
85
  ErrorType["ParamsContainRequiredUnsupportedSchema"] = "params-contain-required-unsupported-schema";
86
- ErrorType["ParamsContainsNestedObject"] = "params-contains-nested-object";
87
- ErrorType["RequestBodyContainsNestedObject"] = "request-body-contains-nested-object";
88
86
  ErrorType["ExceededRequiredParamsLimit"] = "exceeded-required-params-limit";
89
87
  ErrorType["NoParameter"] = "no-parameter";
90
88
  ErrorType["NoAPIInfo"] = "no-api-info";
@@ -152,7 +150,7 @@ ConstantString.WrappedCardResponseLayout = "list";
152
150
  ConstantString.GetMethod = "get";
153
151
  ConstantString.PostMethod = "post";
154
152
  ConstantString.AdaptiveCardVersion = "1.5";
155
- ConstantString.AdaptiveCardSchema = "http://adaptivecards.io/schemas/adaptive-card.json";
153
+ ConstantString.AdaptiveCardSchema = "https://adaptivecards.io/schemas/adaptive-card.json";
156
154
  ConstantString.AdaptiveCardType = "AdaptiveCard";
157
155
  ConstantString.TextBlockType = "TextBlock";
158
156
  ConstantString.ImageType = "Image";
@@ -239,17 +237,6 @@ class SpecParserError extends Error {
239
237
 
240
238
  // Copyright (c) Microsoft Corporation.
241
239
  class Utils {
242
- static hasNestedObjectInSchema(schema) {
243
- if (this.isObjectSchema(schema)) {
244
- for (const property in schema.properties) {
245
- const nestedSchema = schema.properties[property];
246
- if (this.isObjectSchema(nestedSchema)) {
247
- return true;
248
- }
249
- }
250
- }
251
- return false;
252
- }
253
240
  static isObjectSchema(schema) {
254
241
  return schema.type === "object" || (!schema.type && !!schema.properties);
255
242
  }
@@ -381,7 +368,7 @@ class Utils {
381
368
  }
382
369
  return newStr;
383
370
  }
384
- static checkServerUrl(servers) {
371
+ static checkServerUrl(servers, allowHttp = false) {
385
372
  const errors = [];
386
373
  let serverUrl;
387
374
  try {
@@ -404,8 +391,7 @@ class Utils {
404
391
  data: servers,
405
392
  });
406
393
  }
407
- else if (protocol !== "https:") {
408
- // Http server url is not supported
394
+ else if (protocol !== "https:" && !(protocol === "http:" && allowHttp)) {
409
395
  const protocolString = protocol.slice(0, -1);
410
396
  errors.push({
411
397
  type: exports.ErrorType.UrlProtocolNotSupported,
@@ -421,10 +407,11 @@ class Utils {
421
407
  let hasTopLevelServers = false;
422
408
  let hasPathLevelServers = false;
423
409
  let hasOperationLevelServers = false;
410
+ const allowHttp = options.projectType === exports.ProjectType.Copilot;
424
411
  if (spec.servers && spec.servers.length >= 1) {
425
412
  hasTopLevelServers = true;
426
413
  // for multiple server, we only use the first url
427
- const serverErrors = Utils.checkServerUrl(spec.servers);
414
+ const serverErrors = Utils.checkServerUrl(spec.servers, allowHttp);
428
415
  errors.push(...serverErrors);
429
416
  }
430
417
  const paths = spec.paths;
@@ -432,7 +419,7 @@ class Utils {
432
419
  const methods = paths[path];
433
420
  if ((methods === null || methods === void 0 ? void 0 : methods.servers) && methods.servers.length >= 1) {
434
421
  hasPathLevelServers = true;
435
- const serverErrors = Utils.checkServerUrl(methods.servers);
422
+ const serverErrors = Utils.checkServerUrl(methods.servers, allowHttp);
436
423
  errors.push(...serverErrors);
437
424
  }
438
425
  for (const method in methods) {
@@ -440,7 +427,7 @@ class Utils {
440
427
  if (((_a = options.allowMethods) === null || _a === void 0 ? void 0 : _a.includes(method)) && operationObject) {
441
428
  if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
442
429
  hasOperationLevelServers = true;
443
- const serverErrors = Utils.checkServerUrl(operationObject.servers);
430
+ const serverErrors = Utils.checkServerUrl(operationObject.servers, allowHttp);
444
431
  errors.push(...serverErrors);
445
432
  }
446
433
  }
@@ -753,8 +740,8 @@ class Validator {
753
740
  result.reason.push(exports.ErrorType.NoServerInformation);
754
741
  }
755
742
  else {
756
- // server url should be absolute url with https protocol
757
- const serverValidateResult = Utils.checkServerUrl([serverObj]);
743
+ const allowHttp = this.projectType === exports.ProjectType.Copilot;
744
+ const serverValidateResult = Utils.checkServerUrl([serverObj], allowHttp);
758
745
  result.reason.push(...serverValidateResult.map((item) => item.type));
759
746
  }
760
747
  return result;
@@ -802,11 +789,6 @@ class Validator {
802
789
  }
803
790
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
804
791
  const isCopilot = this.projectType === exports.ProjectType.Copilot;
805
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
806
- paramResult.isValid = false;
807
- paramResult.reason = [exports.ErrorType.RequestBodyContainsNestedObject];
808
- return paramResult;
809
- }
810
792
  if (schema.type === "string" ||
811
793
  schema.type === "integer" ||
812
794
  schema.type === "boolean" ||
@@ -854,11 +836,6 @@ class Validator {
854
836
  for (let i = 0; i < paramObject.length; i++) {
855
837
  const param = paramObject[i];
856
838
  const schema = param.schema;
857
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
858
- paramResult.isValid = false;
859
- paramResult.reason.push(exports.ErrorType.ParamsContainsNestedObject);
860
- continue;
861
- }
862
839
  const isRequiredWithoutDefault = param.required && schema.default === undefined;
863
840
  if (isCopilot) {
864
841
  if (isRequiredWithoutDefault) {