@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.
@@ -35,8 +35,6 @@ var ErrorType;
35
35
  ErrorType["PostBodySchemaIsNotJson"] = "post-body-schema-is-not-json";
36
36
  ErrorType["PostBodyContainsRequiredUnsupportedSchema"] = "post-body-contains-required-unsupported-schema";
37
37
  ErrorType["ParamsContainRequiredUnsupportedSchema"] = "params-contain-required-unsupported-schema";
38
- ErrorType["ParamsContainsNestedObject"] = "params-contains-nested-object";
39
- ErrorType["RequestBodyContainsNestedObject"] = "request-body-contains-nested-object";
40
38
  ErrorType["ExceededRequiredParamsLimit"] = "exceeded-required-params-limit";
41
39
  ErrorType["NoParameter"] = "no-parameter";
42
40
  ErrorType["NoAPIInfo"] = "no-api-info";
@@ -112,7 +110,7 @@ ConstantString.WrappedCardResponseLayout = "list";
112
110
  ConstantString.GetMethod = "get";
113
111
  ConstantString.PostMethod = "post";
114
112
  ConstantString.AdaptiveCardVersion = "1.5";
115
- ConstantString.AdaptiveCardSchema = "http://adaptivecards.io/schemas/adaptive-card.json";
113
+ ConstantString.AdaptiveCardSchema = "https://adaptivecards.io/schemas/adaptive-card.json";
116
114
  ConstantString.AdaptiveCardType = "AdaptiveCard";
117
115
  ConstantString.TextBlockType = "TextBlock";
118
116
  ConstantString.ImageType = "Image";
@@ -191,17 +189,6 @@ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-sche
191
189
 
192
190
  // Copyright (c) Microsoft Corporation.
193
191
  class Utils {
194
- static hasNestedObjectInSchema(schema) {
195
- if (this.isObjectSchema(schema)) {
196
- for (const property in schema.properties) {
197
- const nestedSchema = schema.properties[property];
198
- if (this.isObjectSchema(nestedSchema)) {
199
- return true;
200
- }
201
- }
202
- }
203
- return false;
204
- }
205
192
  static isObjectSchema(schema) {
206
193
  return schema.type === "object" || (!schema.type && !!schema.properties);
207
194
  }
@@ -333,7 +320,7 @@ class Utils {
333
320
  }
334
321
  return newStr;
335
322
  }
336
- static checkServerUrl(servers) {
323
+ static checkServerUrl(servers, allowHttp = false) {
337
324
  const errors = [];
338
325
  let serverUrl;
339
326
  try {
@@ -356,8 +343,7 @@ class Utils {
356
343
  data: servers,
357
344
  });
358
345
  }
359
- else if (protocol !== "https:") {
360
- // Http server url is not supported
346
+ else if (protocol !== "https:" && !(protocol === "http:" && allowHttp)) {
361
347
  const protocolString = protocol.slice(0, -1);
362
348
  errors.push({
363
349
  type: ErrorType.UrlProtocolNotSupported,
@@ -373,10 +359,11 @@ class Utils {
373
359
  let hasTopLevelServers = false;
374
360
  let hasPathLevelServers = false;
375
361
  let hasOperationLevelServers = false;
362
+ const allowHttp = options.projectType === ProjectType.Copilot;
376
363
  if (spec.servers && spec.servers.length >= 1) {
377
364
  hasTopLevelServers = true;
378
365
  // for multiple server, we only use the first url
379
- const serverErrors = Utils.checkServerUrl(spec.servers);
366
+ const serverErrors = Utils.checkServerUrl(spec.servers, allowHttp);
380
367
  errors.push(...serverErrors);
381
368
  }
382
369
  const paths = spec.paths;
@@ -384,7 +371,7 @@ class Utils {
384
371
  const methods = paths[path];
385
372
  if ((methods === null || methods === void 0 ? void 0 : methods.servers) && methods.servers.length >= 1) {
386
373
  hasPathLevelServers = true;
387
- const serverErrors = Utils.checkServerUrl(methods.servers);
374
+ const serverErrors = Utils.checkServerUrl(methods.servers, allowHttp);
388
375
  errors.push(...serverErrors);
389
376
  }
390
377
  for (const method in methods) {
@@ -392,7 +379,7 @@ class Utils {
392
379
  if (((_a = options.allowMethods) === null || _a === void 0 ? void 0 : _a.includes(method)) && operationObject) {
393
380
  if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
394
381
  hasOperationLevelServers = true;
395
- const serverErrors = Utils.checkServerUrl(operationObject.servers);
382
+ const serverErrors = Utils.checkServerUrl(operationObject.servers, allowHttp);
396
383
  errors.push(...serverErrors);
397
384
  }
398
385
  }
@@ -705,8 +692,8 @@ class Validator {
705
692
  result.reason.push(ErrorType.NoServerInformation);
706
693
  }
707
694
  else {
708
- // server url should be absolute url with https protocol
709
- const serverValidateResult = Utils.checkServerUrl([serverObj]);
695
+ const allowHttp = this.projectType === ProjectType.Copilot;
696
+ const serverValidateResult = Utils.checkServerUrl([serverObj], allowHttp);
710
697
  result.reason.push(...serverValidateResult.map((item) => item.type));
711
698
  }
712
699
  return result;
@@ -754,11 +741,6 @@ class Validator {
754
741
  }
755
742
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
756
743
  const isCopilot = this.projectType === ProjectType.Copilot;
757
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
758
- paramResult.isValid = false;
759
- paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
760
- return paramResult;
761
- }
762
744
  if (schema.type === "string" ||
763
745
  schema.type === "integer" ||
764
746
  schema.type === "boolean" ||
@@ -806,11 +788,6 @@ class Validator {
806
788
  for (let i = 0; i < paramObject.length; i++) {
807
789
  const param = paramObject[i];
808
790
  const schema = param.schema;
809
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
810
- paramResult.isValid = false;
811
- paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
812
- continue;
813
- }
814
791
  const isRequiredWithoutDefault = param.required && schema.default === undefined;
815
792
  if (isCopilot) {
816
793
  if (isRequiredWithoutDefault) {