Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 2.7.0 #141

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog

## 2.6.0+jre21
## 2.7.0+jre17
published to:
- [JetBrains marketplace](https://plugins.jetbrains.com/plugin/15673-asyncapi/versions/stable/643494)
- [GitHub](https://github.com/asyncapi/jasyncapi-idea-plugin/releases/new?tag=2.7.0%2Bjre17)
Pakisan marked this conversation as resolved.
Show resolved Hide resolved

### Added

- Resolve local references for correct AsyncAPI specification rendering

### Fixed

- Inject AsyncAPI specification directly into preview instead of saving as temporal file and rendering it

## 2.6.0+jre17
published to:
- [JetBrains marketplace](https://plugins.jetbrains.com/plugin/15673-asyncapi/edit/versions/stable/596939)
- [GitHub](https://github.com/asyncapi/jasyncapi-idea-plugin/releases/new?tag=2.6.0%2Bjre17)
Expand Down
16 changes: 11 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.asyncapi.plugin.idea"
version = "2.6.0+jre17"
version = "2.7.0+jre17"
Pakisan marked this conversation as resolved.
Show resolved Hide resolved

repositories {
mavenCentral()
Expand Down Expand Up @@ -61,9 +61,11 @@ intellijPlatform {
changeNotes = """
<h3>Added</h3>
<ul>
<li>IDEA 2024.2</li>
<li>Yaml single quoted references handling - '#/components/messages/welcomeMessage', '../common/messages/welcomeMessage.yml'</li>
<li><code>.yml</code> file recognition</li>
<li>Resolve local references for correct AsyncAPI specification rendering</li>
</ul>
<h3>Fixed</h3>
<ul>
<li>Inject AsyncAPI specification directly into preview instead of saving as temporal file and rendering it</li>
</ul>
""".trimIndent()
}
Expand Down Expand Up @@ -111,7 +113,11 @@ intellijPlatform {
"2024.2",
"2024.2.0.1",
"2024.2.0.2",
"2024.2.1"
"2024.2.1",
"2024.2.2",
"2024.2.3",
"2024.2.4",
"2024.2.5"
))
Pakisan marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.intellij.json.JsonFileType
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.systemIndependentPath
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import io.netty.handler.codec.http.FullHttpRequest
import org.jetbrains.yaml.YAMLFileType
import java.io.File
import java.util.function.Supplier

/**
* @author Pavel Bodiachevskii
Expand Down Expand Up @@ -47,20 +44,19 @@ class AsyncAPISpecificationHtmlRenderer {

val isJson = specificationVirtualFile.fileType is JsonFileType
val specification = replaceLocalReferences(specificationFile.readText(Charsets.UTF_8), specificationVirtualFile, isJson)
val temporalSpecificationUrl = saveAsTemporalFile(specification, isJson)

val specificationTemplate = this.javaClass.getResource(specificationTemplateUrl)
specificationTemplate ?: return "specification template not found."

val webSocket = webSocketRendererProvider.provide(
fullHttpRequest = request,
supplier = Supplier<VirtualFile?> { specificationVirtualFile }
supplier = { specificationVirtualFile }
)

return specificationTemplate.readText(Charsets.UTF_8)
.replace(
"url: '',",
"url: '${urlProvider.specification(temporalSpecificationUrl)}',"
"schema: {},",
"schema: $specification,"
)
.replace(
"<link rel=\"stylesheet\" href=\"\">",
Expand All @@ -74,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 {
Expand All @@ -89,7 +85,7 @@ class AsyncAPISpecificationHtmlRenderer {
}
}

return objectMapper.writeValueAsString(tree)
return ObjectMapper().writeValueAsString(tree)
}

private fun localReferenceToFileUrl(localReference: String, specificationFile: VirtualFile): String {
Expand All @@ -104,17 +100,4 @@ class AsyncAPISpecificationHtmlRenderer {
return urlProvider.reference(referencedFile.path, specificationComponentReference)
}

private fun saveAsTemporalFile(specification: String, isJson: Boolean): String {
val suffix = if (isJson) {
".json"
} else {
".yaml"
}

val tempSpecification = FileUtil.createTempFile("jasyncapi-idea-plugin-${System.currentTimeMillis()}", suffix, true)
tempSpecification.writeText(specification, Charsets.UTF_8)

return tempSpecification.systemIndependentPath
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? {
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
<script src=""></script>
<script>
AsyncApiStandalone.render({
schema: {
url: '',
options: { method: "GET", mode: "cors" },
},
schema: {},
config: {
show: {
sidebar: true,
Expand Down
Loading