Skip to content

Commit df34466

Browse files
authored
Merge branch 'master' into model-bug
2 parents 414dc52 + cec8081 commit df34466

File tree

6 files changed

+65
-5
lines changed

6 files changed

+65
-5
lines changed

.changeset/quick-pandas-stare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@asyncapi/cli": patch
3+
---
4+
5+
feat: added Proxy support for the generate commands.

docs/usage.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Generates whatever you want using templates compatible with AsyncAPI Generator.
428428
USAGE
429429
$ asyncapi generate fromTemplate ASYNCAPI TEMPLATE [-h] [-d <value>...] [--no-interactive] [-i] [--debug] [-n <value>...]
430430
[-o <value>] [--force-write] [-w] [-p <value>...] [--map-base-url <value>] [--registry-url <value>] [--registry-auth
431-
<value>] [--registry-token <value>] [--use-new-generator]
431+
<value>] [--registry-token <value>] [--proxyHost <value>] [--proxyPort <value>] [--use-new-generator]
432432
433433
ARGUMENTS
434434
ASYNCAPI - Local path, url or context-name pointing to AsyncAPI file
@@ -454,6 +454,8 @@ FLAGS
454454
username and password
455455
--registry-url=<value> [default: https://registry.npmjs.org] Specifies the URL of the private registry for
456456
fetching templates and dependencies
457+
--proxyHost=<value> Name of the ProxyHost
458+
--proxyPort=<value> Port number number for the proxyHost.
457459
--use-new-generator Use v2 generator, for generating from newer templates
458460
459461
DESCRIPTION
@@ -477,7 +479,7 @@ USAGE
477479
[--csharpAutoImplement] [--csharpNewtonsoft] [--csharpArrayType Array|List] [--csharpHashcode] [--csharpEqual]
478480
[--csharpSystemJson] [--javaIncludeComments] [--javaJackson] [--javaConstraints] [--javaArrayType Array|List]
479481
[--pyDantic] [--no-interactive] [--log-diagnostics] [--diagnostics-format
480-
json|stylish|junit|html|text|teamcity|pretty] [--fail-severity error|warn|info|hint]
482+
json|stylish|junit|html|text|teamcity|pretty] [--proxyHost <value>] [--proxyPort <value>] [--fail-severity error|warn|info|hint]
481483
482484
ARGUMENTS
483485
LANGUAGE (typescript|csharp|golang|java|javascript|dart|python|rust|kotlin|php|cplusplus|scala) The language you want
@@ -528,6 +530,8 @@ FLAGS
528530
--tsModuleSystem=<option> [default: ESM] TypeScript specific, define the module system to be used.
529531
<options: ESM|CJS>
530532
--tsRawPropertyNames Typescript specific, generate the models using raw property names.
533+
--proxyHost=<value> Name of the ProxyHost
534+
--proxyPort=<value> Port number number for the proxyHost.
531535
532536
DESCRIPTION
533537
Generates typed models

src/commands/generate/fromTemplate.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { intro, isCancel, spinner, text } from '@clack/prompts';
1616
import { inverse, yellow, magenta, green, red } from 'picocolors';
1717
import fetch from 'node-fetch';
1818
import { fromTemplateFlags } from '../../core/flags/generate/fromTemplate.flags';
19+
import { proxyFlags } from '../../core/flags/proxy.flags';
1920

