Skip to content

Commit fd81045

Browse files
committed
update samples after merge of master
1 parent 2a4b8f2 commit fd81045

12 files changed

Lines changed: 96 additions & 25 deletions

File tree

samples/client/echo_api/typescript-axios/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepare": "npm run build"
2323
},
2424
"dependencies": {
25-
"axios": "^1.6.1"
25+
"axios": "^1.13.5"
2626
},
2727
"devDependencies": {
2828
"@types/node": "12.11.5 - 12.20.42",

samples/client/petstore/java/feign-hc5/src/main/java/org/openapitools/client/ApiResponseDecoder.java

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,99 @@
1818
import feign.Types;
1919
import feign.jackson.JacksonDecoder;
2020

21+
import java.io.File;
2122
import java.io.IOException;
23+
import java.io.InputStream;
2224
import java.lang.reflect.ParameterizedType;
2325
import java.lang.reflect.Type;
26+
import java.nio.file.Files;
27+
import java.nio.file.Paths;
28+
import java.nio.file.StandardCopyOption;
2429
import java.util.Collection;
2530
import java.util.Collections;
2631
import java.util.Map;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
2734

2835
import org.openapitools.client.model.ApiResponse;
2936

3037
public class ApiResponseDecoder extends JacksonDecoder {
3138

39+
private static final Pattern FILENAME_PATTERN =
40+
Pattern.compile("filename=\"([^\"]+)\"|filename=([^\\s;]+)");
41+
3242
public ApiResponseDecoder(ObjectMapper mapper) {
3343
super(mapper);
3444
}
3545

3646
@Override
3747
public Object decode(Response response, Type type) throws IOException {
38-
//Detects if the type is an instance of the parameterized class ApiResponse
3948
if (type instanceof ParameterizedType && Types.getRawType(type).isAssignableFrom(ApiResponse.class)) {
40-
//The ApiResponse class has a single type parameter, the Dto class itself
4149
Type responseBodyType = ((ParameterizedType) type).getActualTypeArguments()[0];
42-
Object body = super.decode(response, responseBodyType);
50+
Object body = isBinaryType(responseBodyType)
51+
? decodeBinary(response, responseBodyType)
52+
: super.decode(response, responseBodyType);
4353
Map<String, Collection<String>> responseHeaders = Collections.unmodifiableMap(response.headers());
4454
return new ApiResponse<>(response.status(), responseHeaders, body);
55+
}
56+
57+
if (isBinaryType(type)) {
58+
return decodeBinary(response, type);
59+
}
60+
61+
return super.decode(response, type);
62+
}
63+
64+
private boolean isBinaryType(Type type) {
65+
Class<?> raw = Types.getRawType(type);
66+
return File.class.isAssignableFrom(raw)
67+
|| byte[].class.isAssignableFrom(raw)
68+
|| InputStream.class.isAssignableFrom(raw);
69+
}
70+
71+
private Object decodeBinary(Response response, Type type) throws IOException {
72+
Class<?> raw = Types.getRawType(type);
73+
if (response.body() == null) {
74+
return null;
75+
}
76+
if (byte[].class.isAssignableFrom(raw)) {
77+
return response.body().asInputStream().readAllBytes();
78+
}
79+
if (InputStream.class.isAssignableFrom(raw)) {
80+
return response.body().asInputStream();
81+
}
82+
return downloadToTempFile(response);
83+
}
84+
85+
private File downloadToTempFile(Response response) throws IOException {
86+
String filename = extractFilename(response);
87+
File file;
88+
if (filename != null) {
89+
// Sanitize: strip path components to prevent path traversal
90+
String safeName = Paths.get(filename).getFileName().toString();
91+
java.nio.file.Path tempDir = Files.createTempDirectory("feign-download");
92+
file = Files.createFile(tempDir.resolve(safeName)).toFile();
93+
tempDir.toFile().deleteOnExit();
4594
} else {
46-
//The response is not encapsulated in the ApiResponse, decode the Dto as normal
47-
return super.decode(response, type);
95+
file = Files.createTempFile("download-", "").toFile();
96+
}
97+
file.deleteOnExit();
98+
try (InputStream is = response.body().asInputStream()) {
99+
Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
100+
}
101+
return file;
102+
}
103+
104+
private String extractFilename(Response response) {
105+
Collection<String> dispositions = response.headers().get("Content-Disposition");
106+
if (dispositions == null) return null;
107+
for (String disposition : dispositions) {
108+
Matcher m = FILENAME_PATTERN.matcher(disposition);
109+
if (m.find()) {
110+
// Group 1: quoted filename (may contain spaces), Group 2: unquoted token
111+
return m.group(1) != null ? m.group(1) : m.group(2);
112+
}
48113
}
114+
return null;
49115
}
50116
}

samples/client/petstore/typescript-axios/builds/es6-target/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"prepare": "npm run build"
2525
},
2626
"dependencies": {
27-
"axios": "^1.6.1"
27+
"axios": "^1.13.5"
2828
},
2929
"devDependencies": {
3030
"@types/node": "12.11.5 - 12.20.42",

samples/client/petstore/typescript-axios/builds/test-petstore/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export type MammalAnyofTypeEnum = typeof MammalAnyofTypeEnum[keyof typeof Mammal
329329

330330
export interface MapTest {
331331
'map_map_of_string'?: { [key: string]: { [key: string]: string; }; };
332-
'map_of_enum_string'?: { [key: string]: string; };
332+
'map_of_enum_string'?: { [key: string]: MapTestMapOfEnumStringEnum; };
333333
'direct_map'?: { [key: string]: boolean; };
334334
'indirect_map'?: { [key: string]: boolean; };
335335
}

samples/client/petstore/typescript-axios/builds/with-complex-headers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepare": "npm run build"
2323
},
2424
"dependencies": {
25-
"axios": "^1.6.1"
25+
"axios": "^1.13.5"
2626
},
2727
"devDependencies": {
2828
"@types/node": "12.11.5 - 12.20.42",

samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export type Mammal = { className: 'whale' } & Whale | { className: 'zebra' } & Z
227227

228228
export interface MapTest {
229229
'map_map_of_string'?: { [key: string]: { [key: string]: string; }; };
230-
'map_of_enum_string'?: { [key: string]: string; };
230+
'map_of_enum_string'?: { [key: string]: MapTestMapOfEnumStringEnum; };
231231
'direct_map'?: { [key: string]: boolean; };
232232
'indirect_map'?: { [key: string]: boolean; };
233233
}

samples/client/petstore/typescript-axios/builds/with-npm-version-and-separate-models-and-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepare": "npm run build"
2323
},
2424
"dependencies": {
25-
"axios": "^1.6.1"
25+
"axios": "^1.13.5"
2626
},
2727
"devDependencies": {
2828
"@types/node": "12.11.5 - 12.20.42",

samples/client/petstore/typescript-axios/builds/with-npm-version/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepare": "npm run build"
2323
},
2424
"dependencies": {
25-
"axios": "^1.6.1"
25+
"axios": "^1.13.5"
2626
},
2727
"devDependencies": {
2828
"@types/node": "12.11.5 - 12.20.42",

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export interface MapTest {
2727
mapMapOfString?: { [key: string]: { [key: string]: string; }; };
2828
/**
2929
*
30-
* @type {{ [key: string]: string; }}
30+
* @type {{ [key: string]: MapTestMapOfEnumStringEnum; }}
3131
* @memberof MapTest
3232
*/
33-
mapOfEnumString?: { [key: string]: string; };
33+
mapOfEnumString?: { [key: string]: MapTestMapOfEnumStringEnum; };
3434
/**
3535
*
3636
* @type {{ [key: string]: boolean; }}

samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export interface MapTest {
2727
mapMapOfString?: { [key: string]: { [key: string]: string; }; };
2828
/**
2929
*
30-
* @type {{ [key: string]: string; }}
30+
* @type {{ [key: string]: MapTestMapOfEnumStringEnum; }}
3131
* @memberof MapTest
3232
*/
33-
mapOfEnumString?: { [key: string]: string; };
33+
mapOfEnumString?: { [key: string]: MapTestMapOfEnumStringEnum; };
3434
/**
3535
*
3636
* @type {{ [key: string]: boolean; }}

0 commit comments

Comments
 (0)