mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-19 21:37:15 +00:00
This commit is contained in:
@@ -83,6 +83,54 @@ public class AnotherFakeApi {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* To test special tags
|
||||
* To test special tags and operation ID starting with number
|
||||
|
||||
@@ -83,6 +83,54 @@ public class DefaultApi {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
||||
@@ -100,6 +100,54 @@ public class FakeApi {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* for Java apache and Java native, test toUrlQueryString for maps with BegDecimal keys
|
||||
|
||||
@@ -89,6 +89,54 @@ public class FakeClassnameTags123Api {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* To test class name in snake case
|
||||
* To test class name in snake case
|
||||
|
||||
@@ -91,6 +91,54 @@ public class PetApi {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
|
||||
@@ -89,6 +89,54 @@ public class StoreApi {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
@@ -90,6 +90,54 @@ public class UserApi {
|
||||
return operationId + " call failed with: " + statusCode + " - " + body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from the given response.
|
||||
*
|
||||
* @param response Response
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare the file for download from the response.</p>
|
||||
*
|
||||
* @param response a {@link java.net.http.HttpResponse} object.
|
||||
* @return a {@link java.io.File} object.
|
||||
* @throws java.io.IOException if any.
|
||||
*/
|
||||
private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOException {
|
||||
String filename = null;
|
||||
java.util.Optional<String> contentDisposition = response.headers().firstValue("Content-Disposition");
|
||||
if (contentDisposition.isPresent() && !"".equals(contentDisposition.get())) {
|
||||
// Get filename from the Content-Disposition header.
|
||||
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
|
||||
java.util.regex.Matcher matcher = pattern.matcher(contentDisposition.get());
|
||||
if (matcher.find())
|
||||
filename = matcher.group(1);
|
||||
}
|
||||
File file = null;
|
||||
if (filename != null) {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("swagger-gen-native");
|
||||
java.nio.file.Path filePath = java.nio.file.Files.createFile(tempDir.resolve(filename));
|
||||
file = filePath.toFile();
|
||||
tempDir.toFile().deleteOnExit(); // best effort cleanup
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
} else {
|
||||
file = java.nio.file.Files.createTempFile("download-", "").toFile();
|
||||
file.deleteOnExit(); // best effort cleanup
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
|
||||
Reference in New Issue
Block a user