Skip to content

Commit

Permalink
Merge pull request #562 from Backbase/feature/BUS-603
Browse files Browse the repository at this point in the history
[BUS-603]: angular generator: new mocks format in a separate file
  • Loading branch information
daiscog authored Jun 9, 2023
2 parents a18a4a2 + 1d160b6 commit f69cb63
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The project is very much Work In Progress and will be published on maven central

# Release Notes
BOAT is still under development and subject to change.
## 0.16.14
* Boat Angular generator
* New format for Angular mocks, which are now export an array with responses.
## 0.16.13
* Boat Angular generator
* `@angular/common` added as a peer dependency in the generated package.json files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class BoatAngularGenerator extends AbstractTypeScriptClientCodegen {
protected String serviceFileSuffix = ".service";
protected String modelFileSuffix = "";

private static final String MOCKS_ARRAY_TEMPLATE_NAME = "apiMocks.array.mustache";

public BoatAngularGenerator() {
super();

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

@Override
public String apiFilename(String templateName, String tag) {
String suffix = apiTemplateFiles().get(templateName);
String folder = templateName.equals(MOCKS_ARRAY_TEMPLATE_NAME) ? mocksArrayFolder() : apiFileFolder();
return folder + File.separator + toApiFilename(tag) + suffix;
}

protected String mocksArrayFolder() {
return outputFolder + File.separator + "mocks";
}

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
Expand Down Expand Up @@ -200,6 +212,7 @@ public void processOpts() {
processBooleanOpt(WITH_MOCKS, withMocks -> {
if (Boolean.TRUE.equals(withMocks)) {
apiTemplateFiles.put("apiMocks.mustache", ".mocks.ts");
apiTemplateFiles.put(MOCKS_ARRAY_TEMPLATE_NAME, ".mocks.array.js");
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = [{{#operations}}
{{#operation}}
{
urlPattern: "{{{basePathWithoutHost}}}{{pattern}}",
method: "{{#lambda.uppercase}}{{httpMethod}}{{/lambda.uppercase}}",
responses: [
{{#responses}}
{{#examples}}
{{#isJson}}
{
status: {{{code}}},
body: {{{prettyPrintValue}}}
},
{{/isJson}}
{{^isJson}}
{
status: {{{code}}},
body: "{{#escapeJavascript}}{{{prettyPrintValue}}}{{/escapeJavascript}}"
},
{{/isJson}}
{{/examples}}
{{#hasEmptyBody}}
{
status: {{{code}}},
body: ""
},
{{/hasEmptyBody}}
{{/responses}}
]
},
{{/operation}}
{{/operations}}]
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"lib": {
"entryFile": "public_api.ts"
},
"dest": "{{{buildDist}}}"
"dest": "{{{buildDist}}}",
"assets": ["mocks/*.js"]
}
17 changes: 16 additions & 1 deletion boat-scaffold/src/main/templates/boat-angular/package.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
"description": "OpenAPI client for {{{npmName}}}",
"backbase": {
{{#specVersion}}
"specVersion": "{{{specVersion}}}"
"specVersion": "{{{specVersion}}}",
{{/specVersion}}
{{#specArtifactId}}
"specArtifactId": "{{{specArtifactId}}}",
{{/specArtifactId}}
{{#specGroupId}}
"specGroupId": "{{{specGroupId}}}",
{{/specGroupId}}
{{#inputSpecRelative}}
"inputSpecRelative": "{{{inputSpecRelative}}}",
{{/inputSpecRelative}}
{{#specClassifier}}
"specClassifier": "{{{specClassifier}}}",
{{/specClassifier}}
{{#specType}}
"specType": "{{{specType}}}"
{{/specType}}
},
"keywords": [
"backbase",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public void withMocks() {
assertThat(
findPattern(selectFiles("/api/.+\\.service\\.mocks\\.ts$"), "MocksProvider = /\\*#__PURE__\\*/ createMocks"),
equalTo(this.param.withMocks));
assertThat(
findPattern(selectFiles("/mocks/.+\\.service\\.mocks\\.array\\.js$"), "module.exports"),
equalTo(this.param.withMocks));
}

@Check
Expand Down

0 comments on commit f69cb63

Please sign in to comment.