swagger-typescript-api 11.0.0--alpha-3 → 11.0.0--alpha-5

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/cli/execute.js CHANGED
@@ -1,7 +1,9 @@
1
1
  const _ = require("lodash");
2
2
  const { root_command, skip_command } = require("./constants");
3
3
  const { parseArgs } = require("./parse-args");
4
- const didyoumean = require("didyoumean");
4
+ const didYouMean = require("didyoumean");
5
+
6
+ didYouMean.threshold = 0.5;
5
7
 
6
8
  const execute = (params, commands, instance) => {
7
9
  const args = parseArgs(params.args, params.from);
@@ -96,7 +98,8 @@ const processArgs = (commands, args) => {
96
98
  const option = command.options.find((option) => option.flags.keys.includes(arg));
97
99
 
98
100
  if (!option) {
99
- error = `unknown option ${arg}\n(Did you mean ${didyoumean(arg, allFlagKeys)} ?)`;
101
+ const tip = didYouMean(arg, allFlagKeys);
102
+ error = `unknown option ${arg}${tip ? `\n(Did you mean ${tip} ?)` : ""}`;
100
103
  }
101
104
 
102
105
  if (option) {
package/index.js CHANGED
@@ -201,46 +201,56 @@ const program = cli({
201
201
 
202
202
  const main = async () => {
203
203
  const { command, options } = await program.execute({ args: process.argv });
204
- if (command === "generate-templates") {
205
- } else if (command === null) {
206
- await generateApi({
207
- name: options.name,
208
- url: options.path,
209
- generateRouteTypes: options.routeTypes,
210
- generateClient: !!(options.axios || options.client),
211
- httpClientType: options.axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
212
- defaultResponseAsSuccess: options.defaultAsSuccess,
213
- defaultResponseType: options.defaultResponse,
214
- unwrapResponseData: options.unwrapResponseData,
215
- disableThrowOnError: options.disableThrowOnError,
216
- sortTypes: options.sortTypes,
217
- generateUnionEnums: options.unionEnums,
218
- addReadonly: options.addReadonly,
219
- generateResponses: options.responses,
220
- extractRequestParams: !!options.extractRequestParams,
221
- extractRequestBody: !!options.extractRequestBody,
222
- extractResponseBody: !!options.extractResponseBody,
223
- extractResponseError: !!options.extractResponseError,
224
- input: resolve(process.cwd(), options.path),
225
- output: resolve(process.cwd(), options.output || "."),
226
- templates: options.templates,
227
- modular: !!options.modular,
228
- toJS: !!options.js,
229
- enumNamesAsValues: options.enumNamesAsValues,
230
- moduleNameIndex: +(options.moduleNameIndex || 0),
231
- moduleNameFirstTag: options.moduleNameFirstTag,
232
- disableStrictSSL: !!options.disableStrictSSL,
233
- disableProxy: !!options.disableProxy,
234
- singleHttpClient: !!options.singleHttpClient,
235
- cleanOutput: !!options.cleanOutput,
236
- silent: !!options.silent,
237
- typePrefix: options.typePrefix,
238
- typeSuffix: options.typeSuffix,
239
- patch: !!options.patch,
240
- apiClassName: options.apiClassName,
241
- debug: options.debug,
242
- anotherArrayType: options.anotherArrayType,
243
- });
204
+
205
+ switch (command) {
206
+ case null: {
207
+ await generateApi({
208
+ name: options.name,
209
+ url: options.path,
210
+ generateRouteTypes: options.routeTypes,
211
+ generateClient: !!(options.axios || options.client),
212
+ httpClientType: options.axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
213
+ defaultResponseAsSuccess: options.defaultAsSuccess,
214
+ defaultResponseType: options.defaultResponse,
215
+ unwrapResponseData: options.unwrapResponseData,
216
+ disableThrowOnError: options.disableThrowOnError,
217
+ sortTypes: options.sortTypes,
218
+ generateUnionEnums: options.unionEnums,
219
+ addReadonly: options.addReadonly,
220
+ generateResponses: options.responses,
221
+ extractRequestParams: !!options.extractRequestParams,
222
+ extractRequestBody: !!options.extractRequestBody,
223
+ extractResponseBody: !!options.extractResponseBody,
224
+ extractResponseError: !!options.extractResponseError,
225
+ input: resolve(process.cwd(), options.path),
226
+ output: resolve(process.cwd(), options.output || "."),
227
+ templates: options.templates,
228
+ modular: !!options.modular,
229
+ toJS: !!options.js,
230
+ enumNamesAsValues: options.enumNamesAsValues,
231
+ moduleNameIndex: +(options.moduleNameIndex || 0),
232
+ moduleNameFirstTag: options.moduleNameFirstTag,
233
+ disableStrictSSL: !!options.disableStrictSSL,
234
+ disableProxy: !!options.disableProxy,
235
+ singleHttpClient: !!options.singleHttpClient,
236
+ cleanOutput: !!options.cleanOutput,
237
+ silent: !!options.silent,
238
+ typePrefix: options.typePrefix,
239
+ typeSuffix: options.typeSuffix,
240
+ patch: !!options.patch,
241
+ apiClassName: options.apiClassName,
242
+ debug: options.debug,
243
+ anotherArrayType: options.anotherArrayType,
244
+ });
245
+ break;
246
+ }
247
+ case "generate-templates": {
248
+ console.info("todo");
249
+ break;
250
+ }
251
+ default: {
252
+ break;
253
+ }
244
254
  }
245
255
  };
246
256
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "11.0.0--alpha-3",
3
+ "version": "11.0.0--alpha-5",
4
4
  "description": "Generate typescript/javascript api from swagger schema",
5
5
  "scripts": {
6
6
  "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
@@ -53,6 +53,10 @@ class CodeGenProcess {
53
53
  */
54
54
  codeFormatter;
55
55
 
56
+ /**
57
+ *
58
+ * @param config {Partial<import("../index.d.ts").GenerateApiConfiguration['config']>}
59
+ */
56
60
  constructor(config) {
57
61
  this.config = new Configuration(config);
58
62
  this.logger = new Logger(this.config);
@@ -293,52 +293,17 @@ class Configuration {
293
293
 
294
294
  templateExtensions = [".eta", ".ejs"];
295
295
 
296
+ /**
297
+ * @param config {Partial<GenerateApiConfiguration['config']>}
298
+ */
296
299
  constructor({
297
- input,
298
- output,
299
- url,
300
- spec,
301
- name: fileName,
302
- toJS,
303
- modular,
304
- templates,
305
- generateResponses,
306
- defaultResponseAsSuccess,
307
- generateRouteTypes,
308
- generateClient,
309
- httpClientType,
310
- generateUnionEnums,
311
- addReadonly,
312
- moduleNameIndex,
313
- moduleNameFirstTag,
314
- extractRequestParams,
315
- extractRequestBody,
316
- extractResponseBody,
317
- extractResponseError,
318
- defaultResponseType,
319
- unwrapResponseData,
320
- disableThrowOnError,
321
- sortTypes,
322
- singleHttpClient,
323
- prettier: prettierOptions = getDefaultPrettierOptions(),
324
- hooks: rawHooks,
325
- extraTemplates,
326
- enumNamesAsValues,
327
- disableStrictSSL,
328
- disableProxy,
329
- cleanOutput,
330
- silent,
331
- typePrefix,
332
- typeSuffix,
333
- patch,
334
- authorizationToken,
335
- apiClassName,
336
- debug,
337
- anotherArrayType,
300
+ prettierOptions = getDefaultPrettierOptions(),
338
301
  codeGenConstructs,
339
302
  primitiveTypeConstructs,
340
303
  constants,
341
304
  templateInfos,
305
+ hooks,
306
+ ...params
342
307
  }) {
343
308
  objectAssign(this.Ts, codeGenConstructs);
344
309
  objectAssign(this.primitiveTypes, primitiveTypeConstructs);
@@ -346,52 +311,14 @@ class Configuration {
346
311
  this.defaultResponseType = this.Ts.Keyword.Void;
347
312
 
348
313
  this.update({
349
- input,
350
- output,
351
- url,
352
- spec,
353
- fileName,
354
- extraTemplates,
355
- defaultResponseAsSuccess,
356
- generateRouteTypes,
357
- generateClient,
358
- httpClientType,
359
- generateResponses,
360
- templates,
361
- generateUnionEnums,
362
- addReadonly,
363
- moduleNameIndex,
364
- moduleNameFirstTag,
365
- prettierOptions,
366
- modular,
367
- extractRequestParams,
368
- extractRequestBody,
369
- extractResponseBody,
370
- extractResponseError,
371
- hooks: _.merge(this.hooks, rawHooks || {}),
372
- enumNamesAsValues,
373
- disableStrictSSL,
374
- disableProxy,
375
- cleanOutput,
376
- defaultResponseType,
377
- unwrapResponseData,
378
- disableThrowOnError,
379
- sortTypes,
380
- singleHttpClient,
314
+ ...params,
315
+ prettierOptions: prettierOptions === undefined ? getDefaultPrettierOptions() : prettierOptions,
316
+ hooks: _.merge(this.hooks, hooks || {}),
381
317
  constants: {
382
318
  ...constantsBase,
383
319
  ...constants,
384
320
  },
385
- authorizationToken,
386
- silent,
387
- toJS,
388
- typePrefix,
389
- typeSuffix,
390
- patch,
391
- apiClassName,
392
- debug,
393
- anotherArrayType,
394
- templateInfos,
321
+ templateInfos: templateInfos || this.templateInfos,
395
322
  });
396
323
 
397
324
  this.jsPrimitiveTypes = [this.Ts.Keyword.Number, this.Ts.Keyword.String, this.Ts.Keyword.Boolean];
package/src/index.js CHANGED
@@ -12,8 +12,12 @@ const { CodeGenProcess } = require("./code-gen-process.js");
12
12
 
13
13
  module.exports = {
14
14
  constants: constants,
15
- generateApi: async (config) => {
16
- const codeGenProcess = new CodeGenProcess(config);
15
+ generateApi: async ({ name, prettier, ...config }) => {
16
+ const codeGenProcess = new CodeGenProcess({
17
+ ...config,
18
+ fileName: name,
19
+ prettierOptions: prettier,
20
+ });
17
21
  return await codeGenProcess.start();
18
22
  },
19
23
  generateTemplates: (config) => {},
@@ -2,8 +2,12 @@ const _ = require("lodash");
2
2
 
3
3
  const objectAssign = (target, updaterFn) => {
4
4
  if (!updaterFn) return;
5
- const updated = typeof updaterFn === "function" ? updaterFn(target) : updaterFn;
6
- Object.assign(target, _.merge(target, updated));
5
+ const update = typeof updaterFn === "function" ? updaterFn(target) : updaterFn;
6
+ const undefinedKeys = _.map(update, (value, key) => value === undefined && key).filter(Boolean);
7
+ Object.assign(target, _.merge(target, update));
8
+ undefinedKeys.forEach((key) => {
9
+ target[key] = undefined;
10
+ });
7
11
  };
8
12
 
9
13
  module.exports = {
@@ -1,7 +1,6 @@
1
1
  <%
2
2
  const { contract, utils } = it;
3
3
  const { formatDescription, require, _ } = utils;
4
- console.info('contract', contract.name, contract)
5
4
  %>
6
5
  export interface <%~ contract.name %> {
7
6
  <% _.forEach(contract.$content, (field) => { %>