@microsoft/m365-spec-parser 0.1.1-alpha.42af26ca6.0 → 0.1.1-alpha.4562b2cd0.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.
@@ -87,7 +87,7 @@ ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
87
87
  ConstantString.MissingOperationId = "Missing operationIds: %s.";
88
88
  ConstantString.NoSupportedApi = "No supported API is found in the OpenAPI description document: only GET and POST methods are supported, additionally, there can be at most one required parameter, and no auth is allowed.";
89
89
  ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
90
- ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
90
+ ConstantString.SchemaNotSupported = "'oneOf', 'allOf', 'anyOf', and 'not' schema are not supported: %s.";
91
91
  ConstantString.UnknownSchema = "Unknown schema: %s.";
92
92
  ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
93
93
  ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
@@ -107,9 +107,14 @@ ConstantString.AdaptiveCardVersion = "1.5";
107
107
  ConstantString.AdaptiveCardSchema = "http://adaptivecards.io/schemas/adaptive-card.json";
108
108
  ConstantString.AdaptiveCardType = "AdaptiveCard";
109
109
  ConstantString.TextBlockType = "TextBlock";
110
+ ConstantString.ImageType = "Image";
110
111
  ConstantString.ContainerType = "Container";
111
- ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
112
- ConstantString.OAuthRegistrationIdPostFix = "OAUTH_REGISTRATION_ID";
112
+ ConstantString.RegistrationIdPostfix = {
113
+ apiKey: "REGISTRATION_ID",
114
+ oauth2: "CONFIGURATION_ID",
115
+ http: "REGISTRATION_ID",
116
+ openIdConnect: "REGISTRATION_ID",
117
+ };
113
118
  ConstantString.ResponseCodeFor20X = [
114
119
  "200",
115
120
  "201",
@@ -168,9 +173,11 @@ ConstantString.ShortDescriptionMaxLens = 80;
168
173
  ConstantString.FullDescriptionMaxLens = 4000;
169
174
  ConstantString.CommandDescriptionMaxLens = 128;
170
175
  ConstantString.ParameterDescriptionMaxLens = 128;
176
+ ConstantString.ConversationStarterMaxLens = 50;
171
177
  ConstantString.CommandTitleMaxLens = 32;
172
178
  ConstantString.ParameterTitleMaxLens = 32;
173
- ConstantString.SMERequiredParamsMaxNum = 5;
179
+ ConstantString.SMERequiredParamsMaxNum = 5;
180
+ ConstantString.DefaultPluginId = "plugin_1";
174
181
 
175
182
  // Copyright (c) Microsoft Corporation.
176
183
  class Utils {
@@ -203,9 +210,10 @@ class Utils {
203
210
  var _a;
204
211
  const result = [];
205
212
  const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
206
- if (securities && securitySchemas) {
207
- for (let i = 0; i < securities.length; i++) {
208
- const security = securities[i];
213
+ const securitiesArr = securities !== null && securities !== void 0 ? securities : spec.security;
214
+ if (securitiesArr && securitySchemas) {
215
+ for (let i = 0; i < securitiesArr.length; i++) {
216
+ const security = securitiesArr[i];
209
217
  const authArray = [];
210
218
  for (const name in security) {
211
219
  const auth = securitySchemas[name];
@@ -222,6 +230,25 @@ class Utils {
222
230
  result.sort((a, b) => a[0].name.localeCompare(b[0].name));
223
231
  return result;
224
232
  }
233
+ static getAuthInfo(spec) {
234
+ let authInfo = undefined;
235
+ for (const url in spec.paths) {
236
+ for (const method in spec.paths[url]) {
237
+ const operation = spec.paths[url][method];
238
+ const authArray = Utils.getAuthArray(operation.security, spec);
239
+ if (authArray && authArray.length > 0) {
240
+ const currentAuth = authArray[0][0];
241
+ if (!authInfo) {
242
+ authInfo = authArray[0][0];
243
+ }
244
+ else if (authInfo.name !== currentAuth.name) {
245
+ throw new SpecParserError(ConstantString.MultipleAuthNotSupported, ErrorType.MultipleAuthNotSupported);
246
+ }
247
+ }
248
+ }
249
+ }
250
+ return authInfo;
251
+ }
225
252
  static updateFirstLetter(str) {
226
253
  return str.charAt(0).toUpperCase() + str.slice(1);
227
254
  }
@@ -550,9 +577,16 @@ class Validator {
550
577
  const apiMap = this.listAPIs();
551
578
  const validAPIs = Object.entries(apiMap).filter(([, value]) => value.isValid);
552
579
  if (validAPIs.length === 0) {
580
+ const data = [];
581
+ for (const key in apiMap) {
582
+ const { reason } = apiMap[key];
583
+ const apiInvalidReason = { api: key, reason: reason };
584
+ data.push(apiInvalidReason);
585
+ }
553
586
  result.errors.push({
554
587
  type: ErrorType.NoSupportedApi,
555
588
  content: ConstantString.NoSupportedApi,
589
+ data,
556
590
  });
557
591
  }
558
592
  return result;
@@ -596,13 +630,15 @@ class Validator {
596
630
  const result = { isValid: true, reason: [] };
597
631
  const operationObject = this.spec.paths[path][method];
598
632
  const { json, multipleMediaType } = Utils.getResponseJson(operationObject);
599
- // only support response body only contains “application/json” content type
600
- if (multipleMediaType) {
601
- result.reason.push(ErrorType.ResponseContainMultipleMediaTypes);
602
- }
603
- else if (Object.keys(json).length === 0) {
604
- // response body should not be empty
605
- result.reason.push(ErrorType.ResponseJsonIsEmpty);
633
+ if (this.options.projectType === ProjectType.SME) {
634
+ // only support response body only contains “application/json” content type
635
+ if (multipleMediaType) {
636
+ result.reason.push(ErrorType.ResponseContainMultipleMediaTypes);
637
+ }
638
+ else if (Object.keys(json).length === 0) {
639
+ // response body should not be empty
640
+ result.reason.push(ErrorType.ResponseJsonIsEmpty);
641
+ }
606
642
  }
607
643
  return result;
608
644
  }
@@ -820,9 +856,6 @@ class CopilotValidator extends Validator {
820
856
  // validate requestBody
821
857
  const requestBody = operationObject.requestBody;
822
858
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
823
- if (Utils.containMultipleMediaTypes(requestBody)) {
824
- result.reason.push(ErrorType.PostBodyContainMultipleMediaTypes);
825
- }
826
859
  if (requestJsonBody) {
827
860
  const requestBodySchema = requestJsonBody.schema;
828
861
  if (requestBodySchema.type !== "object") {
@@ -862,8 +895,10 @@ class SMEValidator extends Validator {
862
895
  validationResult = this.validateSpecNoSupportAPI();
863
896
  result.errors.push(...validationResult.errors);
864
897
  // validate operationId missing
865
- validationResult = this.validateSpecOperationId();
866
- result.warnings.push(...validationResult.warnings);
898
+ if (this.options.allowMissingId) {
899
+ validationResult = this.validateSpecOperationId();
900
+ result.warnings.push(...validationResult.warnings);
901
+ }
867
902
  return result;
868
903
  }
869
904
  validateAPI(method, path) {
@@ -1014,7 +1049,11 @@ class SpecParser {
1014
1049
  allowBearerTokenAuth: false,
1015
1050
  allowOauth2: false,
1016
1051
  allowMethods: ["get", "post"],
1052
+ allowConversationStarters: false,
1053
+ allowResponseSemantics: false,
1054
+ allowConfirmation: false,
1017
1055
  projectType: ProjectType.SME,
1056
+ isGptPlugin: false,
1018
1057
  };
1019
1058
  this.pathOrSpec = pathOrDoc;
1020
1059
  this.parser = new SwaggerParser();
@@ -1029,7 +1068,11 @@ class SpecParser {
1029
1068
  try {
1030
1069
  try {
1031
1070
  await this.loadSpec();
1032
- await this.parser.validate(this.spec);
1071
+ await this.parser.validate(this.spec, {
1072
+ validate: {
1073
+ schema: false,
1074
+ },
1075
+ });
1033
1076
  }
1034
1077
  catch (e) {
1035
1078
  return {
@@ -1167,12 +1210,8 @@ class SpecParser {
1167
1210
  }
1168
1211
  }
1169
1212
  getAPIs(spec) {
1170
- if (this.apiMap !== undefined) {
1171
- return this.apiMap;
1172
- }
1173
1213
  const validator = this.getValidator(spec);
1174
1214
  const apiMap = validator.listAPIs();
1175
- this.apiMap = apiMap;
1176
1215
  return apiMap;
1177
1216
  }
1178
1217
  getValidator(spec) {