Skip to content

Commit f69cb63

Browse files
authored
Merge pull request #562 from Backbase/feature/BUS-603
[BUS-603]: angular generator: new mocks format in a separate file
2 parents a18a4a2 + 1d160b6 commit f69cb63

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ The project is very much Work In Progress and will be published on maven central
1818

1919
# Release Notes
2020
BOAT is still under development and subject to change.
21+
## 0.16.14
22+
* Boat Angular generator
23+
* New format for Angular mocks, which are now export an array with responses.
2124
## 0.16.13
2225
* Boat Angular generator
2326
* `@angular/common` added as a peer dependency in the generated package.json files

boat-scaffold/src/main/java/com/backbase/oss/codegen/angular/BoatAngularGenerator.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class BoatAngularGenerator extends AbstractTypeScriptClientCodegen {
7575
protected String serviceFileSuffix = ".service";
7676
protected String modelFileSuffix = "";
7777

78+
private static final String MOCKS_ARRAY_TEMPLATE_NAME = "apiMocks.array.mustache";
79+
7880
public BoatAngularGenerator() {
7981
super();
8082

@@ -105,6 +107,16 @@ public BoatAngularGenerator() {
105107
this.cliOptions.add(new CliOption(SPEC_VERSION, "The version of OpenAPI YAML spec used to generate the NPM package."));
106108
}
107109

110+
@Override
111+
public String apiFilename(String templateName, String tag) {
112+
String suffix = apiTemplateFiles().get(templateName);
113+
String folder = templateName.equals(MOCKS_ARRAY_TEMPLATE_NAME) ? mocksArrayFolder() : apiFileFolder();
114+
return folder + File.separator + toApiFilename(tag) + suffix;
115+
}
116+
117+
protected String mocksArrayFolder() {
118+
return outputFolder + File.separator + "mocks";
119+
}
108120

109121
@Override
110122
public void preprocessOpenAPI(OpenAPI openAPI) {
@@ -200,6 +212,7 @@ public void processOpts() {
200212
processBooleanOpt(WITH_MOCKS, withMocks -> {
201213
if (Boolean.TRUE.equals(withMocks)) {
202214
apiTemplateFiles.put("apiMocks.mustache", ".mocks.ts");
215+
apiTemplateFiles.put(MOCKS_ARRAY_TEMPLATE_NAME, ".mocks.array.js");
203216
}
204217
});
205218

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = [{{#operations}}
2+
{{#operation}}
3+
{
4+
urlPattern: "{{{basePathWithoutHost}}}{{pattern}}",
5+
method: "{{#lambda.uppercase}}{{httpMethod}}{{/lambda.uppercase}}",
6+
responses: [
7+
{{#responses}}
8+
{{#examples}}
9+
{{#isJson}}
10+
{
11+
status: {{{code}}},
12+
body: {{{prettyPrintValue}}}
13+
},
14+
{{/isJson}}
15+
{{^isJson}}
16+
{
17+
status: {{{code}}},
18+
body: "{{#escapeJavascript}}{{{prettyPrintValue}}}{{/escapeJavascript}}"
19+
},
20+
{{/isJson}}
21+
{{/examples}}
22+
{{#hasEmptyBody}}
23+
{
24+
status: {{{code}}},
25+
body: ""
26+
},
27+
{{/hasEmptyBody}}
28+
{{/responses}}
29+
]
30+
},
31+
{{/operation}}
32+
{{/operations}}]

boat-scaffold/src/main/templates/boat-angular/ng-package.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"lib": {
44
"entryFile": "public_api.ts"
55
},
6-
"dest": "{{{buildDist}}}"
6+
"dest": "{{{buildDist}}}",
7+
"assets": ["mocks/*.js"]
78
}

boat-scaffold/src/main/templates/boat-angular/package.mustache

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@
44
"description": "OpenAPI client for {{{npmName}}}",
55
"backbase": {
66
{{#specVersion}}
7-
"specVersion": "{{{specVersion}}}"
7+
"specVersion": "{{{specVersion}}}",
88
{{/specVersion}}
9+
{{#specArtifactId}}
10+
"specArtifactId": "{{{specArtifactId}}}",
11+
{{/specArtifactId}}
12+
{{#specGroupId}}
13+
"specGroupId": "{{{specGroupId}}}",
14+
{{/specGroupId}}
15+
{{#inputSpecRelative}}
16+
"inputSpecRelative": "{{{inputSpecRelative}}}",
17+
{{/inputSpecRelative}}
18+
{{#specClassifier}}
19+
"specClassifier": "{{{specClassifier}}}",
20+
{{/specClassifier}}
21+
{{#specType}}
22+
"specType": "{{{specType}}}"
23+
{{/specType}}
924
},
1025
"keywords": [
1126
"backbase",

boat-scaffold/src/test/java/com/backbase/oss/codegen/angular/BoatAngularTemplatesTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public void withMocks() {
123123
assertThat(
124124
findPattern(selectFiles("/api/.+\\.service\\.mocks\\.ts$"), "MocksProvider = /\\*#__PURE__\\*/ createMocks"),
125125
equalTo(this.param.withMocks));
126+
assertThat(
127+
findPattern(selectFiles("/mocks/.+\\.service\\.mocks\\.array\\.js$"), "module.exports"),
128+
equalTo(this.param.withMocks));
126129
}
127130

128131
@Check

0 commit comments

Comments
 (0)