@penkov/swagger-code-gen 1.12.0 → 1.13.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.
- package/dist/renderer.js +3 -3
- package/dist/templates/method.ejs +1 -1
- package/jest.config.cjs +18 -0
- package/package.json +5 -1
- package/tsconfig.jest.json +15 -0
- package/AGENTS.md +0 -34
package/dist/renderer.js
CHANGED
|
@@ -3,11 +3,11 @@ import * as fs from 'fs';
|
|
|
3
3
|
import path, { dirname } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import * as scatsLib from 'scats';
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const currentFilename = typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url);
|
|
7
|
+
const currentDirname = typeof __dirname !== 'undefined' ? __dirname : dirname(currentFilename);
|
|
8
8
|
export class Renderer {
|
|
9
9
|
async renderToFile(schemas, methods, enableScats, targetNode, file) {
|
|
10
|
-
const view = await ejs.renderFile(path.resolve(
|
|
10
|
+
const view = await ejs.renderFile(path.resolve(currentDirname, 'templates/index.ejs'), {
|
|
11
11
|
scatsLib: scatsLib,
|
|
12
12
|
schemas: schemas,
|
|
13
13
|
methods: methods,
|
|
@@ -46,7 +46,7 @@ export async function <%= method.endpointName %><%= body.map(b => b.suffix).getO
|
|
|
46
46
|
<%_ } -%>
|
|
47
47
|
<%_ }) -%>
|
|
48
48
|
<%_ method.parameters.filter(x => x.in === 'query' && !x.required).foreach(p => { -%>
|
|
49
|
-
if (
|
|
49
|
+
if (<%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %> !== undefined) {
|
|
50
50
|
<%_ if (p.isArray) { -%>
|
|
51
51
|
<%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>.forEach(p => {
|
|
52
52
|
queryParams.push(`<%= p.name %>=${p}`);
|
package/jest.config.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @type {import('jest').Config} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest/presets/default-esm',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.(ts|tsx)$': [
|
|
8
|
+
'ts-jest',
|
|
9
|
+
{
|
|
10
|
+
useESM: true,
|
|
11
|
+
tsconfig: './tsconfig.jest.json'
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
moduleNameMapper: {
|
|
16
|
+
'^(\\.{1,2}/.*)\\.js$': '$1'
|
|
17
|
+
}
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@penkov/swagger-code-gen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"generate-client": "./dist/cli.mjs"
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/papirosko/swagger-code-gen#readme",
|
|
24
24
|
"scripts": {
|
|
25
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
25
26
|
"test:petstore": "node --loader ts-node/esm ./src/cli.mjs --enableScats --targetNode --url https://petstore3.swagger.io/api/v3/openapi.json tmp/petstore.ts",
|
|
26
27
|
"clean": "rimraf dist",
|
|
27
28
|
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
|
|
@@ -39,10 +40,13 @@
|
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/ejs": "^3.1.1",
|
|
43
|
+
"@types/jest": "^29.5.12",
|
|
42
44
|
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
43
45
|
"@typescript-eslint/parser": "^5.10.2",
|
|
44
46
|
"eslint": "^7.30.0",
|
|
47
|
+
"jest": "^29.7.0",
|
|
45
48
|
"rimraf": "^3.0.2",
|
|
49
|
+
"ts-jest": "^29.2.5",
|
|
46
50
|
"ts-node": "^10.9.2",
|
|
47
51
|
"typescript": "^4.9.3"
|
|
48
52
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"target": "ES2020",
|
|
7
|
+
"isolatedModules": true,
|
|
8
|
+
"types": ["jest"]
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"src/**/*.ts",
|
|
12
|
+
"src/**/*.mjs",
|
|
13
|
+
"test/**/*.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/AGENTS.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# Repository Guidelines
|
|
2
|
-
|
|
3
|
-
## Project Structure & Module Organization
|
|
4
|
-
- Core TypeScript sources live in `src/` (CLI in `src/cli.mjs`, generators in `src/openapi.ts`, `src/renderer.ts`, helpers in `src/name.utils.ts`, etc.).
|
|
5
|
-
- Handlebars/EJS-style templates for emitted clients are under `src/templates/`; they are copied to `dist/templates/` during build.
|
|
6
|
-
- Built artifacts output to `dist/` (ESM). Keep `dist/` out of PR diffs unless you're publishing.
|
|
7
|
-
- Temporary outputs from local runs can go in `tmp/`; avoid committing generated clients.
|
|
8
|
-
|
|
9
|
-
## Build, Test, and Development Commands
|
|
10
|
-
- `npm run lint` — ESLint over `src/**/*.ts`; fixes simple style issues.
|
|
11
|
-
- `npm run build` — Type-checks with `tsc`, lints, cleans `dist/`, copies templates, and makes the CLI executable.
|
|
12
|
-
- `npm run test:petstore` — Integration sanity check that generates a client from the public Petstore spec into `tmp/petstore.ts`.
|
|
13
|
-
- Local usage example while developing: `node --loader ts-node/esm ./src/cli.mjs --url <openapi.json> --targetNode tmp/client.ts`.
|
|
14
|
-
|
|
15
|
-
## Coding Style & Naming Conventions
|
|
16
|
-
- TypeScript, ESM (`"type": "module"`). Prefer `export`/`import` syntax and avoid CommonJS.
|
|
17
|
-
- Indentation: 2 spaces; keep lines concise and avoid trailing whitespace.
|
|
18
|
-
- Naming: PascalCase for types/interfaces/classes; camelCase for functions/variables; kebab-case for filenames (`method.ts`, `components-parse.ts`).
|
|
19
|
-
- Keep pure generation logic inside `src/` modules; CLI wiring belongs in `src/cli.mjs`.
|
|
20
|
-
- Run `npm run lint` before pushing; configure editors to respect the repo’s ESLint/TypeScript settings (`tsconfig.json`, `tsconfig-eslint.json`).
|
|
21
|
-
|
|
22
|
-
## Testing Guidelines
|
|
23
|
-
- Primary check is code generation parity; use `npm run test:petstore` after generator changes to ensure emitted code compiles and fetch imports are wired when `--targetNode` is used.
|
|
24
|
-
- When adding new parsing/rendering logic, add a minimal fixture OpenAPI snippet under `tmp/` (ignored) and exercise `src/cli.mjs` with `ts-node` to confirm types render as expected.
|
|
25
|
-
- Prefer assertions in future tests under `test/` with `ts-node` if you add unit coverage; mirror file names of the modules under test.
|
|
26
|
-
|
|
27
|
-
## Commit & Pull Request Guidelines
|
|
28
|
-
- Follow existing history: `release: x.y.z` for version bumps; otherwise use `type: short-description` (e.g., `fix: handle nullable refs`, `feat: add tag filter`).
|
|
29
|
-
- Keep PRs small and scoped (parser vs renderer vs CLI). Describe the OpenAPI inputs you validated against and attach generated output snippets when relevant.
|
|
30
|
-
- Link issues when applicable; include reproduction steps for bugs and the exact CLI command used.
|
|
31
|
-
|
|
32
|
-
## Security & Configuration Tips
|
|
33
|
-
- Treat remote specs as untrusted; prefer HTTPS URLs and avoid embedding secrets in command examples.
|
|
34
|
-
- Generated clients may import `node-fetch` when `--targetNode` is passed; ensure the consumer installs it if targeting Node.
|