@microsoft/m365-spec-parser 0.1.1-alpha.f4dd51600.0 → 0.1.1-alpha.fbb412c19.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.";
@@ -109,8 +109,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
109
109
  ConstantString.TextBlockType = "TextBlock";
110
110
  ConstantString.ImageType = "Image";
111
111
  ConstantString.ContainerType = "Container";
112
- ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
113
- 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
+ };
114
118
  ConstantString.ResponseCodeFor20X = [
115
119
  "200",
116
120
  "201",
@@ -169,6 +173,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
169
173
  ConstantString.FullDescriptionMaxLens = 4000;
170
174
  ConstantString.CommandDescriptionMaxLens = 128;
171
175
  ConstantString.ParameterDescriptionMaxLens = 128;
176
+ ConstantString.ConversationStarterMaxLens = 50;
172
177
  ConstantString.CommandTitleMaxLens = 32;
173
178
  ConstantString.ParameterTitleMaxLens = 32;
174
179
  ConstantString.SMERequiredParamsMaxNum = 5;
@@ -205,9 +210,10 @@ class Utils {
205
210
  var _a;
206
211
  const result = [];
207
212
  const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
208
- if (securities && securitySchemas) {
209
- for (let i = 0; i < securities.length; i++) {
210
- 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];
211
217
  const authArray = [];
212
218
  for (const name in security) {
213
219
  const auth = securitySchemas[name];
@@ -224,6 +230,25 @@ class Utils {
224
230
  result.sort((a, b) => a[0].name.localeCompare(b[0].name));
225
231
  return result;
226
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
+ }
227
252
  static updateFirstLetter(str) {
228
253
  return str.charAt(0).toUpperCase() + str.slice(1);
229
254
  }
@@ -605,13 +630,15 @@ class Validator {
605
630
  const result = { isValid: true, reason: [] };
606
631
  const operationObject = this.spec.paths[path][method];
607
632
  const { json, multipleMediaType } = Utils.getResponseJson(operationObject);
608
- // only support response body only contains “application/json” content type
609
- if (multipleMediaType) {
610
- result.reason.push(ErrorType.ResponseContainMultipleMediaTypes);
611
- }
612
- else if (Object.keys(json).length === 0) {
613
- // response body should not be empty
614
- 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
+ }
615
642
  }
616
643
  return result;
617
644
  }
@@ -829,9 +856,6 @@ class CopilotValidator extends Validator {
829
856
  // validate requestBody
830
857
  const requestBody = operationObject.requestBody;
831
858
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
832
- if (Utils.containMultipleMediaTypes(requestBody)) {
833
- result.reason.push(ErrorType.PostBodyContainMultipleMediaTypes);
834
- }
835
859
  if (requestJsonBody) {
836
860
  const requestBodySchema = requestJsonBody.schema;
837
861
  if (requestBodySchema.type !== "object") {
@@ -1027,7 +1051,9 @@ class SpecParser {
1027
1051
  allowMethods: ["get", "post"],
1028
1052
  allowConversationStarters: false,
1029
1053
  allowResponseSemantics: false,
1054
+ allowConfirmation: false,
1030
1055
  projectType: ProjectType.SME,
1056
+ isGptPlugin: false,
1031
1057
  };
1032
1058
  this.pathOrSpec = pathOrDoc;
1033
1059
  this.parser = new SwaggerParser();
@@ -1042,7 +1068,11 @@ class SpecParser {
1042
1068
  try {
1043
1069
  try {
1044
1070
  await this.loadSpec();
1045
- await this.parser.validate(this.spec);
1071
+ await this.parser.validate(this.spec, {
1072
+ validate: {
1073
+ schema: false,
1074
+ },
1075
+ });
1046
1076
  }
1047
1077
  catch (e) {
1048
1078
  return {