@microsoft/m365-spec-parser 0.1.1-alpha.cd2ba87f2.0 → 0.1.1-alpha.d1a09e202.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.
@@ -67,7 +67,7 @@ export declare enum ErrorType {
67
67
  NoExtraAPICanBeAdded = "no-extra-api-can-be-added",
68
68
  ResolveServerUrlFailed = "resolve-server-url-failed",
69
69
  SwaggerNotSupported = "swagger-not-supported",
70
- MultipleAPIKeyNotSupported = "multiple-api-key-not-supported",
70
+ MultipleAuthNotSupported = "multiple-auth-not-supported",
71
71
  ListFailed = "list-failed",
72
72
  listSupportedAPIInfoFailed = "list-supported-api-info-failed",
73
73
  FilterSpecFailed = "filter-spec-failed",
@@ -75,6 +75,7 @@ export declare enum ErrorType {
75
75
  GenerateAdaptiveCardFailed = "generate-adaptive-card-failed",
76
76
  GenerateFailed = "generate-failed",
77
77
  ValidateFailed = "validate-failed",
78
+ GetSpecFailed = "get-spec-failed",
78
79
  Cancelled = "cancelled",
79
80
  Unknown = "unknown"
80
81
  }
@@ -152,11 +153,44 @@ export interface CheckParamResult {
152
153
  isValid: boolean;
153
154
  }
154
155
  export interface ParseOptions {
156
+ /**
157
+ * If true, the parser will not throw an error if an ID is missing the spec file.
158
+ */
155
159
  allowMissingId?: boolean;
160
+ /**
161
+ * If true, the parser will allow parsing of Swagger specifications.
162
+ */
156
163
  allowSwagger?: boolean;
164
+ /**
165
+ * If true, the parser will allow API Key authentication in the spec file.
166
+ */
157
167
  allowAPIKeyAuth?: boolean;
168
+ /**
169
+ * If true, the parser will allow Bearer Token authentication in the spec file.
170
+ */
171
+ allowBearerTokenAuth?: boolean;
172
+ /**
173
+ * If true, the parser will allow multiple parameters in the spec file. Teams AI project would ignore this parameters and always true
174
+ */
158
175
  allowMultipleParameters?: boolean;
176
+ /**
177
+ * If true, the parser will allow OAuth2 authentication in the spec file. Currently only support OAuth2 with auth code flow.
178
+ */
159
179
  allowOauth2?: boolean;
180
+ /**
181
+ * An array of HTTP methods that the parser will allow in the spec file.
182
+ */
183
+ allowMethods?: string[];
184
+ /**
185
+ * The type of project that the parser is being used for.
186
+ * Project can be SME/Copilot/TeamsAi
187
+ */
188
+ projectType?: ProjectType;
189
+ }
190
+ export declare enum ProjectType {
191
+ Copilot = 0,
192
+ SME = 1,
193
+ TeamsAi = 2
160
194
  }
161
195
  export interface APIInfo {
162
196
  method: string;
@@ -173,7 +207,7 @@ export interface ListAPIResult {
173
207
  operationId: string;
174
208
  auth?: OpenAPIV3.SecuritySchemeObject;
175
209
  }
176
- export interface AuthSchema {
177
- authSchema: OpenAPIV3.SecuritySchemeObject;
210
+ export interface AuthInfo {
211
+ authScheme: OpenAPIV3.SecuritySchemeObject;
178
212
  name: string;
179
213
  }
@@ -1,8 +1,12 @@
1
1
  import { OpenAPIV3 } from "openapi-types";
2
- import { WarningResult } from "./interfaces";
3
- import { IMessagingExtensionCommand, TeamsAppManifest } from "@microsoft/teams-manifest";
2
+ import { AuthInfo, ParseOptions, WarningResult } from "./interfaces";
3
+ import { IMessagingExtensionCommand, TeamsAppManifest, PluginManifestSchema, FunctionParameter } from "@microsoft/teams-manifest";
4
4
  export declare class ManifestUpdater {
5
- static updateManifest(manifestPath: string, outputSpecPath: string, adaptiveCardFolder: string, spec: OpenAPIV3.Document, allowMultipleParameters: boolean, auth?: OpenAPIV3.SecuritySchemeObject): Promise<[TeamsAppManifest, WarningResult[]]>;
6
- static generateCommands(spec: OpenAPIV3.Document, adaptiveCardFolder: string, manifestPath: string, allowMultipleParameters: boolean): Promise<[IMessagingExtensionCommand[], WarningResult[]]>;
5
+ static updateManifestWithAiPlugin(manifestPath: string, outputSpecPath: string, apiPluginFilePath: string, spec: OpenAPIV3.Document, options: ParseOptions): Promise<[TeamsAppManifest, PluginManifestSchema]>;
6
+ static updateManifestDescription(manifest: TeamsAppManifest, spec: OpenAPIV3.Document): void;
7
+ static mapOpenAPISchemaToFuncParam(schema: OpenAPIV3.SchemaObject, method: string, pathUrl: string): FunctionParameter;
8
+ static generatePluginManifestSchema(spec: OpenAPIV3.Document, specRelativePath: string, options: ParseOptions): PluginManifestSchema;
9
+ static updateManifest(manifestPath: string, outputSpecPath: string, spec: OpenAPIV3.Document, options: ParseOptions, adaptiveCardFolder?: string, authInfo?: AuthInfo): Promise<[TeamsAppManifest, WarningResult[]]>;
10
+ static generateCommands(spec: OpenAPIV3.Document, manifestPath: string, options: ParseOptions, adaptiveCardFolder?: string): Promise<[IMessagingExtensionCommand[], WarningResult[]]>;
7
11
  static getRelativePath(from: string, to: string): string;
8
12
  }
@@ -1,4 +1,5 @@
1
1
  import { OpenAPIV3 } from "openapi-types";
2
+ import { ParseOptions } from "./interfaces";
2
3
  export declare class SpecFilter {
3
- static specFilter(filter: string[], unResolveSpec: OpenAPIV3.Document, resolvedSpec: OpenAPIV3.Document, allowMissingId: boolean, allowAPIKeyAuth: boolean, allowMultipleParameters: boolean, allowOauth2: boolean): OpenAPIV3.Document;
4
+ static specFilter(filter: string[], unResolveSpec: OpenAPIV3.Document, resolvedSpec: OpenAPIV3.Document, options: ParseOptions): OpenAPIV3.Document;
4
5
  }
@@ -32,14 +32,28 @@ export declare class SpecParser {
32
32
  * according to copilot plugin spec, only list get and post method without auth
33
33
  */
34
34
  list(): Promise<ListAPIResult[]>;
35
+ /**
36
+ * Generate specs according to the filters.
37
+ * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
38
+ */
39
+ getFilteredSpecs(filter: string[], signal?: AbortSignal): Promise<[OpenAPIV3.Document, OpenAPIV3.Document]>;
40
+ /**
41
+ * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
42
+ * @param manifestPath A file path of the Teams app manifest file to update.
43
+ * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
44
+ * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
45
+ * @param pluginFilePath File path of the api plugin file to generate.
46
+ */
47
+ generateForCopilot(manifestPath: string, filter: string[], outputSpecPath: string, pluginFilePath: string, signal?: AbortSignal): Promise<GenerateResult>;
35
48
  /**
36
49
  * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
37
50
  * @param manifestPath A file path of the Teams app manifest file to update.
38
51
  * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
39
52
  * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
40
53
  * @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
54
+ * @param isMe Boolean that indicates whether the project is an Messaging Extension. For Messaging Extension, composeExtensions will be added in Teams app manifest.
41
55
  */
42
- generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder: string, signal?: AbortSignal): Promise<GenerateResult>;
56
+ generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder?: string, signal?: AbortSignal): Promise<GenerateResult>;
43
57
  private loadSpec;
44
58
  private getAllSupportedAPIs;
45
59
  }
@@ -32,6 +32,19 @@ export declare class SpecParser {
32
32
  * according to copilot plugin spec, only list get and post method without auth
33
33
  */
34
34
  list(): Promise<ListAPIResult[]>;
35
+ /**
36
+ * Generate specs according to the filters.
37
+ * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
38
+ */
39
+ getFilteredSpecs(filter: string[], signal?: AbortSignal): Promise<[OpenAPIV3.Document, OpenAPIV3.Document]>;
40
+ /**
41
+ * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
42
+ * @param manifestPath A file path of the Teams app manifest file to update.
43
+ * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
44
+ * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
45
+ * @param pluginFilePath File path of the api plugin file to generate.
46
+ */
47
+ generateForCopilot(manifestPath: string, filter: string[], outputSpecPath: string, pluginFilePath: string, signal?: AbortSignal): Promise<GenerateResult>;
35
48
  /**
36
49
  * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
37
50
  * @param manifestPath A file path of the Teams app manifest file to update.
@@ -39,7 +52,7 @@ export declare class SpecParser {
39
52
  * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
40
53
  * @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
41
54
  */
42
- generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder: string, signal?: AbortSignal): Promise<GenerateResult>;
55
+ generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder?: string, signal?: AbortSignal): Promise<GenerateResult>;
43
56
  private loadSpec;
