mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-14 16:33:56 +00:00
Co-authored-by: Simon Baranov <simon.baranov@zahlungswerk.de>
This commit is contained in:
parent
6278512122
commit
6e48cf4247
@ -145,7 +145,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
||||||
// Set default User-Agent.
|
// Set default User-Agent.
|
||||||
setUserAgent("Java-SDK");
|
setUserAgent("{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}");
|
||||||
|
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||||
|
@ -3151,6 +3151,43 @@ public class JavaClientCodegenTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRestTemplateWithDefaultUserAgent() {
|
||||||
|
|
||||||
|
final Map<String, File> files = generateFromContract(
|
||||||
|
"src/test/resources/3_1/java/petstore.yaml",
|
||||||
|
JavaClientCodegen.RESTTEMPLATE
|
||||||
|
);
|
||||||
|
|
||||||
|
final JavaFileAssert apiClient = JavaFileAssert.assertThat(files.get("ApiClient.java"))
|
||||||
|
.printFileContent();
|
||||||
|
apiClient
|
||||||
|
.assertMethod("init")
|
||||||
|
.bodyContainsLines("setUserAgent(\"OpenAPI-Generator/1.0.0/java\");");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRestTemplateWithCustomUserAgent() {
|
||||||
|
|
||||||
|
final Path output = newTempFolder();
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setValidateSpec(false)
|
||||||
|
.setGeneratorName(JAVA_GENERATOR)
|
||||||
|
.setLibrary(JavaClientCodegen.RESTTEMPLATE)
|
||||||
|
.setHttpUserAgent("MyAwesomeCustomService/0.0.1")
|
||||||
|
.setInputSpec("src/test/resources/3_1/java/petstore.yaml")
|
||||||
|
.setOutputDir(output.toString().replace("\\", "/"));
|
||||||
|
|
||||||
|
final Map<String, File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate()
|
||||||
|
.stream().collect(Collectors.toMap(File::getName, Function.identity()));;
|
||||||
|
|
||||||
|
final JavaFileAssert apiClient = JavaFileAssert.assertThat(files.get("ApiClient.java"))
|
||||||
|
.printFileContent();
|
||||||
|
apiClient
|
||||||
|
.assertMethod("init")
|
||||||
|
.bodyContainsLines("setUserAgent(\"MyAwesomeCustomService/0.0.1\");");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestClientWithGeneratedOAuthTokenSuppliers() {
|
public void testRestClientWithGeneratedOAuthTokenSuppliers() {
|
||||||
final Map<String, File> files = generateFromContract(
|
final Map<String, File> files = generateFromContract(
|
||||||
@ -3195,6 +3232,7 @@ public class JavaClientCodegenTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestClientWithUseSingleRequestParameter_issue_19406() {
|
public void testRestClientWithUseSingleRequestParameter_issue_19406() {
|
||||||
final Path output = newTempFolder();
|
final Path output = newTempFolder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user