@team-supercharge/oasg 13.2.0-feature-csharp-functions-c3d21a55.0 → 13.2.0-feature-csharp-functions-c1cbb3b0.0

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.
Files changed (3) hide show
  1. package/bin/exec.js +2 -3
  2. package/bin/oasg +154 -122
  3. package/package.json +1 -1
package/bin/exec.js CHANGED
@@ -3,9 +3,8 @@ const { execSync } = require('child_process');
3
3
 
4
4
  function exec(command, stdio) {
5
5
  try {
6
- execSync(command, { stdio: stdio || 'inherit' });
7
- }
8
- catch (e) {
6
+ execSync(`bash -e -c "${command}"`, { stdio: stdio || 'inherit' });
7
+ } catch (e) {
9
8
  console.error(e.message);
10
9
  exit(1);
11
10
  }
package/bin/oasg CHANGED
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const crypto = require('crypto');
5
5
  const ajv = new (require('ajv'))({
6
- strict: 'log'
6
+ strict: 'log',
7
7
  });
8
8
  const YAML = require('yamljs');
9
9
  const refParser = require('@apidevtools/json-schema-ref-parser');
@@ -33,23 +33,23 @@ const PROXY_PORT = '9999';
33
33
 
34
34
  const DEFAULT_GENERATOR_MAPPING = {
35
35
  // client targets
36
- "android": { version: '7.0.1', generator: 'kotlin' },
37
- "angular": { version: '7.0.1', generator: 'typescript-angular' },
38
- "feign": { version: '7.0.1', generator: 'spring' },
39
- "feign-kotlin": { version: '7.0.1', generator: 'kotlin-spring' },
40
- "flutter": { version: '7.0.1', generator: 'dart-dio' },
41
- "ios": { version: '7.0.1', generator: 'swift5' },
42
- "python": { version: '7.0.1', generator: 'python' },
43
- "react": { version: '7.0.1', generator: 'typescript-fetch' },
36
+ android: { version: '7.0.1', generator: 'kotlin' },
37
+ angular: { version: '7.0.1', generator: 'typescript-angular' },
38
+ feign: { version: '7.0.1', generator: 'spring' },
39
+ 'feign-kotlin': { version: '7.0.1', generator: 'kotlin-spring' },
40
+ flutter: { version: '7.0.1', generator: 'dart-dio' },
41
+ ios: { version: '7.0.1', generator: 'swift5' },
42
+ python: { version: '7.0.1', generator: 'python' },
43
+ react: { version: '7.0.1', generator: 'typescript-fetch' },
44
44
  // server targets
45
- "nestjs": { version: '7.0.1', generator: 'typescript-angular' },
46
- "spring": { version: '7.0.1', generator: 'spring' },
47
- "spring-kotlin": { version: '7.0.1', generator: 'kotlin-spring' },
48
- "csharp-functions": { version: '7.0.1', generator: 'csharp-functions' },
45
+ nestjs: { version: '7.0.1', generator: 'typescript-angular' },
46
+ spring: { version: '7.0.1', generator: 'spring' },
47
+ 'spring-kotlin': { version: '7.0.1', generator: 'kotlin-spring' },
48
+ 'csharp-functions': { version: '7.0.1', generator: 'csharp-functions' },
49
49
  // misc targets
50
- "contract-testing": { version: '4.3.1', generator: 'typescript-node' },
51
- "openapi": { version: undefined, generator: undefined },
52
- "stubby": { version: '4.3.1', generator: 'stubby' },
50
+ 'contract-testing': { version: '4.3.1', generator: 'typescript-node' },
51
+ openapi: { version: undefined, generator: undefined },
52
+ stubby: { version: '4.3.1', generator: 'stubby' },
53
53
  };
54
54
  const DEFAULT_KTLINT_VERSION = '1.0.0';
55
55
  const BIN_FOLDER = 'out/.bin';
@@ -59,8 +59,8 @@ const CONFIG_FILE_NAME = 'config.json';
59
59
  const DEFAULT_SOURCE = {
60
60
  id: 'default',
61
61
  type: 'simple',
62
- input: 'api/openapi.yaml'
63
- }
62
+ input: 'api/openapi.yaml',
63
+ };
64
64
 
