@microsoft/m365-spec-parser 0.1.1-alpha.87f45d762.0 → 0.1.1-alpha.8da24c130.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,6 +173,7 @@ 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
179
  ConstantString.SMERequiredParamsMaxNum = 5;
@@ -204,9 +210,10 @@ class Utils {
204
210
  var _a;
205
211
  const result = [];
206
212
  const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
207
- if (securities && securitySchemas) {
208
- for (let i = 0; i < securities.length; i++) {
209
- 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];
210
217
  const authArray = [];
211
218
  for (const name in security) {
212
219
  const auth = securitySchemas[name];
@@ -223,6 +230,25 @@ class Utils {
223
230
  result.sort((a, b) => a[0].name.localeCompare(b[0].name));
224
231
  return result;
225
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
+ }
226
252
  static updateFirstLetter(str) {
227
253
  return str.charAt(0).toUpperCase() + str.slice(1);
228
254
  }
@@ -604,13 +630,15 @@ class Validator {
604
630
  const result = { isValid: true, reason: [] };
605
631
  const operationObject = this.spec.paths[path][method];
606
632
  const { json, multipleMediaType } = Utils.getResponseJson(operationObject);
607
- // only support response body only contains “application/json” content type
608
- if (multipleMediaType) {
609
- result.reason.push(ErrorType.ResponseContainMultipleMediaTypes);
610
- }
611
- else if (Object.keys(json).length === 0) {
612
- // response body should not be empty
613
- 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
+ }
614
642
  }
615
643
  return result;
616
644
  }
@@ -828,9 +856,6 @@ class CopilotValidator extends Validator {
828
856
  // validate requestBody
829
857
  const requestBody = operationObject.requestBody;
830
858
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
831
- if (Utils.containMultipleMediaTypes(requestBody)) {
832
- result.reason.push(ErrorType.PostBodyContainMultipleMediaTypes);
833
- }
834
859
  if (requestJsonBody) {
835
860
  const requestBodySchema = requestJsonBody.schema;
836
861
  if (requestBodySchema.type !== "object") {
@@ -1024,7 +1049,11 @@ class SpecParser {
1024
1049
  allowBearerTokenAuth: false,
1025
1050
  allowOauth2: false,
1026
1051
  allowMethods: ["get", "post"],
1052
+ allowConversationStarters: false,
1053
+ allowResponseSemantics: false,
1054
+ allowConfirmation: false,
1027
1055
  projectType: ProjectType.SME,
1056
+ isGptPlugin: false,
1028
1057
  };
1029
1058
  this.pathOrSpec = pathOrDoc;
1030
1059
  this.parser = new SwaggerParser();
@@ -1177,12 +1206,8 @@ class SpecParser {
1177
1206
  }
1178
1207
  }
1179
1208
  getAPIs(spec) {
1180
- if (this.apiMap !== undefined) {
1181
- return this.apiMap;
1182
- }
1183
1209
  const validator = this.getValidator(spec);
1184
1210
  const apiMap = validator.listAPIs();
1185
- this.apiMap = apiMap;
1186
1211
  return apiMap;
1187
1212
  }
1188
1213
  getValidator(spec) {