use of io.swagger.parser.SwaggerCompatConverter in project gravitee-management-rest-api by gravitee-io.
the class SwaggerServiceImpl method transformV1.
private Swagger transformV1(String content, PageConfigurationEntity config) {
// Create temporary file for Swagger parser (only for descriptor version < 2.x)
File temp = null;
String fileName = "gio_swagger_" + System.currentTimeMillis();
BufferedWriter bw = null;
FileWriter out = null;
Swagger swagger = null;
try {
temp = File.createTempFile(fileName, ".tmp");
out = new FileWriter(temp);
bw = new BufferedWriter(out);
bw.write(content);
bw.close();
swagger = new SwaggerCompatConverter().read(temp.getAbsolutePath());
if (swagger != null && config != null && config.getTryItURL() != null) {
URI newURI = URI.create(config.getTryItURL());
swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme())));
swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost());
swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath());
}
} catch (IOException ioe) {
// Fallback to the new parser
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
if (temp != null) {
temp.delete();
}
}
return swagger;
}
Aggregations