@penkov/swagger-code-gen 1.8.7 → 1.8.9
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 +11 -2
- package/dist/index.js +12 -2
- package/dist/property.js +6 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { main } from './index.js';
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
-
import { HashSet } from "scats";
|
|
4
|
+
import { HashSet, option } from "scats";
|
|
5
5
|
const program = new Command();
|
|
6
6
|
program
|
|
7
7
|
.name('Swagger client code generator')
|
|
@@ -13,16 +13,25 @@ program
|
|
|
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
15
|
.option('--targetNode', 'Add imports for node-fetch into generated code', false)
|
|
16
|
+
.option('--user <username>', 'If swagger requires authorisation')
|
|
17
|
+
.option('--password <password>', 'If swagger requires authorisation')
|
|
18
|
+
.option('--ignoreSSLErrors', 'If swagger requires authorisation, but ssl cert is wrong')
|
|
16
19
|
.argument('outputFile', 'File with generated code')
|
|
17
20
|
.parse();
|
|
18
21
|
const url = program.opts().url;
|
|
22
|
+
const user = program.opts().user;
|
|
23
|
+
const password = program.opts().password;
|
|
24
|
+
const ignoreSSLErrors = program.opts().ignoreSSLErrors;
|
|
19
25
|
const referencedObjectsNullableByDefault = program.opts().referencedObjectsNullableByDefault;
|
|
20
26
|
const enableScats = program.opts().enableScats;
|
|
21
27
|
const targetNode = program.opts().targetNode;
|
|
22
28
|
const outputFile = program.args[0];
|
|
23
29
|
const includeTags = HashSet.from(program.opts().includeTags || []);
|
|
24
30
|
const excludeTags = HashSet.from(program.opts().excludeTags || []);
|
|
25
|
-
main(url, enableScats, targetNode, outputFile, {
|
|
31
|
+
main(url, enableScats, targetNode, outputFile, ignoreSSLErrors, option(user).flatMap(u => option(password).map(p => ({
|
|
32
|
+
user: u,
|
|
33
|
+
password: p
|
|
34
|
+
}))), {
|
|
26
35
|
referencedObjectsNullableByDefault: referencedObjectsNullableByDefault,
|
|
27
36
|
includeTags: includeTags,
|
|
28
37
|
excludeTags: excludeTags
|
package/dist/index.js
CHANGED
|
@@ -4,15 +4,25 @@ import { Renderer } from './renderer.js';
|
|
|
4
4
|
import { resolvePaths, resolveSchemas, resolveSchemasTypes } from './components-parse.js';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { dirname } from 'path';
|
|
7
|
+
import https from 'https';
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
9
|
const __dirname = dirname(__filename);
|
|
9
|
-
export async function main(url, enableScats, targetNode, outputFile, options) {
|
|
10
|
+
export async function main(url, enableScats, targetNode, outputFile, ignoreSSLErrors, auth, options) {
|
|
10
11
|
const { configure, getLogger } = log4js;
|
|
11
12
|
configure(`${__dirname}/../config/log4js.json`);
|
|
12
13
|
const logger = getLogger('Generator');
|
|
13
14
|
logger.info(`Generating code from ${url}`);
|
|
15
|
+
const httpsAgent = ignoreSSLErrors ? new https.Agent({
|
|
16
|
+
rejectUnauthorized: false,
|
|
17
|
+
}) : undefined;
|
|
14
18
|
const renderer = new Renderer();
|
|
15
|
-
|
|
19
|
+
const headers = auth.map(a => new Headers({
|
|
20
|
+
'Authorization': `Basic ${btoa(a.user + ':' + a.password)}`
|
|
21
|
+
}));
|
|
22
|
+
fetch(url, {
|
|
23
|
+
headers: headers.orUndefined,
|
|
24
|
+
agent: httpsAgent
|
|
25
|
+
})
|
|
16
26
|
.then(res => res.json())
|
|
17
27
|
.then(async (json) => {
|
|
18
28
|
const schemasTypes = resolveSchemasTypes(json);
|
package/dist/property.js
CHANGED
|
@@ -21,7 +21,12 @@ export class Property {
|
|
|
21
21
|
}
|
|
22
22
|
static fromDefinition(name, definition, schemaTypes, options) {
|
|
23
23
|
const referencesObject = option(definition.$ref)
|
|
24
|
-
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'))
|
|
24
|
+
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object')) ||
|
|
25
|
+
option(definition.allOf)
|
|
26
|
+
.filter(allOf => allOf.length === 1)
|
|
27
|
+
.flatMap(allOf => option(allOf[0]))
|
|
28
|
+
.flatMap(schema => option(schema.$ref))
|
|
29
|
+
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
|
|
25
30
|
const itemReferencesObject = option(definition.items)
|
|
26
31
|
.flatMap(i => option(i.$ref))
|
|
27
32
|
.exists(ref => schemaTypes.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
|