From c9201299756a61bace17ee94942b210c072e1987 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 9 Oct 2023 12:32:11 +0200 Subject: [PATCH 1/2] Fix @Component for RestTemplate ApiClient --- .../libraries/resttemplate/ApiClient.mustache | 4 ++++ .../libraries/resttemplate/api.mustache | 2 ++ .../codegen/java/BoatJavaCodeGenTests.java | 20 ++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/ApiClient.mustache b/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/ApiClient.mustache index cd4054f24..0c48412c9 100644 --- a/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/ApiClient.mustache +++ b/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/ApiClient.mustache @@ -29,7 +29,9 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; {{/withXml}} +{{#createApiComponent}} import org.springframework.stereotype.Component; +{{/createApiComponent}} import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -84,7 +86,9 @@ import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} {{>generatedAnnotation}} +{{#createApiComponent}} @Component("{{invokerPackage}}.ApiClient") +{{/createApiComponent}} public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { public enum CollectionFormat { CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null); diff --git a/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/api.mustache b/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/api.mustache index 1966c50da..92760fd0b 100644 --- a/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/api.mustache +++ b/boat-scaffold/src/main/templates/boat-java/libraries/resttemplate/api.mustache @@ -13,7 +13,9 @@ import java.util.Map; import java.util.stream.Collectors;{{/fullJavaUtil}} import org.springframework.beans.factory.annotation.Autowired; +{{#createApiComponent}} import org.springframework.stereotype.Component; +{{/createApiComponent}} import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClientException; diff --git a/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatJavaCodeGenTests.java b/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatJavaCodeGenTests.java index e4664fa22..d3f58bb12 100644 --- a/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatJavaCodeGenTests.java +++ b/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatJavaCodeGenTests.java @@ -1,7 +1,6 @@ package com.backbase.oss.codegen.java; import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; import io.swagger.parser.OpenAPIParser; import io.swagger.v3.parser.core.models.ParseOptions; @@ -11,10 +10,10 @@ import org.openapitools.codegen.CliOption; import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.DefaultGenerator; -import org.openapitools.codegen.languages.SpringCodegen; import java.io.File; import java.io.FileNotFoundException; +import java.util.function.Function; import java.util.List; import java.util.Map; @@ -140,15 +139,22 @@ void shouldHonourGenerateComponentAnnotation(boolean generate) throws Interrupte List files = new DefaultGenerator().opts(clientOptInput).generate(); - File apiFile = files.stream() - .filter(file -> file.getName().equals("PaymentsApiClient.java")) - .findFirst() - .get(); + Function getFileByName = (String fileName) -> files.stream() + .filter(file -> file.getName().equals(fileName)) + .findFirst() + .get(); + + File apiFile = getFileByName.apply("PaymentsApiClient.java"); TypeDeclaration apiType = StaticJavaParser.parse(apiFile) .findFirst(TypeDeclaration.class).get(); + assertThat(apiType.getAnnotationByName("Component").isPresent(), is(generate)); + + File apiClientFile = getFileByName.apply("ApiClient.java"); + TypeDeclaration apiClientType = StaticJavaParser.parse(apiClientFile) + .findFirst(TypeDeclaration.class).get(); + assertThat(apiClientType.getAnnotationByName("Component").isPresent(), is(generate)); assertThat(gen.createApiComponent, is(generate)); assertThat(gen.getLibrary(), is("resttemplate")); - assertThat(apiType.getAnnotationByName("Component").isPresent(), is(generate)); } } From e61ed36a5721c490e289d20ab9ad37fdc73f6ee8 Mon Sep 17 00:00:00 2001 From: Krzysztof Grobarczyk Date: Mon, 9 Oct 2023 12:54:42 +0200 Subject: [PATCH 2/2] Fix @Component for RestTemplate ApiClient - readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e2c7e203..7b448e296 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ It currently consists of # Release Notes BOAT is still under development and subject to change. - +## 0.17.24 +* boat-spring + * Fix [Inconsistent @Component for RestTemplate](https://github.com/Backbase/backbase-openapi-tools/issues/661) ## 0.17.23 * *Boat Engine* * Added support for byte array examples