@@ -8,14 +8,11 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
8
8
import com.intellij.json.JsonFileType
9
9
import com.intellij.openapi.components.Service
10
10
import com.intellij.openapi.components.service
11
- import com.intellij.openapi.util.io.FileUtil
12
- import com.intellij.openapi.util.io.systemIndependentPath
13
11
import com.intellij.openapi.vfs.LocalFileSystem
14
12
import com.intellij.openapi.vfs.VirtualFile
15
13
import io.netty.handler.codec.http.FullHttpRequest
16
14
import org.jetbrains.yaml.YAMLFileType
17
15
import java.io.File
18
- import java.util.function.Supplier
19
16
20
17
/* *
21
18
* @author Pavel Bodiachevskii
@@ -47,20 +44,19 @@ class AsyncAPISpecificationHtmlRenderer {
47
44
48
45
val isJson = specificationVirtualFile.fileType is JsonFileType
49
46
val specification = replaceLocalReferences(specificationFile.readText(Charsets .UTF_8 ), specificationVirtualFile, isJson)
50
- val temporalSpecificationUrl = saveAsTemporalFile(specification, isJson)
51
47
52
48
val specificationTemplate = this .javaClass.getResource(specificationTemplateUrl)
53
49
specificationTemplate ? : return " specification template not found."
54
50
55
51
val webSocket = webSocketRendererProvider.provide(
56
52
fullHttpRequest = request,
57
- supplier = Supplier < VirtualFile ?> { specificationVirtualFile }
53
+ supplier = { specificationVirtualFile }
58
54
)
59
55
60
56
return specificationTemplate.readText(Charsets .UTF_8 )
61
57
.replace(
62
- " url: '' ," ,
63
- " url: ' ${urlProvider. specification(temporalSpecificationUrl)} ' ,"
58
+ " schema: {} ," ,
59
+ " schema: $ specification ,"
64
60
)
65
61
.replace(
66
62
" <link rel=\" stylesheet\" href=\"\" >" ,
@@ -74,7 +70,7 @@ class AsyncAPISpecificationHtmlRenderer {
74
70
)
75
71
}
76
72
77
- private fun replaceLocalReferences (specification : String , specificationFile : VirtualFile , isJson : Boolean ): String {
73
+ fun replaceLocalReferences (specification : String , specificationFile : VirtualFile , isJson : Boolean ): String {
78
74
val objectMapper = if (isJson) {
79
75
ObjectMapper ()
80
76
} else {
@@ -89,7 +85,7 @@ class AsyncAPISpecificationHtmlRenderer {
89
85
}
90
86
}
91
87
92
- return objectMapper .writeValueAsString(tree)
88
+ return ObjectMapper () .writeValueAsString(tree)
93
89
}
94
90
95
91
private fun localReferenceToFileUrl (localReference : String , specificationFile : VirtualFile ): String {
@@ -104,17 +100,4 @@ class AsyncAPISpecificationHtmlRenderer {
104
100
return urlProvider.reference(referencedFile.path, specificationComponentReference)
105
101
}
106
102
107
- private fun saveAsTemporalFile (specification : String , isJson : Boolean ): String {
108
- val suffix = if (isJson) {
109
- " .json"
110
- } else {
111
- " .yaml"
112
- }
113
-
114
- val tempSpecification = FileUtil .createTempFile(" jasyncapi-idea-plugin-${System .currentTimeMillis()} " , suffix, true )
115
- tempSpecification.writeText(specification, Charsets .UTF_8 )
116
-
117
- return tempSpecification.systemIndependentPath
118
- }
119
-
120
103
}
0 commit comments