@penkov/swagger-code-gen 1.11.1 → 1.12.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/AGENTS.md ADDED
@@ -0,0 +1,34 @@
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.
@@ -91,12 +91,8 @@ export function resolvePaths(json, schemasTypes, options, pool) {
91
91
  export function generateInPlace(paths, schemasTypes, options, pool) {
92
92
  const collectInplaceFromProperty = (p) => {
93
93
  if (p.inPlace.isDefined) {
94
- if (p.type === 'array') {
95
- return Collection.of(SchemaObject.fromDefinition(p.items, p.inPlace.get, schemasTypes, options, pool));
96
- }
97
- else {
98
- return Collection.of(SchemaObject.fromDefinition(p.type, p.inPlace.get, schemasTypes, options, pool));
99
- }
94
+ const targetType = p.isArray ? p.items : p.type;
95
+ return Collection.of(SchemaObject.fromDefinition(targetType, p.inPlace.get, schemasTypes, options, pool));
100
96
  }
101
97
  else {
102
98
  return Nil;
@@ -120,7 +116,8 @@ export function generateInPlace(paths, schemasTypes, options, pool) {
120
116
  let pending = res.toCollection.flatMap(s => s.properties).filter(p => p.inPlace.isDefined);
121
117
  while (pending.nonEmpty) {
122
118
  const pass2 = pending.map(p => {
123
- return SchemaObject.fromDefinition(p.type, p.inPlace.get, schemasTypes, options, pool);
119
+ const targetType = p.isArray ? p.items : p.type;
120
+ return SchemaObject.fromDefinition(targetType, p.inPlace.get, schemasTypes, options, pool);
124
121
  });
125
122
  res.appendAll(pass2);
126
123
  pending = pass2.flatMap(s => s.properties).filter(p => p.inPlace.isDefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"