@penkov/swagger-code-gen 1.8.6 → 1.8.8

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
@@ -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
- fetch(url)
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);
@@ -1,4 +1,23 @@
1
-
1
+ /**
2
+ * <%= method.method.toUpperCase() %> <%= method.path %>
3
+ <% if (method.summary) { -%>
4
+ * @summary <%= method.summary %>
5
+ <% } -%>
6
+ <% if (method.description) { -%>
7
+ * @description <%= method.description %>
8
+ <% } -%>
9
+ <% if (method.wrapParamsInObject) { -%>
10
+ * @param {Object} params
11
+ <% } -%>
12
+ <% method.parameters.foreach(p => { -%>
13
+ * @param {<%= p.jsType %>} <%= method.wrapParamsInObject ? 'params.' : '' %><%= p.uniqueName %> <%= p.description.getOrElseValue('')%>
14
+ <% }); -%>
15
+ <%_ if (body.nonEmpty) { -%>
16
+ * @param {<%= body.get.body.jsType %>} body <%= method.bodyDescription.getOrElseValue('') %>
17
+ <%_ } -%>
18
+ * @param {RequestOptions} requestOptions Additional request params
19
+ * @return {<%= method.response.responseType %>} <%= method.response.description %>
20
+ */
2
21
  async <%= method.endpointName %><%= body.map(b => b.suffix).getOrElseValue('') %>(
3
22
  <%_ if (!method.wrapParamsInObject) { -%>
4
23
  <%_ method.parameters.foreach(p => { -%>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"