api-spec-generator 0.0.12-alpha → 0.0.13-alpha
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.
- package/.github/workflows/unit-tests.yml +31 -0
- package/jest.config.js +14 -0
- package/package.json +10 -2
- package/src/OpenApiSpec/openApiSpec.ts +40 -0
- package/src/index.ts +2 -5
- package/tests/OpenApiSpec/openApiSpec.test.ts +23 -0
- package/tsconfig.jest.json +9 -0
- package/tsconfig.json +5 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Build and Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-and-test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
node-version: [22.x]
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: ${{ matrix.node-version }}
|
|
22
|
+
cache: 'npm'
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: npm ci
|
|
26
|
+
|
|
27
|
+
- name: Build
|
|
28
|
+
run: npm run build
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: npm t
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
preset: "ts-jest",
|
|
3
|
+
testEnvironment: "node",
|
|
4
|
+
testRegex: ".*\\.test\\.ts$",
|
|
5
|
+
extensionsToTreatAsEsm: [".ts"],
|
|
6
|
+
transform: {
|
|
7
|
+
"^.+\\.tsx?$": ["ts-jest", { useESM: true, tsconfig: "tsconfig.jest.json" }],
|
|
8
|
+
},
|
|
9
|
+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
10
|
+
collectCoverageFrom: [
|
|
11
|
+
"src/**/*.ts",
|
|
12
|
+
"!src/**/*.d.ts",
|
|
13
|
+
],
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"test:watch": "jest --watch",
|
|
10
|
+
"test:coverage": "jest --coverage"
|
|
9
11
|
},
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -18,7 +20,13 @@
|
|
|
18
20
|
},
|
|
19
21
|
"homepage": "https://github.com/TheDevOpAl/aws-api-gateway-spec-file-generator#readme",
|
|
20
22
|
"devDependencies": {
|
|
23
|
+
"@types/jest": "^30.0.0",
|
|
24
|
+
"@types/node": "^25.2.3",
|
|
25
|
+
"ts-jest": "^29.4.6",
|
|
21
26
|
"typescript": "^5.9.3"
|
|
22
27
|
},
|
|
23
|
-
"
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"zod": "^4.3.6"
|
|
30
|
+
},
|
|
31
|
+
"version": "0.0.13-alpha"
|
|
24
32
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { writeFileSync } from "fs";
|
|
2
|
+
|
|
3
|
+
export class OpenApiSpec {
|
|
4
|
+
private openApi: string = "3.0.1";
|
|
5
|
+
|
|
6
|
+
private paths: any = {};
|
|
7
|
+
private components: any = {};
|
|
8
|
+
private securitySchemes: any = {};
|
|
9
|
+
private writeToYamlFile: boolean = false;
|
|
10
|
+
private fileName: string = "openapi-spec";
|
|
11
|
+
private pathToFiles: string = "./";
|
|
12
|
+
public getOpenApiSpecContent(): any {
|
|
13
|
+
return {
|
|
14
|
+
openapi: this.openApi,
|
|
15
|
+
paths: this.paths,
|
|
16
|
+
components: this.components,
|
|
17
|
+
securitySchemes: this.securitySchemes
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor() {}
|
|
22
|
+
|
|
23
|
+
setOpenApiVersion(version: string): void {
|
|
24
|
+
this.openApi = version;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setFileName(fileName: string): void {
|
|
28
|
+
this.fileName = fileName;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setPathToFiles(pathToFiles: string): void {
|
|
32
|
+
this.pathToFiles = pathToFiles;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
writeOpenApiSpec(): void {
|
|
36
|
+
const specFileContent = this.getOpenApiSpecContent();
|
|
37
|
+
|
|
38
|
+
writeFileSync(`${this.pathToFiles}${this.fileName}.${this.writeToYamlFile ? "yaml" : "json"}`, JSON.stringify(specFileContent, null, 2));
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenApiSpec } from "../../src/index.ts";
|
|
2
|
+
|
|
3
|
+
describe("OpenApiSpec", () => {
|
|
4
|
+
let spec: OpenApiSpec;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
spec = new OpenApiSpec();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should initialize with default OpenAPI version 3.0.1", () => {
|
|
11
|
+
// Note: You may need to make the openApi property public or add a getter to test this
|
|
12
|
+
|
|
13
|
+
const content = spec.getOpenApiSpecContent();
|
|
14
|
+
expect(content).toEqual({components: {}, openapi: "3.0.1", paths: {}, securitySchemes: {}});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should allow setting OpenAPI version", () => {
|
|
18
|
+
spec.setOpenApiVersion("3.1.0");
|
|
19
|
+
// Note: You may need to add a getter to verify this
|
|
20
|
+
const content = spec.getOpenApiSpecContent();
|
|
21
|
+
expect(content).toEqual({components: {}, openapi: "3.1.0", paths: {}, securitySchemes: {}});
|
|
22
|
+
});
|
|
23
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// See also https://aka.ms/tsconfig/module
|
|
10
10
|
"module": "nodenext",
|
|
11
11
|
"target": "esnext",
|
|
12
|
-
"types": [],
|
|
12
|
+
"types": ["node", "jest"],
|
|
13
13
|
// For nodejs:
|
|
14
14
|
// "lib": ["esnext"],
|
|
15
15
|
// "types": ["node"],
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"sourceMap": true,
|
|
20
20
|
"declaration": true,
|
|
21
21
|
"declarationMap": true,
|
|
22
|
+
"noEmit": true,
|
|
22
23
|
|
|
23
24
|
// Stricter Typechecking Options
|
|
24
25
|
"noUncheckedIndexedAccess": true,
|
|
@@ -40,5 +41,7 @@
|
|
|
40
41
|
"noUncheckedSideEffectImports": true,
|
|
41
42
|
"moduleDetection": "force",
|
|
42
43
|
"skipLibCheck": true,
|
|
43
|
-
|
|
44
|
+
"allowImportingTsExtensions": true
|
|
45
|
+
},
|
|
46
|
+
"exclude": ["tests", "node_modules", "dist"]
|
|
44
47
|
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,oBAAoB,YAEzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,GAAG,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|