65
65
  let config;
66
66
 
@@ -76,71 +76,93 @@ async function run() {
76
76
  // handle command line
77
77
  require('yargs')
78
78
  // lint
79
- .command(['lint [source]', 'l'], 'lint definitions', (yargs) => {
80
- yargs
81
- .positional('source', {
79
+ .command(
80
+ ['lint [source]', 'l'],
81
+ 'lint definitions',
82
+ (yargs) => {
83
+ yargs.positional('source', {
82
84
  describe: 'specify a source (optional)',
83
- default: undefined
84
- })
85
- }, (argv) => lint(argv))
85
+ default: undefined,
86
+ });
87
+ },
88
+ (argv) => lint(argv)
89
+ )
86
90
 
87
91
  // serve
88
- .command(['serve [source]', 's'], 'serve definition', (yargs) => {
89
- yargs
90
- .positional('source', {
92
+ .command(
93
+ ['serve [source]', 's'],
94
+ 'serve definition',
95
+ (yargs) => {
96
+ yargs.positional('source', {
91
97
  describe: 'specify a source',
92
- default: 'default'
93
- })
94
- }, (argv) => serve(argv))
98
+ default: 'default',
99
+ });
100
+ },
101
+ (argv) => serve(argv)
102
+ )
95
103
 
96
104
  // proxy
97
- .command(['proxy [source]', 'p'], 'serve definition', (yargs) => {
98
- yargs
99
- .positional('source', {
100
- describe: 'specify a source',
101
- default: 'default'
102
- })
103
- .option('server', {
104
- describe: 'specify a server (from "servers" array)',
105
- alias: 's',
106
- demandOption: true
107
- })
108
- }, (argv) => proxy(argv))
105
+ .command(
106
+ ['proxy [source]', 'p'],
107
+ 'serve definition',
108
+ (yargs) => {
109
+ yargs
110
+ .positional('source', {
111
+ describe: 'specify a source',
112
+ default: 'default',
113
+ })
114
+ .option('server', {
115
+ describe: 'specify a server (from "servers" array)',
116
+ alias: 's',
117
+ demandOption: true,
118
+ });
119
+ },
120
+ (argv) => proxy(argv)
121
+ )
109
122
 
110
123
  // generate
111
- .command(['generate [target]', 'g'], 'generate packages', (yargs) => {
112
- yargs
113
- .positional('target', {
114
- describe: 'specify a target (optional)',
115
- default: undefined
116
- })
117
- .option('artifactVersion', {
118
- describe: 'Specify an artifactVersion (optional). \nIf you do not specify it, the tool uses the root package.json\'s version field.',
119
- default: undefined
120
- })
121
- .option('preRelease', {
122
- describe: 'Generate as pre-release (optional). \nHow a pre-release is handled varies between different target types.',
123
- type: 'boolean'
124
- })
125
- }, (argv) => generate(argv))
124
+ .command(
125
+ ['generate [target]', 'g'],
126
+ 'generate packages',
127
+ (yargs) => {
128
+ yargs
129
+ .positional('target', {
130
+ describe: 'specify a target (optional)',
131
+ default: undefined,
132
+ })
133
+ .option('artifactVersion', {
134
+ describe: "Specify an artifactVersion (optional). \nIf you do not specify it, the tool uses the root package.json's version field.",
135
+ default: undefined,
136
+ })
137
+ .option('preRelease', {
138
+ describe: 'Generate as pre-release (optional). \nHow a pre-release is handled varies between different target types.',
139
+ type: 'boolean',
140
+ });
141
+ },
142
+ (argv) => generate(argv)
143
+ )
126
144
 
127
145
  // publish
128
- .command(['publish [target]', 'p'], 'publish packages', (yargs) => {
129
- yargs
130
- .positional('target', {
131
- describe: 'specifiy a target (optional)',
132
- default: undefined
133
- })
134
- .option('preRelease', {
135
- describe: 'Publish as pre-release (optional). \nHow a pre-release is handled varies between different target types.',
136
- type: 'boolean'
137
- })
138
- }, (argv) => publish(argv))
146
+ .command(
147
+ ['publish [target]', 'p'],
148
+ 'publish packages',
149
+ (yargs) => {
150
+ yargs
151
+ .positional('target', {
152
+ describe: 'specifiy a target (optional)',
153
+ default: undefined,
154
+ })
155
+ .option('preRelease', {
156
+ describe: 'Publish as pre-release (optional). \nHow a pre-release is handled varies between different target types.',
157
+ type: 'boolean',
158
+ });
159
+ },
160
+ (argv) => publish(argv)
161
+ )
139
162
 
140
163
  // options
141
164
  .demandCommand(1, 'You need to specify a command!')
142
- .strict()
143
- .argv
165
+ .strict().argv;
144
166
  }
