@penkov/swagger-code-gen 1.16.0 → 1.16.1

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/cli.mjs CHANGED
@@ -12,6 +12,7 @@ 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('--onlyUsedSchemas', 'Generate only schemas reachable from filtered methods', false)
15
+ .option('--includeSchemasByMask <masks...>', 'Space-separated list of schema name masks to force-include with dependencies (supports * and ? wildcards)')
15
16
  .option('--enableScats', 'Generate scats', false)
16
17
  .option('--targetNode', 'Add imports for node-fetch into generated code', false)
17
18
  .option('--user <username>', 'If swagger requires authorisation')
@@ -30,6 +31,7 @@ const outputFile = program.args[0];
30
31
  const includeTags = HashSet.from(program.opts().includeTags || []);
31
32
  const excludeTags = HashSet.from(program.opts().excludeTags || []);
32
33
  const onlyUsedSchemas = program.opts().onlyUsedSchemas;
34
+ const includeSchemasByMask = HashSet.from(program.opts().includeSchemasByMask || []);
33
35
  main(url, enableScats, targetNode, outputFile, ignoreSSLErrors, option(user).flatMap(u => option(password).map(p => ({
34
36
  user: u,
35
37
  password: p
@@ -37,6 +39,7 @@ main(url, enableScats, targetNode, outputFile, ignoreSSLErrors, option(user).fla
37
39
  referencedObjectsNullableByDefault: referencedObjectsNullableByDefault,
38
40
  includeTags: includeTags,
39
41
  excludeTags: excludeTags,
40
- onlyUsedSchemas: onlyUsedSchemas
42
+ onlyUsedSchemas: onlyUsedSchemas,
43
+ includeSchemasByMask: includeSchemasByMask
41
44
  }).then(() => {
42
45
  });
@@ -1,4 +1,4 @@
1
- import { Collection, mutable, Nil, option } from 'scats';
1
+ import { Collection, HashSet, mutable, Nil, option } from 'scats';
2
2
  import { SchemaFactory, SchemaObject } from './schemas.js';
3
3
  import { Property, SCHEMA_PREFIX } from './property.js';
4
4
  import { Method, supportedBodyMimeTypes } from './method.js';
@@ -95,9 +95,15 @@ function collectSchemaRefsFromType(type, schemas, add) {
95
95
  .filter(t => schemas.containsKey(t))
96
96
  .foreach(t => add(t));
97
97
  }
98
- export function filterUsedSchemas(paths, schemas) {
98
+ function wildcardMaskToRegExp(mask) {
99
+ const escaped = mask.replace(/[.+^${}()|[\]\\]/g, '\\$&');
100
+ const regex = escaped.replace(/\*/g, '.*').replace(/\?/g, '.');
101
+ return new RegExp(`^${regex}$`);
102
+ }
103
+ export function filterUsedSchemas(paths, schemas, includeSchemasByMask = HashSet.empty) {
99
104
  const used = new Set();
100
105
  const pending = [];
106
+ const maskRegexes = includeSchemasByMask.map(mask => wildcardMaskToRegExp(mask));
101
107
  const add = (name) => {
102
108
  if (!used.has(name) && schemas.containsKey(name)) {
103
109
  used.add(name);
@@ -117,6 +123,9 @@ export function filterUsedSchemas(paths, schemas) {
117
123
  }
118
124
  });
119
125
  });
126
+ schemas.keySet
127
+ .filter(name => maskRegexes.exists(regex => regex.test(name)))
128
+ .foreach(name => add(name));
120
129
  while (pending.length > 0) {
121
130
  const schemaName = pending.shift();
122
131
  const schema = schemas.get(schemaName).getOrElseThrow(() => new Error(`No schema for ${schemaName}`));
package/dist/index.js CHANGED
@@ -28,7 +28,9 @@ export async function main(url, enableScats, targetNode, outputFile, ignoreSSLEr
28
28
  const schemasTypes = resolveSchemasTypes(json);
29
29
  const allSchemas = resolveSchemas(json, schemasTypes, options);
30
30
  const paths = resolvePaths(json, schemasTypes, options, allSchemas);
31
- const schemas = options.onlyUsedSchemas ? filterUsedSchemas(paths, allSchemas) : allSchemas;
31
+ const schemas = options.onlyUsedSchemas
32
+ ? filterUsedSchemas(paths, allSchemas, options.includeSchemasByMask)
33
+ : allSchemas;
32
34
  const inplace = generateInPlace(paths, schemasTypes, options, schemas);
33
35
  logger.debug(`Downloaded swagger: ${schemas.size} schemas, ${paths.size} paths`);
34
36
  await renderer.renderToFile(schemas.appendedAll(inplace.toMap(s => [s.name, s])).values, paths, enableScats, targetNode, outputFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "dist/cli.mjs"