From 9a06eecddb1bd2b43823cfee44de643c7b6928f4 Mon Sep 17 00:00:00 2001 From: Sheldon Warkentin Date: Mon, 21 Jun 2021 13:30:36 -0600 Subject: [PATCH 1/8] Allow 'title' to be overridden * This change is only at the API level for now (no CLI flag) Set `esModuleInterop` to `true` * This fixes some typescript build errors caused by `GenerateSchema` import --- src/apis/avantation.ts | 8 ++++++-- src/apis/util.ts | 2 +- src/index.ts | 1 + src/interfaces/avantation.ts | 1 + src/templates/avantation.ts | 2 +- tsconfig.json | 1 + 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/apis/avantation.ts b/src/apis/avantation.ts index c751c04..fd5a597 100644 --- a/src/apis/avantation.ts +++ b/src/apis/avantation.ts @@ -14,6 +14,7 @@ const YAML: any = require('json2yaml'); export class AvantationAPI implements Avantation.InputConfig { har: HAR.Final; + title: string; template: OAS.Template; host: string; basePath: string; @@ -31,6 +32,7 @@ export class AvantationAPI implements Avantation.InputConfig { constructor(input: Avantation.InputConfig, oclif: any) { this.har = input.har; + this.title = input.title; this.host = input.host; this.basePath = input.basePath; this.pathParamRegex = input.pathParamRegex; @@ -49,7 +51,7 @@ export class AvantationAPI implements Avantation.InputConfig { private async run() { this.har.log.entries.forEach(this.buildEntry.bind(this)); - this.onBuildComplete(this.template); + this.onBuildComplete(); } logSuccess(head: string): void { @@ -381,7 +383,7 @@ export class AvantationAPI implements Avantation.InputConfig { ]; } - onBuildComplete(openapi: OAS.Template): void { + onBuildComplete(): void { if (!this.template.tags) this.template.tags = []; if (!this.disableTag) @@ -392,6 +394,8 @@ export class AvantationAPI implements Avantation.InputConfig { } let that = this; + this.template.info.title = that.title; + this.template.servers.forEach(function (server: OAS.ServerObject) { server.url = server.url.replace('{host}', that.host); if (server.variables && server.variables.basePath && typeof server.variables.basePath == 'object') { diff --git a/src/apis/util.ts b/src/apis/util.ts index 7771a67..54890a6 100644 --- a/src/apis/util.ts +++ b/src/apis/util.ts @@ -1,5 +1,5 @@ import * as HAR from '../interfaces/har'; -import * as GenerateSchema from './json.js'; +import GenerateSchema from './json.js'; export namespace Util { export function generateSchema(input: any): any { let schema = GenerateSchema(input) diff --git a/src/index.ts b/src/index.ts index ea28940..adb3a57 100644 --- a/src/index.ts +++ b/src/index.ts @@ -102,6 +102,7 @@ class Avantation extends Command { : ""; var input: AvantationInterface.InputConfig = { har: har, + title: "Avantation REST Template", host: host, basePath: flags['base-path'] || '', template: template, diff --git a/src/interfaces/avantation.ts b/src/interfaces/avantation.ts index 1135196..f5a9875 100644 --- a/src/interfaces/avantation.ts +++ b/src/interfaces/avantation.ts @@ -48,6 +48,7 @@ export interface build { export interface InputConfig { har: HAR.Final; + title: string; host: string; basePath: string; template: OAS.Template; diff --git a/src/templates/avantation.ts b/src/templates/avantation.ts index 60952f6..0dcbe30 100644 --- a/src/templates/avantation.ts +++ b/src/templates/avantation.ts @@ -2,7 +2,7 @@ let defaultTemplate: any = { openapi: '3.0.0', info: { version: '1.0', - title: 'Avantation REST Template', + title: '{title}', description: 'TODO: Add Description' }, servers: [ diff --git a/tsconfig.json b/tsconfig.json index 7e6b7c6..2f65037 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "declaration": true, + "esModuleInterop": true, "importHelpers": true, "module": "commonjs", "outDir": "lib", From b51bc9f8160858768a700c61d589f39fce3b46b4 Mon Sep 17 00:00:00 2001 From: anbuksv Date: Mon, 21 Jun 2021 13:52:05 +0530 Subject: [PATCH 2/8] Typo fixed --- README.md | 2 +- package-lock.json | 1 + package.json | 4 ++-- src/index.ts | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1a0ddc4..c7318ba 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@

-avantation is tool the for generate OpenAPI3.0 from HTTP Archive format(HAR). +avantation is a tool to generate an OpenAPI 3.0 specification from HTTP Archive format(HAR). avantation is written and maintained by Anbarasan K (anbuksv@gmail.com). diff --git a/package-lock.json b/package-lock.json index 1c930b3..0ea6530 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "avantation", "version": "2.0.4", "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 8afe08d..c19815d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "avantation", "description": "Build OpenAPI3.0 specification from HAR", - "version": "2.0.4", + "version": "2.0.5", "author": "Anbarasan K (https://www.avantation.in)", "bin": { "avantation": "./bin/run" @@ -45,7 +45,7 @@ "REST", "REST API'S", "API", - "OpenAPI Sepecification", + "OpenAPI Specification", "OAS", "Swagger", "HAR", diff --git a/src/index.ts b/src/index.ts index adb3a57..f2dbdd2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,7 @@ class Avantation extends Command { description: 'Write output result in JSON format.' }), 'disable-tag': flags.boolean({ - description: 'Diable end points grouping based on route path in HAR' + description: 'Disable end points grouping based on route path in HAR' }), 'security-headers': flags.string({ char: 's', @@ -73,7 +73,7 @@ class Avantation extends Command { }), 'http-snippet': flags.boolean({ description: - "Generate HTTP smaple code snippet for request and appedn it as 'x-code-sample' to OpenAPI path object.", + "Generate HTTP sample code snippet for request and append it as 'x-code-sample' to OpenAPI path object.", default: false }) }; From d234a8d3ab995b728bd159bece565e0f85ed434f Mon Sep 17 00:00:00 2001 From: anbuksv Date: Mon, 21 Jun 2021 15:22:46 +0530 Subject: [PATCH 3/8] github action init --- .../workflows/Avantation-Build-Manual-Test.yml | 15 +++++++++++++++ package-lock.json | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/Avantation-Build-Manual-Test.yml diff --git a/.github/workflows/Avantation-Build-Manual-Test.yml b/.github/workflows/Avantation-Build-Manual-Test.yml new file mode 100644 index 0000000..c3a946d --- /dev/null +++ b/.github/workflows/Avantation-Build-Manual-Test.yml @@ -0,0 +1,15 @@ +name: Avantation Package Build Test + +on: workflow_dispatch + +jobs: + gitleaks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Oclif-Dev Installation + run: | + npm install -g @oclif/dev-cli + - name: Package Build + run: | + oclif-dev pack \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0ea6530..e21eb81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "avantation", - "version": "2.0.4", + "version": "2.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "avantation", - "version": "2.0.4", + "version": "2.0.5", "license": "MIT", "dependencies": { "@oclif/command": "^1.5.6", From 2ddc4ca6d2c0d8046ac9cffe98a297aff84484ea Mon Sep 17 00:00:00 2001 From: anbuksv Date: Tue, 22 Jun 2021 08:33:13 +0530 Subject: [PATCH 4/8] github workflow test --- .../Avantation-Build-Manual-Test.yml | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Avantation-Build-Manual-Test.yml b/.github/workflows/Avantation-Build-Manual-Test.yml index c3a946d..9e5cf43 100644 --- a/.github/workflows/Avantation-Build-Manual-Test.yml +++ b/.github/workflows/Avantation-Build-Manual-Test.yml @@ -3,13 +3,60 @@ name: Avantation Package Build Test on: workflow_dispatch jobs: - gitleaks: + Avantation: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Oclif-Dev Installation + - uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Install dependencies + run: npm install + + - name: Install oclif-dev + run: npm install -g @oclif/dev-cli + + - name: Testing + run: npm run test + + - name: Package metadata + id: metadata run: | - npm install -g @oclif/dev-cli + set -x + sudo apt-get install jq + export PACKAGE_VERSION=$(cat package.json | jq -r .version) + export PACKAGE_NAME="avantation-v${PACKAGE_VERSION}" + export PACKAGE_LIST="./dist/${PACKAGE_NAME}/*" + + echo "::set-output name=package-version::${PACKAGE_VERSION}" + echo "::set-output name=package-name::${PACKAGE_NAME}" + echo "::set-output name=package-dir::${PACKAGE_LIST}" + - name: Package Build run: | - oclif-dev pack \ No newline at end of file + oclif-dev pack --root avantation + + # - name: Create Release + # id: create_release + # uses: actions/create-release@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # tag_name: tv1.0.0 #${{ github.ref }} + # release_name: Release tv1.0.0 #${{ github.ref }} + # body_path: Hello world #${{ steps.changelog.outputs.path }} + # draft: false + + - name: Release package to Github #ref: https://hub.github.com/hub-release.1.html + id: upload-plugin-asset + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + set -x + assets=() + export DIR="${{ steps.metadata.outputs.package-dir }}" + for asset in $DIR; do + assets+=("-a" "$asset") + done + tag_name="tv1.0.0" #"${GITHUB_REF##*/}" + hub release create "${assets[@]}" -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" \ No newline at end of file From b663e601769a1b2741ee078d3df87c265f217e1a Mon Sep 17 00:00:00 2001 From: anbuksv Date: Tue, 22 Jun 2021 11:35:00 +0530 Subject: [PATCH 5/8] manual test release ci --- .github/workflows/Avantation-Build-Manual-Test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Avantation-Build-Manual-Test.yml b/.github/workflows/Avantation-Build-Manual-Test.yml index 9e5cf43..b70b893 100644 --- a/.github/workflows/Avantation-Build-Manual-Test.yml +++ b/.github/workflows/Avantation-Build-Manual-Test.yml @@ -59,4 +59,4 @@ jobs: assets+=("-a" "$asset") done tag_name="tv1.0.0" #"${GITHUB_REF##*/}" - hub release create "${assets[@]}" -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" \ No newline at end of file + hub release create "${assets[@]}" -d -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" \ No newline at end of file From 52bd7655d7febfec9d7e693d338883d24988bd58 Mon Sep 17 00:00:00 2001 From: Anbarasan Date: Tue, 22 Jun 2021 11:46:32 +0530 Subject: [PATCH 6/8] Update Avantation-Build-Manual-Test.yml --- .github/workflows/Avantation-Build-Manual-Test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Avantation-Build-Manual-Test.yml b/.github/workflows/Avantation-Build-Manual-Test.yml index b70b893..e62b591 100644 --- a/.github/workflows/Avantation-Build-Manual-Test.yml +++ b/.github/workflows/Avantation-Build-Manual-Test.yml @@ -6,6 +6,7 @@ jobs: Avantation: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '14' @@ -59,4 +60,4 @@ jobs: assets+=("-a" "$asset") done tag_name="tv1.0.0" #"${GITHUB_REF##*/}" - hub release create "${assets[@]}" -d -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" \ No newline at end of file + hub release create "${assets[@]}" -d -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" From 9d41af7bbc028877dfc2067ac4232b65814739b3 Mon Sep 17 00:00:00 2001 From: anbuksv Date: Tue, 22 Jun 2021 11:55:03 +0530 Subject: [PATCH 7/8] package release process automation --- .github/workflows/manual_release_npm.yml | 16 +++++++ .github/workflows/release_github.yml | 54 ++++++++++++++++++++++++ .github/workflows/release_npm.yml | 18 ++++++++ 3 files changed, 88 insertions(+) create mode 100644 .github/workflows/manual_release_npm.yml create mode 100644 .github/workflows/release_github.yml create mode 100644 .github/workflows/release_npm.yml diff --git a/.github/workflows/manual_release_npm.yml b/.github/workflows/manual_release_npm.yml new file mode 100644 index 0000000..f95a5bd --- /dev/null +++ b/.github/workflows/manual_release_npm.yml @@ -0,0 +1,16 @@ +name: Release Package to NPM +on: workflow_dispatch +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v2 + with: + node-version: '14.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml new file mode 100644 index 0000000..b9827ef --- /dev/null +++ b/.github/workflows/release_github.yml @@ -0,0 +1,54 @@ +name: Build and Create Github Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + Avantation: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Install dependencies + run: npm install + + - name: Install oclif-dev + run: npm install -g @oclif/dev-cli + + - name: Testing + run: npm run test + + - name: Package metadata + id: metadata + run: | + set -x + sudo apt-get install jq + export PACKAGE_VERSION=$(cat package.json | jq -r .version) + export PACKAGE_NAME="avantation-v${PACKAGE_VERSION}" + export PACKAGE_LIST="./dist/${PACKAGE_NAME}/*" + + echo "::set-output name=package-version::${PACKAGE_VERSION}" + echo "::set-output name=package-name::${PACKAGE_NAME}" + echo "::set-output name=package-dir::${PACKAGE_LIST}" + + - name: Package Build + run: oclif-dev pack + + - name: Release package to Github #ref: https://hub.github.com/hub-release.1.html + id: upload-plugin-asset + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + set -x + assets=() + export DIR="${{ steps.metadata.outputs.package-dir }}" + for asset in $DIR; do + assets+=("-a" "$asset") + done + tag_name="${{ github.ref }}" + hub release create "${assets[@]}" -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" \ No newline at end of file diff --git a/.github/workflows/release_npm.yml b/.github/workflows/release_npm.yml new file mode 100644 index 0000000..626df25 --- /dev/null +++ b/.github/workflows/release_npm.yml @@ -0,0 +1,18 @@ +name: Release Package to NPM +on: + release: + types: [created] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v2 + with: + node-version: '14.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file From f9e6fb1f44b988b525037e8f0850b881f145716e Mon Sep 17 00:00:00 2001 From: anbuksv Date: Tue, 22 Jun 2021 12:05:14 +0530 Subject: [PATCH 8/8] github actions updated --- .github/workflows/manual_release_npm.yml | 2 +- .github/workflows/release_github.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/manual_release_npm.yml b/.github/workflows/manual_release_npm.yml index f95a5bd..d93ed46 100644 --- a/.github/workflows/manual_release_npm.yml +++ b/.github/workflows/manual_release_npm.yml @@ -1,4 +1,4 @@ -name: Release Package to NPM +name: Manual Release Package to NPM on: workflow_dispatch jobs: build: diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml index b9827ef..09b22b3 100644 --- a/.github/workflows/release_github.yml +++ b/.github/workflows/release_github.yml @@ -50,5 +50,5 @@ jobs: for asset in $DIR; do assets+=("-a" "$asset") done - tag_name="${{ github.ref }}" - hub release create "${assets[@]}" -m "$tag_name" "v${{ steps.metadata.outputs.package-name }}" \ No newline at end of file + tag_name="${GITHUB_REF##*/}" #${{ github.ref }} + hub release create "${assets[@]}" -m "$tag_name" "${{ steps.metadata.outputs.package-name }}" \ No newline at end of file