44
57
  private getAllSupportedAPIs;
45
58
  }
@@ -1,10 +1,12 @@
1
1
  import { OpenAPIV3 } from "openapi-types";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
- import { AuthSchema, CheckParamResult, ErrorResult, Parameter, ValidateResult, WarningResult } from "./interfaces";
3
+ import { AuthInfo, CheckParamResult, ErrorResult, Parameter, ParseOptions, ValidateResult, WarningResult } from "./interfaces";
4
4
  import { IMessagingExtensionCommand } from "@microsoft/teams-manifest";
5
5
  export declare class Utils {
6
- static checkParameters(paramObject: OpenAPIV3.ParameterObject[]): CheckParamResult;
7
- static checkPostBody(schema: OpenAPIV3.SchemaObject, isRequired?: boolean): CheckParamResult;
6
+ static hasNestedObjectInSchema(schema: OpenAPIV3.SchemaObject): boolean;
7
+ static checkParameters(paramObject: OpenAPIV3.ParameterObject[], isCopilot: boolean): CheckParamResult;
8
+ static checkPostBody(schema: OpenAPIV3.SchemaObject, isRequired?: boolean, isCopilot?: boolean): CheckParamResult;
9
+ static containMultipleMediaTypes(bodyObject: OpenAPIV3.RequestBodyObject | OpenAPIV3.ResponseObject): boolean;
8
10
  /**
9
11
  * Checks if the given API is supported.
10
12
  * @param {string} method - The HTTP method of the API.
@@ -19,26 +21,27 @@ export declare class Utils {
19
21
  * 5. response body should be “application/json” and not empty, and response code should be 20X
20
22
  * 6. only support request body with “application/json” content type
21
23
  */
22
- static isSupportedApi(method: string, path: string, spec: OpenAPIV3.Document, allowMissingId: boolean, allowAPIKeyAuth: boolean, allowMultipleParameters: boolean, allowOauth2: boolean): boolean;
23
- static isSupportedAuth(authSchemaArray: AuthSchema[][], allowAPIKeyAuth: boolean, allowOauth2: boolean): boolean;
24
- static isAPIKeyAuth(authSchema: OpenAPIV3.SecuritySchemeObject): boolean;
25
- static isBearerTokenAuth(authSchema: OpenAPIV3.SecuritySchemeObject): boolean;
26
- static getAuthArray(securities: OpenAPIV3.SecurityRequirementObject[] | undefined, spec: OpenAPIV3.Document): AuthSchema[][];
24
+ static isSupportedApi(method: string, path: string, spec: OpenAPIV3.Document, options: ParseOptions): boolean;
25
+ static isSupportedAuth(authSchemeArray: AuthInfo[][], options: ParseOptions): boolean;
26
+ static isBearerTokenAuth(authScheme: OpenAPIV3.SecuritySchemeObject): boolean;
27
+ static isAPIKeyAuth(authScheme: OpenAPIV3.SecuritySchemeObject): boolean;
28
+ static isOAuthWithAuthCodeFlow(authScheme: OpenAPIV3.SecuritySchemeObject): boolean;
29
+ static getAuthArray(securities: OpenAPIV3.SecurityRequirementObject[] | undefined, spec: OpenAPIV3.Document): AuthInfo[][];
27
30
  static updateFirstLetter(str: string): string;
28
- static getResponseJson(operationObject: OpenAPIV3.OperationObject | undefined): OpenAPIV3.MediaTypeObject;
31
+ static getResponseJson(operationObject: OpenAPIV3.OperationObject | undefined, isTeamsAiProject?: boolean): OpenAPIV3.MediaTypeObject;
29
32
  static convertPathToCamelCase(path: string): string;
30
33
  static getUrlProtocol(urlString: string): string | undefined;
31
34
  static resolveServerUrl(url: string): string;
32
35
  static checkServerUrl(servers: OpenAPIV3.ServerObject[]): ErrorResult[];
33
- static validateServer(spec: OpenAPIV3.Document, allowMissingId: boolean, allowAPIKeyAuth: boolean, allowMultipleParameters: boolean, allowOauth2: boolean): ErrorResult[];
36
+ static validateServer(spec: OpenAPIV3.Document, options: ParseOptions): ErrorResult[];
34
37
  static isWellKnownName(name: string, wellknownNameList: string[]): boolean;
35
38
  static generateParametersFromSchema(schema: OpenAPIV3.SchemaObject, name: string, allowMultipleParameters: boolean, isRequired?: boolean): [Parameter[], Parameter[]];
36
39
  static updateParameterWithInputType(schema: OpenAPIV3.SchemaObject, param: Parameter): void;
37
- static parseApiInfo(operationItem: OpenAPIV3.OperationObject, allowMultipleParameters: boolean): [IMessagingExtensionCommand, WarningResult | undefined];
38
- static listSupportedAPIs(spec: OpenAPIV3.Document, allowMissingId: boolean, allowAPIKeyAuth: boolean, allowMultipleParameters: boolean, allowOauth2: boolean): {
40
+ static parseApiInfo(operationItem: OpenAPIV3.OperationObject, options: ParseOptions): [IMessagingExtensionCommand, WarningResult | undefined];
41
+ static listSupportedAPIs(spec: OpenAPIV3.Document, options: ParseOptions): {
39
42
  [key: string]: OpenAPIV3.OperationObject;
40
43
  };
41
- static validateSpec(spec: OpenAPIV3.Document, parser: SwaggerParser, isSwaggerFile: boolean, allowMissingId: boolean, allowAPIKeyAuth: boolean, allowMultipleParameters: boolean, allowOauth2: boolean): ValidateResult;
44
+ static validateSpec(spec: OpenAPIV3.Document, parser: SwaggerParser, isSwaggerFile: boolean, options: ParseOptions): ValidateResult;
42
45
  static format(str: string, ...args: string[]): string;
43
46
  static getSafeRegistrationIdEnvName(authName: string): string;
44
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/m365-spec-parser",
3
- "version": "0.1.1-alpha.cd2ba87f2.0",
3
+ "version": "0.1.1-alpha.d1a09e202.0",
4
4
  "description": "OpenAPI specification files Parser for M365 Apps",
5
5
  "main": "dist/index.node.cjs.js",
6
6
  "browser": "dist/index.esm2017.js",
@@ -9,7 +9,7 @@
9
9
  "types": "dist/src/index.d.ts",
10
10
  "scripts": {
11
11
  "build": "rollup -c",
12
- "test:unit:node": "nyc --no-clean -- mocha \"test/*.test.ts\" -r config/mocha.env.ts --config config/.mocharc.json",
12
+ "test:unit:node": "nyc --no-clean -- mocha -r config/mocha.env.ts --config config/.mocharc.json",
13
13
  "test:unit:browser": "karma start karma.conf.cjs --single-run --unit",
14
14
  "test:unit": "npm run test:unit:node && npm run test:unit:browser ",
15
15
  "lint:staged": "lint-staged",
@@ -39,7 +39,7 @@
39
39
  "sideEffects": false,
40
40
  "dependencies": {
41
41
  "@apidevtools/swagger-parser": "^10.1.0",
42
- "@microsoft/teams-manifest": "0.1.4-alpha.cd2ba87f2.0",
42
+ "@microsoft/teams-manifest": "0.1.4-alpha.d1a09e202.0",
43
43
  "fs-extra": "^11.2.0",
44
44
  "js-yaml": "^4.1.0",
45
45
  "openapi-types": "^7.2.3",
@@ -148,5 +148,5 @@
148
148
  "npx eslint --cache --fix --quiet"
149
149
  ]
150
150
  },
151
- "gitHead": "3965b434b4be4c2ee6465081ce0ff0577d3aee28"
151
+ "gitHead": "9136f341e4e833a2f7e8e72b400684b59547ea44"
152
152
  }