From 1e6cf2be474216110a2d68ab55a5004dcac70188 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Sat, 7 Sep 2024 21:51:07 +0400 Subject: [PATCH] feat(preview): resolve nested references --- .../idea/_core/AsyncAPISpecificationHtmlRenderer.kt | 2 +- .../asyncapi/plugin/idea/extensions/web/StaticServer.kt | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/asyncapi/plugin/idea/_core/AsyncAPISpecificationHtmlRenderer.kt b/src/main/kotlin/com/asyncapi/plugin/idea/_core/AsyncAPISpecificationHtmlRenderer.kt index bf4d351..2120779 100644 --- a/src/main/kotlin/com/asyncapi/plugin/idea/_core/AsyncAPISpecificationHtmlRenderer.kt +++ b/src/main/kotlin/com/asyncapi/plugin/idea/_core/AsyncAPISpecificationHtmlRenderer.kt @@ -70,7 +70,7 @@ class AsyncAPISpecificationHtmlRenderer { ) } - private fun replaceLocalReferences(specification: String, specificationFile: VirtualFile, isJson: Boolean): String { + fun replaceLocalReferences(specification: String, specificationFile: VirtualFile, isJson: Boolean): String { val objectMapper = if (isJson) { ObjectMapper() } else { diff --git a/src/main/kotlin/com/asyncapi/plugin/idea/extensions/web/StaticServer.kt b/src/main/kotlin/com/asyncapi/plugin/idea/extensions/web/StaticServer.kt index ce47320..706bdb4 100644 --- a/src/main/kotlin/com/asyncapi/plugin/idea/extensions/web/StaticServer.kt +++ b/src/main/kotlin/com/asyncapi/plugin/idea/extensions/web/StaticServer.kt @@ -12,6 +12,7 @@ import org.jetbrains.io.send import org.jetbrains.yaml.YAMLFileType import java.io.File import java.nio.charset.StandardCharsets +import kotlin.text.toByteArray /** * @author Pavel Bodiachevskii @@ -128,7 +129,12 @@ class StaticServer : HttpRequestHandler() { "application/x-yaml" } - return Resource(contentType, requestedFile.readBytes()) + val componentJson = asyncAPISpecificationHtmlRenderer.replaceLocalReferences( + requestedFile.readText(StandardCharsets.UTF_8), + referenceVirtualFile, + isJson + ) + return Resource(contentType, componentJson.toByteArray(StandardCharsets.UTF_8)) } private fun resolveResource(resourceName: String): Resource? {