Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: spec-parser to separate package #10842

Merged
merged 43 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c96011d
perf: init spec-parser package
KennethBWSong Jan 25, 2024
6a414e3
perf(spec-parser): remove unused package, use correct option (#10776)
SLdragon Jan 29, 2024
63401c9
perf: add test (#10789)
KennethBWSong Jan 30, 2024
81996be
test: add browser test (#10796)
KennethBWSong Jan 31, 2024
1d02365
test: fix coverage = 0 bug (#10802)
KennethBWSong Feb 1, 2024
188bdc0
perf: not allow res/req body has type other than json (#10803)
SLdragon Feb 1, 2024
25a890d
ci: add ci for spec-parser (#10805)
KennethBWSong Feb 1, 2024
a67a8ad
ci: add cd for spec parser (#10816)
KennethBWSong Feb 4, 2024
0953606
ci: fix cd for spec parser (#10819)
KennethBWSong Feb 4, 2024
250c46b
ci: update node version to 18 (#10820)
KennethBWSong Feb 4, 2024
27c5f0e
perf(spec-parser): try to fix browser lib issue (#10821)
SLdragon Feb 4, 2024
72f67c4
ci: update version (#10822)
KennethBWSong Feb 4, 2024
511880c
perf: add format for spec parser (#10827)
KennethBWSong Feb 5, 2024
804e450
perf: export utils in spec parser (#10829)
KennethBWSong Feb 5, 2024
3cfc9bf
perf: add license and update package.json (#10837)
KennethBWSong Feb 6, 2024
50e2d74
perf(spec-parser): add README.md and update export (#10838)
SLdragon Feb 6, 2024
23b3c91
ci: update version (#10839)
KennethBWSong Feb 6, 2024
6a7c0b5
perf: init spec-parser package
KennethBWSong Jan 25, 2024
5761291
perf(spec-parser): remove unused package, use correct option (#10776)
SLdragon Jan 29, 2024
a7fc33a
perf: add test (#10789)
KennethBWSong Jan 30, 2024
81fc76d
test: add browser test (#10796)
KennethBWSong Jan 31, 2024
000c519
test: fix coverage = 0 bug (#10802)
KennethBWSong Feb 1, 2024
11babe8
perf: not allow res/req body has type other than json (#10803)
SLdragon Feb 1, 2024
ba4b61f
ci: add ci for spec-parser (#10805)
KennethBWSong Feb 1, 2024
51b0047
ci: add cd for spec parser (#10816)
KennethBWSong Feb 4, 2024
a89bc9f
ci: fix cd for spec parser (#10819)
KennethBWSong Feb 4, 2024
158a3b0
ci: update node version to 18 (#10820)
KennethBWSong Feb 4, 2024
e2ee2b8
perf(spec-parser): try to fix browser lib issue (#10821)
SLdragon Feb 4, 2024
9ac9b79
ci: update version (#10822)
KennethBWSong Feb 4, 2024
83bbd9e
perf: add format for spec parser (#10827)
KennethBWSong Feb 5, 2024
9a52d1a
perf: export utils in spec parser (#10829)
KennethBWSong Feb 5, 2024
b6fe59e
perf: add license and update package.json (#10837)
KennethBWSong Feb 6, 2024
3ec4651
perf(spec-parser): add README.md and update export (#10838)
SLdragon Feb 6, 2024
5b4c8ce
ci: update version (#10839)
KennethBWSong Feb 6, 2024
fc6d2d3
perf: update
KennethBWSong Feb 6, 2024
1f3a637
fix: fix merge conflict
KennethBWSong Feb 6, 2024
b5a3bb0
docs: update readme
KennethBWSong Feb 6, 2024
03183c0
perf: update package.json
KennethBWSong Feb 6, 2024
9fb6acf
test: fix test
KennethBWSong Feb 6, 2024
05f3794
perf: update pnpm-lock
KennethBWSong Feb 6, 2024
7112ba2
test: fix ut
KennethBWSong Feb 7, 2024
08221df
build: update config in webpack
wenytang-ms Feb 7, 2024
87e221b
fix: fix format
KennethBWSong Feb 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions .github/workflows/spec-parser-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,64 @@ run-name: Spec-Parser-${{ github.run_id }}-${{ github.ref_name }}

on:
workflow_dispatch:
inputs:
preid:
description: "preid name(alpha, rc, stable)"
required: true
default: "alpha"

jobs:
cd:
runs-on: ubuntu-latest
steps:
- name: Output
if: ${{ github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/spec-parser' }}
- name: Checkout
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install
working-directory: packages/spec-parser/
run: |
npm install

- name: Build
working-directory: packages/spec-parser/
run: |
npm run build

- name: Setup npm registry
run: |
echo "${{ secrets.NPMRC }}" > ~/.npmrc

- name: Version alpha
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'alpha' }}
working-directory: packages/spec-parser/
run: |
npm version prerelease --preid=alpha

- name: Version rc
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'rc' }}
working-directory: packages/spec-parser/
run: |
npm version prerelease --preid=rc

- name: publish alpha release to npm org
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'alpha' }}
working-directory: packages/spec-parser/
run: |
npm publish --tag alpha

- name: publish rc release to npm org
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'rc' }}
working-directory: packages/spec-parser/
run: |
npm publish --tag rc

- name: publish stable release to npm org
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.preid == 'stable' }}
working-directory: packages/spec-parser/
run: |
echo It's not allowed to run CD on other branch except spec-parser.
exit 1
npm publish
35 changes: 35 additions & 0 deletions .github/workflows/spec-parser-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Spec-Parser CI

on:
push:
paths:
- "packages/spec-parser/**"
branches: ["main", "dev", "prerelease", "spec-parser"]
pull_request:
paths:
- "packages/spec-parser/**"
branches: ["main", "dev", "prerelease", "spec-parser"]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}

- name: Install
working-directory: packages/spec-parser/
run: |
npm install

- name: Test
working-directory: packages/spec-parser/
run: |
npm run test:unit
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ This repository contains the following packages:
| **API** [packages/api](https://github.com/OfficeDev/TeamsFx/tree/main/packages/api) | The API package is a collection of contracts supported by the IDE Extensions and CLI. It enables developers to write plugins to extend TeamsFx with new capabilities. |
| **Core** [packages/fx-core](https://github.com/OfficeDev/TeamsFx/tree/main/packages/fx-core) | The Core package centralizes implementation of capabilities shared by the IDE Extensions and the CLI. |
| **Azure Functions Support** [packages/function-extension](https://github.com/OfficeDev/TeamsFx/tree/main/packages/function-extension) | Teams Toolkit helps developers include server-side code in their Teams application backed by [Azure Functions](https://docs.microsoft.com/azure/azure-functions/). This plugin adds support to simplify the integration of an authentication-aware Azure Function into your Teams app. |
| **Spec Parser** [packages/spec-parser](https://github.com/OfficeDev/TeamsFx/tree/main/packages/spec-parser) | Teams Toolkit automates the process of generating [API-based message extensions](https://learn.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/api-based-overview) and Adaptive Cards by parsing the OpenAPI description document. |

## Contributions

Expand Down
1 change: 1 addition & 0 deletions packages/spec-parser/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist*/*
17 changes: 17 additions & 0 deletions packages/spec-parser/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: __dirname,
},
extends: ["../eslint-plugin-teamsfx/config/shared.js"],
overrides: [
{
files: ["src/*.ts"],
extends: [
"../eslint-plugin-teamsfx/config/header.js",
"../eslint-plugin-teamsfx/config/promise.js",
"../eslint-plugin-teamsfx/config/type.js",
],
},
],
};
7 changes: 7 additions & 0 deletions packages/spec-parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Build results
dist/
types/
coverage-browser/
test-results*.xml
node_modules/
*.tgz
19 changes: 19 additions & 0 deletions packages/spec-parser/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.browser.ts"
],
"reporter": [
"text",
"html",
"json-summary",
"cobertura",
"lcov"
],
"check-coverage": true,
"lines": 0
}
6 changes: 6 additions & 0 deletions packages/spec-parser/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/src/generated/
**/*.d.ts

coverage/
.nyc_output/
.prettierignore
3 changes: 3 additions & 0 deletions packages/spec-parser/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("../prettier-config"),
};
21 changes: 21 additions & 0 deletions packages/spec-parser/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
125 changes: 125 additions & 0 deletions packages/spec-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# M365 Spec Parser

The M365 Spec Parser package is designed to parse OpenAPI specification files to generate resources for M365 applications.

## Sample Usage

### For NodeJS environment
```typescript
import { SpecParser, ParseOptions } from "@microsoft/m365-spec-parser";

// Define parsing options
const option: ParseOptions = {
allowMissingId: true, // Allow missing IDs in the specification, default true
allowSwagger: true, // Allow Swagger specifications, default true
allowAPIKeyAuth: false, // Disallow API key authentication, default false
allowMultipleParameters: false, // Disallow multiple parameters, default false
allowOauth2: false, // Disallow OAuth2 authentication, default false
};

// Create a new SpecParser instance with the given options
const parser = new SpecParser("path/to/spec/file", option);

// Validate the specification
const validateResult = await parser.validate();
// If the specification is not valid, log the errors and warnings
if (validateResult.status !== ValidationStatus.Valid) {
console.log(validateResult.errors);
console.log(validateResult.warnings);
}

// List the operations in the specification
const listResult = await parser.list();
// Log each operation
for (let i = 0; i < listResult.length; i++) {
console.log(listResult[i]);
}

// Define a filter for the operations to generate
const filter = ["GET /pet/{id}"];
// Define the paths for the Teams app manifest file, the output specification file, and the output adaptive card folder
const teamsAppManifestFilePath = "path/to/teamsapp/manifest/file";
const outputSpecFilePath = "path/to/output/spec/path";
const outputAdaptiveCardFolder = "adaptivecard/folder";
// Generate the operations
const generateResult = await parser.generate(
teamsAppManifestFilePath,
filter,
outputSpecFilePath,
outputAdaptiveCardFolder
);

// If not all operations were successfully generated, log the warnings
if (!generateResult.allSuccess) {
console.log(generateResult.warnings);
}
```

### For browser environment
```typescript
import { SpecParser, ParseOptions } from "@microsoft/m365-spec-parser";

// Define parsing options
const option: ParseOptions = {
allowMissingId: false, // Allow missing IDs in the specification, default false
allowSwagger: false, // Allow Swagger specifications, default false
allowAPIKeyAuth: false, // Disallow API key authentication, default false
allowMultipleParameters: false, // Disallow multiple parameters, default false
allowOauth2: false, // Disallow OAuth2 authentication, default false
};

// Create a new SpecParser instance with the given options
const parser = new SpecParser("path/to/spec/file", option);

// Validate the specification
const validateResult = await parser.validate();
// If the specification is not valid, log the errors and warnings
if (validateResult.status !== ValidationStatus.Valid) {
console.log(validateResult.errors);
console.log(validateResult.warnings);
}

// List the operations in the specification
const listResult = await parser.listSupportedAPIInfo();
// Log each operation
for (let i = 0; i < listResult.length; i++) {
console.log(listResult[i]);
}
```

## Data Collection.

The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.

## Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Contributing

There are many ways in which you can participate in the project, for example:

- [Submit bugs and feature requests](https://github.com/OfficeDev/TeamsFx/issues), and help us verify as they are checked in
- Review [source code changes](https://github.com/OfficeDev/TeamsFx/pulls)

If you are interested in fixing issues and contributing directly to the code base, please see the [Contributing Guide](./CONTRIBUTING.md).

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).

If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).

## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

## License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the [MIT](LICENSE.txt) license.
5 changes: 5 additions & 0 deletions packages/spec-parser/config/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extensions": ["ts"],
"spec": ["test/*.test.ts"],
"require": ["ts-node/register"]
}
8 changes: 8 additions & 0 deletions packages/spec-parser/config/mocha.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/*
* Specify test tsconfig file for Windows
*/
process.env.TS_NODE_COMPILER_OPTIONS = '{ "module": "commonjs", "target": "es2016" }';
process.env.TS_NODE_FILES = "true";
52 changes: 52 additions & 0 deletions packages/spec-parser/config/webpack.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const webpack = require("webpack");
module.exports = {
mode: "development",
devtool: "source-map",
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: "ts-loader",
options: {
compilerOptions: {
module: "commonjs",
target: "es2017",
downlevelIteration: true,
resolveJsonModule: true,
},
},
},
},
{
test: /\.[tj]sx?$/,
exclude: /node_modules/,
use: "source-map-loader",
enforce: "pre",
},
],
},
resolve: {
modules: ["node_modules"],
mainFields: ["browser", "module", "main"],
extensions: [".js", ".ts"],
symlinks: true,
fallback: {
url: require.resolve("url/"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
"process/browser": require.resolve("process/browser"),
util: false,
},
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
],
};
Loading
Loading