Skip to content

Commit

Permalink
Fix @component for RestTemplate ApiClient (#662)
Browse files Browse the repository at this point in the history
* Fix @component for RestTemplate ApiClient
  • Loading branch information
krzysztofbackbase authored Oct 9, 2023
1 parent 0714a7d commit 3f39603
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -140,15 +139,22 @@ void shouldHonourGenerateComponentAnnotation(boolean generate) throws Interrupte

List<File> files = new DefaultGenerator().opts(clientOptInput).generate();

File apiFile = files.stream()
.filter(file -> file.getName().equals("PaymentsApiClient.java"))
.findFirst()
.get();
Function<String, File> 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));
}
}

0 comments on commit 3f39603

Please sign in to comment.