145
167
 
146
168
  function checkVersionMismatch() {
@@ -160,7 +182,7 @@ function checkVersionMismatch() {
160
182
  function checkRequiredCommands() {
161
183
  const missing = [];
162
184
 
163
- REQUIRED_COMMANDS.forEach(command => {
185
+ REQUIRED_COMMANDS.forEach((command) => {
164
186
  if (!commandExistsSync(command)) {
165
187
  missing.push(command);
166
188
  }
@@ -191,10 +213,10 @@ async function parseConfig() {
191
213
  }
192
214
 
193
215
  // validate config schema
194
- let schema = YAML.load(`${__dirname}/../config.schema.yml`)
216
+ let schema = YAML.load(`${__dirname}/../config.schema.yml`);
195
217
  schema = await refParser.dereference(schema);
196
218
  schema = mergeAllOf(schema, { ignoreAdditionalProperties: true });
197
- ajv.addVocabulary(["sources", "targets"]);
219
+ ajv.addVocabulary(['sources', 'targets']);
198
220
  const valid = ajv.validate(schema, config);
199
221
 
200
222
  if (!valid) {
@@ -208,7 +230,7 @@ async function parseConfig() {
208
230
  }
209
231
 
210
232
  // set default source values
211
- config.sources.forEach(s => {
233
+ config.sources.forEach((s) => {
212
234
  if (s.bundle === undefined) {
213
235
  s.bundle = true;
214
236
  }
@@ -227,14 +249,14 @@ async function parseConfig() {
227
249
  });
228
250
 
229
251
  // set default source to targets with undefined
230
- config.targets.forEach(t => {
252
+ config.targets.forEach((t) => {
231
253
  if (!t.source) {
232
254
  t.source = 'default';
233
255
  }
234
256
  });
235
257
 
236
258
  // set default generator values to targets with undefined
237
- config.targets.forEach(t => {
259
+ config.targets.forEach((t) => {
238
260
  if (!t.generator) {
239
261
  t.generator = DEFAULT_GENERATOR_MAPPING[t.type].version;
240
262
  }
@@ -246,20 +268,20 @@ async function parseConfig() {
246
268
  exit(1);
247
269
  }
248
270
  }
249
- })
271
+ });
250
272
 
251
273
  // set default ktlint to android targets with undefined
252
- config.targets.forEach(t => {
274
+ config.targets.forEach((t) => {
253
275
  //TODO: handle different types of platform
254
276
  if (t.type === 'android') {
255
277
  if (!t.formatter) {
256
278
  t.formatter = DEFAULT_KTLINT_VERSION;
257
279
  }
258
280
  }
259
- })
281
+ });
260
282
 
261
283
  // validate uniqueness of source IDs
262
- const sourceIds = config.sources.map(s => s.id);
284
+ const sourceIds = config.sources.map((s) => s.id);
263
285
  const duplicateSourceIds = findDuplicates(sourceIds);
264
286
 
265
287
  if (duplicateSourceIds.length > 0) {
@@ -268,7 +290,7 @@ async function parseConfig() {
268
290
  }
269
291
 
270
292
  // validate uniqueness of target IDs
271
- const targetIds = config.targets.map(t => t.id);
293
+ const targetIds = config.targets.map((t) => t.id);
272
294
  const duplicateTargetIds = findDuplicates(targetIds);
273
295
 
274
296
  if (duplicateTargetIds.length > 0) {
@@ -277,7 +299,7 @@ async function parseConfig() {
277
299
  }
278
300
 
279
301
  // validate targets have valid sources
280
- config.targets.forEach(t => {
302
+ config.targets.forEach((t) => {
281
303
  if (!sourceIds.includes(t.source)) {
282
304
  console.error(`source: ${t.source} not found for target: ${t.id}`);
283
305
  exit(1);
@@ -285,8 +307,8 @@ async function parseConfig() {
285
307
  });
286
308
 
287
309
  // validate unused sources
288
- const usedSources = config.targets.map(t => t.source);
289
- config.sources.forEach(s => {
310
+ const usedSources = config.targets.map((t) => t.source);
311
+ config.sources.forEach((s) => {
290
312
  if (!usedSources.includes(s.id)) {
291
313
  console.error(`source: ${s.id} is not used in any of the targets`);
292
314
  exit(1);
@@ -294,7 +316,7 @@ async function parseConfig() {
294
316
  });
295
317
 
296
318
  // validate source inputs exists
297
- config.sources.forEach(s => {
319
+ config.sources.forEach((s) => {
298
320
  switch (s.type) {
299
321
  case 'simple':
300
322
  if (!fs.existsSync(s.input)) {
@@ -305,12 +327,12 @@ async function parseConfig() {
305
327
  break;
306
328
 
307
329
  case 'merged':
308
- s.inputs.forEach(i => {
330
+ s.inputs.forEach((i) => {
309
331
  if (fs.existsSync(i)) {
310
332
  return;
311
333
  }
312
334
  const matches = globSync(i);
313
- if (matches.every(m => fs.existsSync(m))) {
335
+ if (matches.every((m) => fs.existsSync(m))) {
314
336
  return;
315
337
  }
316
338
  console.error(`input file: ${i} not found for source: ${s.id}`);
@@ -335,7 +357,11 @@ async function buildSources(sourceIds) {
335
357
  continue;
336
358
  }
337
359
 
338
- console.log(`\n=====\n id:\t\t${source.id}\n type:\t\t${source.type}\n bundle:\t${source.bundle}\n sortSchemas:\t${source.sortSchemas}\n decorators: \t${JSON.stringify(source.decorators)}\n cleanup:\t${source.cleanup}\n---\n`);
360
+ console.log(
361
+ `\n=====\n id:\t\t${source.id}\n type:\t\t${source.type}\n bundle:\t${source.bundle}\n sortSchemas:\t${
362
+ source.sortSchemas
363
+ }\n decorators: \t${JSON.stringify(source.decorators)}\n cleanup:\t${source.cleanup}\n---\n`
364
+ );
339
365
 
340
366
  let file;
341
367
 
@@ -366,8 +392,8 @@ async function lint(argv) {
366
392
 
367
393
  // gather and deduplicate input files
368
394
  let inputs = [];
369
- sourceIds.forEach(sourceId => {
370
- const source = config.sources.find(s => s.id === sourceId);
395
+ sourceIds.forEach((sourceId) => {
396
+ const source = config.sources.find((s) => s.id === sourceId);
371
397
 
372
398
  switch (source.type) {
373
399
  case 'simple':
@@ -375,9 +401,9 @@ async function lint(argv) {
375
401
  break;
376
402
 
377
403
  case 'merged':
378
- source.inputs.forEach(i => inputs.push(i));
404
+ source.inputs.forEach((i) => inputs.push(i));
379
405
  }
380
- })
406
+ });
381
407
  inputs = Array.from(new Set(inputs));
382
408
 
383
409
  exec(`npx spectral lint --fail-severity warn ${inputs.join(' ')}`);
@@ -395,16 +421,16 @@ async function serve(argv) {
395
421
  const app = express();
396
422
 
397
423
  // configure proxying
398
- const proxyHost = function(request) {
424
+ const proxyHost = function (request) {
399
425
  const url = new URL(request.query.u);
400
426
  return url.origin;
401
427
  };
402
428
 
403
429
  const proxyOptions = {
404
- proxyReqPathResolver: function(request) {
430
+ proxyReqPathResolver: function (request) {
405
431
  const url = new URL(request.query.u);
406
432
  return `${url.pathname}${url.search}${url.hash}`;
407
- }
433
+ },
408
434
  };
409
435
  app.use('/proxy', expressHttpProxy(proxyHost, proxyOptions));
410
436
 
@@ -412,15 +438,15 @@ async function serve(argv) {
412
438
  var swaggerOptions = {
413
439
  swaggerOptions: {
414
440
  showMutatedRequest: false,
415
- requestInterceptor: function(request) {
441
+ requestInterceptor: function (request) {
416
442
  if (request.url.startsWith('http://localhost')) {
417
443
  return request;
418
444
  }
419
445
 
420
446
  request.url = '/proxy?u=' + encodeURIComponent(request.url);
421
447
  return request;
422
- }
423
- }
448
+ },
449
+ },
424
450
  };
425
451
  app.use('/', swaggerUi.serve, swaggerUi.setup(document, swaggerOptions));
426
452
 
@@ -440,7 +466,7 @@ async function proxy(argv) {
440
466
  const document = YAML.load(input);
441
467
 
442
468
  // validate server name
443
- const validServerNames = document.servers.map(s => s.description);
469
+ const validServerNames = document.servers.map((s) => s.description);
444
470
  const serverName = argv.server;
445
471
 
446
472
  if (!validServerNames.includes(serverName)) {
@@ -449,7 +475,7 @@ async function proxy(argv) {
449
475
  }
450
476
 
451
477
  // validate server url
452
- const server = document.servers.find(s => s.description === serverName);
478
+ const server = document.servers.find((s) => s.description === serverName);
453
479
  if (!server.url) {
454
480
  console.error(`url must be defined for server ${server.description}`);
455
481
  exit(1);
@@ -470,8 +496,8 @@ async function generate(argv) {
470
496
 
471
497
  console.log(`generate targets: ${targetIds}`);
472
498
 
473
- targetIds.forEach(targetId => {
474
- const target = config.targets.find(t => t.id === targetId);
499
+ targetIds.forEach((targetId) => {
500
+ const target = config.targets.find((t) => t.id === targetId);
475
501
 
476
502
  // handle docs target
477
503
  if (target.type === 'openapi') {
@@ -491,7 +517,11 @@ async function generate(argv) {
491
517
  const templateDir = customizeTemplates(target);
492
518
 
493
519
  // run generation
494
- exec(`bash -e ${__dirname}/../targets/${target.type}/generate.sh ${VERSION} ${binary} ${CONFIG_FILE_NAME} ${target.id} ${sources[target.source]} ${formatter} ${target.generatorId} ${preRelease.toString()} ${templateDir}`);
520
+ exec(
521
+ `${__dirname}/../targets/${target.type}/generate.sh ${VERSION} ${binary} ${CONFIG_FILE_NAME} ${target.id} ${
522
+ sources[target.source]
523
+ } ${formatter} ${target.generatorId} ${preRelease.toString()} ${templateDir}`
524
+ );
495
525
  });
496
526
  }
497
527
 
@@ -503,8 +533,8 @@ async function publish(argv) {
503
533
 
504
534
  console.log(`publish targets: ${targetIds}`);
505
535
 
506
- targetIds.forEach(targetId => {
507
- const target = config.targets.find(t => t.id === targetId);
536
+ targetIds.forEach((targetId) => {
537
+ const target = config.targets.find((t) => t.id === targetId);
508
538
 
509
539
  // handle docs target
510
540
  if (target.type === 'openapi') {
@@ -520,13 +550,17 @@ async function publish(argv) {
520
550
  formatter = fetchFormatter(target);
521
551
  }
522
552
 
523
- exec(`bash -e ${__dirname}/../targets/${target.type}/publish.sh ${VERSION} ${binary} ${CONFIG_FILE_NAME} ${target.id} ${sources[target.source]} ${formatter} ${target.generatorId} ${preRelease.toString()}`);
553
+ exec(
554
+ `${__dirname}/../targets/${target.type}/publish.sh ${VERSION} ${binary} ${CONFIG_FILE_NAME} ${target.id} ${
555
+ sources[target.source]
556
+ } ${formatter} ${target.generatorId} ${preRelease.toString()}`
557
+ );
524
558
  });
525
559
  }
526
560
 
527
561
  function fetchBinary(target) {
528
562
  // determine binary
529
- const generator = target.generator
563
+ const generator = target.generator;
530
564
  const binary = {};
531
565
 
532
566
  if (generator.startsWith('http')) {
@@ -534,8 +568,7 @@ function fetchBinary(target) {
534
568
 
535
569
  const hash = crypto.createHash('sha256').update(binary.url).digest('hex').substring(0, 8);
536
570
  binary.name = `openapi-generator-cli-${hash}.jar`;
537
- }
538
- else {
571
+ } else {
539
572
  binary.url = `https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${generator}/openapi-generator-cli-${generator}.jar`;
540
573
  binary.name = `openapi-generator-cli-${generator}.jar`;
541
574
  }
@@ -549,26 +582,24 @@ function fetchBinary(target) {
549
582
 
550
583
  // download binary
551
584
  console.log(`... downloading ${binary.url} ==> ${binaryPath}`);
552
- exec(`bash -e -c "mkdir -p ${BIN_FOLDER}"`);
553
- exec(`bash -e -c "wget ${binary.url} -q -O ${binaryPath}"`);
554
- exec(`bash -e -c "chmod +x ${binaryPath}"`);
585
+ exec(`mkdir -p ${BIN_FOLDER}`);
586
+ exec(`wget ${binary.url} -q -O ${binaryPath}`);
587
+ exec(`chmod +x ${binaryPath}`);
555
588
  return binaryPath;
556
589
  }
557
590
 
558
591
  function fetchFormatter(target) {
559
592
  // determine binary
560
- const formatter = target.formatter
593
+ const formatter = target.formatter;
561
594
  const binary = {};
562
595
 
563
-
564
596
  //TODO: handle different types of platforms
565
597
  if (formatter.startsWith('http')) {
566
598
  binary.url = formatter;
567
599
 
568
600
  const hash = crypto.createHash('sha256').update(binary.url).digest('hex').substring(0, 8);
569
601
  binary.name = `ktlint-${hash}`;
570
- }
571
- else {
602
+ } else {
572
603
  binary.url = `https://github.com/pinterest/ktlint/releases/download/${formatter}/ktlint`;
573
604
  binary.name = `ktlint-${formatter}`;
574
605
  }
@@ -628,7 +659,7 @@ function determineSourceIds(argv) {
628
659
  }
629
660
 
630
661
  function validSourceIds() {
631
- return config.sources.map(s => s.id);
662
+ return config.sources.map((s) => s.id);
632
663
  }
633
664
 
634
665
  function checkSourceId(sourceId) {
@@ -652,8 +683,8 @@ function determineTargetIds(argv) {
652
683
 
653
684
  function sourceIdsFromTargetIds(targetIds) {
654
685
  const sourceIds = [];
655
- targetIds.forEach(targetId => {
656
- const target = config.targets.find(t => t.id === targetId);
686
+ targetIds.forEach((targetId) => {
687
+ const target = config.targets.find((t) => t.id === targetId);
657
688
  if (target.source) {
658
689
  sourceIds.push(target.source);
659
690
  }
@@ -662,7 +693,7 @@ function sourceIdsFromTargetIds(targetIds) {
662
693
  }
663
694
 
664
695
  function validTargetIds() {
665
- return config.targets.map(t => t.id);
696
+ return config.targets.map((t) => t.id);
666
697
  }
667
698
 
668
699
  function checkTargetId(targetId) {
@@ -674,8 +705,9 @@ function checkTargetId(targetId) {
674
705
 
675
706
  // find duplicates
676
707
  function findDuplicates(arr) {
677
- return arr.reduce(function(acc, el, i, arr) {
678
- if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el); return acc;
708
+ return arr.reduce(function (acc, el, i, arr) {
709
+ if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el);
710
+ return acc;
679
711
  }, []);
680
712
  }
681
713
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-supercharge/oasg",
3
- "version": "13.2.0-feature-csharp-functions-c3d21a55.0",
3
+ "version": "13.2.0-feature-csharp-functions-c1cbb3b0.0",
4
4
  "description": "Node-based tool to lint OpenAPI documents and generate clients, servers and documentation from them",
5
5
  "author": "Supercharge",
6
6
  "license": "MIT",