Skip to content

Commit a6652d6

Browse files
jonaslagonimagicmatatjahuquetzalliwrites
authored
fix: add multiple blackbox tests and fix small bugs (#371)
Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com> Co-authored-by: Alejandra Quetzalli <19964402+alequetzalli@users.noreply.github.com>
1 parent c240b0a commit a6652d6

35 files changed

+39828
-132
lines changed

.github/workflows/blackbox-testing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ jobs:
3232
- if: matrix.os == 'windows-latest'
3333
name: Setup csc.exe
3434
uses: yoavain/Setup-CSC@v7
35+
- uses: actions/setup-go@v2
36+
with:
37+
go-version: '1.16.8'
3538
- name: Test output
3639
run: npm run test:blackbox

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
99
&& apt-get install -yq nodejs
1010

1111
# Install golang
12-
RUN curl -fsSL https://golang.org/dl/go1.16.5.linux-amd64.tar.gz | tar -C /usr/local -xz
12+
RUN curl -fsSL https://golang.org/dl/go1.16.8.linux-amd64.tar.gz | tar -C /usr/local -xz
1313
ENV PATH="${PATH}:/usr/local/go/bin"
1414

1515
# Install dotnet SDK

docs/development.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,15 @@ You can either build the image and run the needed commands manually or rather us
77

88
- `npm run docker:build` builds the docker image with the tag `asyncapi/modelina` (the rest of the scripts run this one as well).
99
- `npm run docker:test` runs the main test suite.
10-
- `npm run docker:test:blackbox` runs the blackbox test suite.
10+
- `npm run docker:test:blackbox` runs the BlackBox test suite.
1111

1212
## Environment setup
1313

1414
To setup the environment follow these steps:
1515
1. Setup the project by first installing the dependencies `npm install`
1616
2. Make sure the tests pass by running `npm run test` script
17-
- [Blackbox testing](#blackbox-testing) are excluded when running the `test` script because it require some extra setup. Please refer to [Blackbox testing section](#blackbox-testing) below.
1817
- You can update snapshots by running `npm run test -- -u`
1918
3. Make sure code is well formatted and secure `npm run lint`
2019

21-
## Blackbox testing
22-
Please refer to [Docker section](#docker) above if you wanna run the tests directly in Docker without configuring anything extra on your machine.
23-
If you prefer to install all the dependencies locally, keep reading.
24-
25-
The blackbox testing have some different requirements in order to successfully run:
26-
- To to run the `java` blackbox tests, you need to have JDK installed.
27-
- To to run the `ts` blackbox tests, you need to have TypeScript installed globally - `npm install -g typescript`.
28-
- To to run the `C#` blackbox tests, you need to have C# compiler installed globally. - https://www.mono-project.com/download/stable/
29-
30-
By default the blackbox tests are not run with the regular `npm run test`, but can be run with `npm run test:blackbox`.
20+
## BlackBox testing
21+
We have several BlackBox tests that are run separately from the `npm run test` script. Please refer to the [BlackBox documentation](../test/blackbox) for further information.

src/generators/csharp/CSharpGenerator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ export class CSharpGenerator extends AbstractGenerator<CSharpOptions> {
3232
render(model: CommonModel, inputModel: CommonInputModel): Promise<RenderOutput> {
3333
const kind = TypeHelpers.extractKind(model);
3434
switch (kind) {
35+
case ModelKind.UNION:
36+
//We dont support union in Csharp generator, however, if union is an object, we render it as a class.
37+
if (!model.type?.includes('object')) {break;}
38+
return this.renderClass(model, inputModel);
3539
case ModelKind.OBJECT:
3640
return this.renderClass(model, inputModel);
3741
case ModelKind.ENUM:
3842
return this.renderEnum(model, inputModel);
3943
}
40-
4144
return Promise.resolve(RenderOutput.toRenderOutput({ result: '', dependencies: [] }));
4245
}
4346

src/generators/csharp/CSharpRenderer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ export abstract class CSharpRenderer extends AbstractRenderer<CSharpOptions> {
6868
}
6969

7070
toCSharpType(type: string | undefined, model: CommonModel): string {
71-
if (type === undefined) {
72-
return 'dynamic';
73-
}
74-
7571
switch (type) {
7672
case 'string':
7773
return 'string';
@@ -90,7 +86,7 @@ export abstract class CSharpRenderer extends AbstractRenderer<CSharpOptions> {
9086
const arrayType = model.items ? this.renderType(model.items) : 'dynamic';
9187
return `${arrayType}[]`;
9288
}
93-
default: return type;
89+
default: return 'dynamic';
9490
}
9591
}
9692
}

src/generators/go/GoGenerator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ export class GoGenerator extends AbstractGenerator<GoOptions> {
5555
render(model: CommonModel, inputModel: CommonInputModel): Promise<RenderOutput> {
5656
const kind = TypeHelpers.extractKind(model);
5757
switch (kind) {
58+
case ModelKind.UNION:
59+
// We don't support union in Go generator, however, if union is an object, we render it as a struct.
60+
if (!model.type?.includes('object')) {break;}
61+
return this.renderStruct(model, inputModel);
5862
case ModelKind.OBJECT:
5963
return this.renderStruct(model, inputModel);
6064
case ModelKind.ENUM:
6165
return this.renderEnum(model, inputModel);
6266
}
63-
6467
return Promise.resolve(RenderOutput.toRenderOutput({ result: '', dependencies: [] }));
6568
}
6669

src/generators/go/GoRenderer.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ export abstract class GoRenderer extends AbstractRenderer<GoOptions> {
9696

9797
/* eslint-disable sonarjs/no-duplicate-string */
9898
toGoType(type: string | undefined, model: CommonModel): string {
99-
if (type === undefined) {
100-
return 'interface{}';
101-
}
102-
10399
switch (type) {
104100
case 'string':
105101
return 'string';
@@ -113,12 +109,12 @@ export abstract class GoRenderer extends AbstractRenderer<GoOptions> {
113109
return 'interface{}';
114110
case 'array': {
115111
if (Array.isArray(model.items)) {
116-
return model.items.length > 1? '[]interface{}' : `[]${this.renderType(model.items[0])}`;
112+
return model.items.length > 1 ? '[]interface{}' : `[]${this.renderType(model.items[0])}`;
117113
}
118114
const arrayType = model.items ? this.renderType(model.items) : 'interface{}';
119115
return `[]${arrayType}`;
120116
}
121-
default: return type;
117+
default: return 'interface{}';
122118
}
123119
}
124120
}

src/generators/java/JavaGenerator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ export class JavaGenerator extends AbstractGenerator<JavaOptions> {
2929

3030
render(model: CommonModel, inputModel: CommonInputModel): Promise<RenderOutput> {
3131
const kind = TypeHelpers.extractKind(model);
32-
if (kind === ModelKind.ENUM) {
32+
// We don't support union in Java generator, however, if union is an object, we render it as a class.
33+
if (kind === ModelKind.OBJECT || (kind === ModelKind.UNION && model.type?.includes('object'))) {
34+
return this.renderClass(model, inputModel);
35+
} else if (kind === ModelKind.ENUM) {
3336
return this.renderEnum(model, inputModel);
3437
}
35-
return this.renderClass(model, inputModel);
38+
return Promise.resolve(RenderOutput.toRenderOutput({ result: '', dependencies: [] }));
3639
}
3740

3841
async renderClass(model: CommonModel, inputModel: CommonInputModel): Promise<RenderOutput> {

src/generators/java/renderers/ClassRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ClassRenderer extends JavaRenderer {
2020
if (this.options?.collectionType === 'List') {
2121
this.addDependency('import java.util.List;');
2222
}
23-
if (this.model.additionalProperties !== undefined) {
23+
if (this.model.additionalProperties !== undefined || this.model.patternProperties !== undefined) {
2424
this.addDependency('import java.util.Map;');
2525
}
2626

src/generators/typescript/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const RESERVED_TYPESCRIPT_KEYWORDS = [
5151
'from',
5252
'of',
5353
// Strict mode reserved words
54+
'arguments',
5455
'as',
5556
'implements',
5657
'interface',

0 commit comments

Comments
 (0)