Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @Component for RestTemplate ApiClient #662

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}