2021
interface IMapBaseUrlToFlag {
2122
url: string,
@@ -57,7 +58,10 @@ export default class Template extends Command {
5758
'asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template --param version=1.0.0 singleFile=true --output ./docs --force-write'
5859
];
5960

60-
static flags = fromTemplateFlags();
61+
static readonly flags = {
62+
...fromTemplateFlags(),
63+
...proxyFlags()
64+
};
6165

6266
static args = {
6367
asyncapi: Args.string({ description: '- Local path, url or context-name pointing to AsyncAPI file', required: true }),
@@ -72,6 +76,7 @@ export default class Template extends Command {
7276

7377
let { asyncapi, template } = args;
7478
let output = flags.output as string;
79+
const {proxyPort,proxyHost} = flags;
7580
if (interactive) {
7681
intro(inverse('AsyncAPI Generator'));
7782

@@ -96,6 +101,11 @@ export default class Template extends Command {
96101
token: flags['registry-token']
97102
}
98103
};
104+
105+
if (proxyHost && proxyPort) {
106+
const proxyUrl = `http://${proxyHost}:${proxyPort}`;
107+
asyncapi = `${asyncapi}+${proxyUrl}`;
108+
}
99109
const asyncapiInput = (await load(asyncapi)) || (await load());
100110

101111
this.specFile = asyncapiInput;

src/commands/generate/models.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ import { cancel, intro, isCancel, select, spinner, text } from '@clack/prompts';
55
import { green, inverse } from 'picocolors';
66
import { generateModels, Languages, ModelinaArgs } from '@asyncapi/modelina-cli';
77
import { modelsFlags } from '../../core/flags/generate/models.flags';
8+
import { proxyFlags } from '../../core/flags/proxy.flags';
89

910
export default class Models extends Command {
1011
static description = 'Generates typed models';
1112

1213
static readonly args = ModelinaArgs as any;
1314

14-
static flags = modelsFlags();
15+
static readonly flags = {
16+
...modelsFlags(),
17+
...proxyFlags(),
18+
};
1519

1620
async run() {
1721
const { args, flags } = await this.parse(Models);
18-
let { language, file } = args;
22+
let { language, file} = args;
1923
let { output } = flags;
24+
const {proxyPort,proxyHost} = flags;
2025

2126
const interactive = !flags['no-interactive'];
2227

@@ -29,6 +34,10 @@ export default class Models extends Command {
2934
output = parsedArgs.output;
3035
}
3136

37+
if (proxyHost && proxyPort) {
38+
const proxyUrl = `http://${proxyHost}:${proxyPort}`;
39+
file = `${file}+${proxyUrl}`;
40+
}
3241
const inputFile = (await load(file)) || (await load());
3342

3443
const { document, diagnostics ,status } = await parse(this, inputFile, flags as ValidateOptions);

test/integration/generate/fromTemplate.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ describe('template', () => {
6969
});
7070
});
7171

72+
describe('should error out on proxy port', () => {
73+
test
74+
.stderr()
75+
.stdout()
76+
.command([
77+
'generate:fromTemplate',
78+
'http://localhost:8080/dummySpec.yml',
79+
'@asyncapi/newtemplate',
80+
'--output=./test/docs/2',
81+
'--force-write',
82+
'--proxyHost=host',
83+
'--proxyPort=8080',
84+
'--use-new-generator',
85+
])
86+
.it('should throw error when url is passed with proxyHost and proxyPort with invalid host', (ctx, done) => {
87+
expect(ctx.stdout).to.contain('');
88+
expect(ctx.stderr).to.equal('error loading AsyncAPI document from url: Failed to download http://localhost:8080/dummySpec.yml.\n');
89+
cleanup('./test/docs/2');
90+
done();
91+
});
92+
});
93+
7294
describe('git clash', () => {
7395
const pathToOutput = './test/docs/2';
7496
before(() => {

test/integration/generate/models.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ describe('models', () => {
3535
);
3636
done();
3737
});
38+
39+
test
40+
.stderr()
41+
.stdout()
42+
.command([...generalOptions,'typescript','http://localhost:8080/dummySpec.yml --proxyHost=host --proxyPort=8080'])
43+
.it('should throw error when url is passed with proxyHost and proxyPort with invalid host ', (ctx, done) => {
44+
expect(ctx.stdout).to.contain('');
45+
expect(ctx.stderr).to.equal('error loading AsyncAPI document from url: Failed to download http://localhost:8080/dummySpec.yml --proxyHost=host --proxyPort=8080.\n');
46+
done();
47+
});
3848

3949
describe('with logging diagnostics', () => {
4050
test

0 commit comments

Comments
 (0)