@penkov/swagger-code-gen 1.11.1 → 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.
@@ -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/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 __filename = fileURLToPath(import.meta.url);
7
- const __dirname = dirname(__filename);
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(__dirname, 'templates/index.ejs'), {
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 (!!<%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %>) {
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}`);
@@ -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.11.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
+ }