@penkov/swagger-code-gen 1.6.2 → 1.6.3

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/README.md CHANGED
@@ -26,6 +26,7 @@ Cli parameters:
26
26
  (which is default in .net world: asp generates wrong spec)
27
27
  * `--enableScats` - generate additional wrappers in [scats](https://www.npmjs.com/package/scats)
28
28
  style for all objects and create a service with methods for each endpoint.
29
+ * `--targetNode` - adds imports for `node-fetch` package in generated code.
29
30
 
30
31
 
31
32
 
package/dist/cli.mjs CHANGED
@@ -12,15 +12,17 @@ program
12
12
  .option('--includeTags <tags...>', 'Space-separated list of tags of paths to be included. Path is included if it contains any of specified tag')
13
13
  .option('--excludeTags <tags...>', 'Space-separated list of tags of paths to be excluded. Path is excluded if it contains any of specified tag')
14
14
  .option('--enableScats', 'Generate scats', false)
15
+ .option('--targetNode', 'Add imports for node-fetch into generated code', false)
15
16
  .argument('outputFile', 'File with generated code')
16
17
  .parse();
17
18
  const url = program.opts().url;
18
19
  const referencedObjectsNullableByDefault = program.opts().referencedObjectsNullableByDefault;
19
20
  const enableScats = program.opts().enableScats;
21
+ const targetNode = program.opts().targetNode;
20
22
  const outputFile = program.args[0];
21
23
  const includeTags = HashSet.from(program.opts().includeTags || []);
22
24
  const excludeTags = HashSet.from(program.opts().excludeTags || []);
23
- main(url, enableScats, outputFile, {
25
+ main(url, enableScats, targetNode, outputFile, {
24
26
  referencedObjectsNullableByDefault: referencedObjectsNullableByDefault,
25
27
  includeTags: includeTags,
26
28
  excludeTags: excludeTags
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'url';
6
6
  import { dirname } from 'path';
7
7
  const __filename = fileURLToPath(import.meta.url);
8
8
  const __dirname = dirname(__filename);
9
- export async function main(url, enableScats, outputFile, options) {
9
+ export async function main(url, enableScats, targetNode, outputFile, options) {
10
10
  const { configure, getLogger } = log4js;
11
11
  configure(`${__dirname}/../config/log4js.json`);
12
12
  const logger = getLogger('Generator');
@@ -19,7 +19,7 @@ export async function main(url, enableScats, outputFile, options) {
19
19
  const schemas = resolveSchemas(json, schemasTypes, options);
20
20
  const paths = resolvePaths(json, schemasTypes, options);
21
21
  logger.debug(`Downloaded swagger: ${schemas.size} schemas, ${paths.size} paths`);
22
- await renderer.renderToFile(schemas.values, paths, enableScats, outputFile);
22
+ await renderer.renderToFile(schemas.values, paths, enableScats, targetNode, outputFile);
23
23
  logger.debug(`Wrote client to ${outputFile}`);
24
24
  });
25
25
  }
package/dist/property.js CHANGED
@@ -31,7 +31,7 @@ export class Property {
31
31
  .map(ref => ref.substring(SCHEMA_PREFIX.length))
32
32
  .orElseValue(option(oneOfItem.type))).mkString(' & ')))
33
33
  .getOrElseValue(definition.type);
34
- const nullable = option(definition.nullable).contains(true) || !option(definition.required).contains(true) ||
34
+ const nullable = option(definition.nullable).contains(true) ||
35
35
  (referencesObject && options.referencedObjectsNullableByDefault && !option(definition.nullable).contains(false));
36
36
  const description = option(definition.description);
37
37
  const required = option(definition.required).contains(false);
package/dist/renderer.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import * as ejs from 'ejs';
2
2
  import * as fs from 'fs';
3
- import path from 'path';
3
+ import path, { dirname } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- import { dirname } from 'path';
6
5
  const __filename = fileURLToPath(import.meta.url);
7
6
  const __dirname = dirname(__filename);
8
7
  export class Renderer {
9
- async renderToFile(schemas, methods, enableScats, file) {
8
+ async renderToFile(schemas, methods, enableScats, targetNode, file) {
10
9
  const view = await ejs.renderFile(path.resolve(__dirname, 'templates/index.ejs'), {
11
10
  schemas: schemas,
12
11
  methods: methods,
13
- scats: enableScats
12
+ scats: enableScats,
13
+ targetNode: targetNode
14
14
  });
15
15
  fs.writeFileSync(file, view);
16
16
  }
@@ -10,7 +10,9 @@
10
10
  *********************************************************
11
11
  *********************************************************
12
12
  *********************************************************/
13
+ <% if (targetNode) {%>
13
14
  import fetch, {Request, Response} from 'node-fetch';
15
+ <% } %>
14
16
  <% if (scats) {%>
15
17
  import {option, Option, Collection, Try, TryLike, none} from 'scats';
16
18
  <% } %>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "homepage": "https://github.com/papirosko/swagger-code-gen#readme",
24
24
  "scripts": {
25
- "test:petstore": "mkdir -p tmp && ts-node-esm ./src/cli.mjs --enableScats --url https://petstore3.swagger.io/api/v3/openapi.json tmp/petstore.ts",
25
+ "test:petstore": "npm run build && mkdir -p tmp && ts-node-esm ./dist/cli.mjs --enableScats --targetNode --url https://petstore3.swagger.io/api/v3/openapi.json tmp/petstore.ts",
26
26
  "clean": "rimraf dist",
27
27
  "lint": "eslint \"{src,test}/**/*.ts\" --fix",
28
28
  "prebuild": "npm run lint && npm run clean",