Skip to content

Commit

Permalink
feat: AsyncAPI 3.0.0 completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Dec 9, 2023
1 parent 6960dae commit 77f4916
Show file tree
Hide file tree
Showing 33 changed files with 444 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AsyncAPISpecificationRecognizer {

fun isSupported(version: String?): Boolean {
return when (version) {
"2.0.0", "2.1.0", "2.2.0", "2.3.0", "2.4.0", "2.5.0", "2.6.0" -> true
"2.0.0", "2.1.0", "2.2.0", "2.3.0", "2.4.0", "2.5.0", "2.6.0", "3.0.0" -> true
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.asyncapi.plugin.idea.completion
package com.asyncapi.plugin.idea.completion.v2

import com.intellij.codeInsight.completion.CompletionType
import com.intellij.testFramework.fixtures.BasePlatformTestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_0_0
package com.asyncapi.plugin.idea.completion.v2._0_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_0_0
package com.asyncapi.plugin.idea.completion.v2._0_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_1_0
package com.asyncapi.plugin.idea.completion.v2._1_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_1_0
package com.asyncapi.plugin.idea.completion.v2._1_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_2_0
package com.asyncapi.plugin.idea.completion.v2._2_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_2_0
package com.asyncapi.plugin.idea.completion.v2._2_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_3_0
package com.asyncapi.plugin.idea.completion.v2._3_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_3_0
package com.asyncapi.plugin.idea.completion.v2._3_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_4_0
package com.asyncapi.plugin.idea.completion.v2._4_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_4_0
package com.asyncapi.plugin.idea.completion.v2._4_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_5_0
package com.asyncapi.plugin.idea.completion.v2._5_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_5_0
package com.asyncapi.plugin.idea.completion.v2._5_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_6_0
package com.asyncapi.plugin.idea.completion.v2._6_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asyncapi.plugin.idea.completion.v2_6_0
package com.asyncapi.plugin.idea.completion.v2._6_0

import com.asyncapi.plugin.idea.completion.AbstractAsyncAPISpecificationCompletionContributorTest
import com.asyncapi.plugin.idea.completion.v2.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.asyncapi.plugin.idea.completion.v3

import com.intellij.codeInsight.completion.CompletionType
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import junit.framework.TestCase

/**
* @author Pavel Bodiachevskii
* @since 2.4.0
*/
abstract class AbstractAsyncAPISpecificationCompletionContributorTest: BasePlatformTestCase() {

abstract fun fileExtension(): String

abstract fun asyncAPIVersion(): String

override fun getTestDataPath(): String = "src/test/testData/${fileExtension()}/completion/${asyncAPIVersion()}"

protected open val `$ - c` = listOf(
"\"channels\"",
"\"components\"",
"\"defaultContentType\"",
)

protected open val `$ - components - messages - UserSignedUp - p` = listOf(
"\"contentType\"",
"\"deprecated\"",
"\"description\"",
"\"examples\""
)

protected open val `$ - info - i` = listOf(
"\"description\"",
"\"license\"",
"\"termsOfService\"",
"\"title\"",
"\"version\""
)

fun `test $ - (double quote)c(double quote)`() {
configureMyFixture("\"c\".${fileExtension()}")

/*
TODO: to research why completion returns more variants only in tests. In IDEA everything is ok:
expected: ["channels", "components", "defaultContentType", "externalDocs"]
actual: ["channels", "components", "defaultContentType", "externalDocs", "id", "info", "servers", "tags"]
*/
TestCase.assertTrue((myFixture.lookupElementStrings ?: emptyList<String>()).containsAll(`$ - c`))
}

fun `test $ - c`() {
configureMyFixture("c.${fileExtension()}")

TestCase.assertEquals(`$ - c`.sorted(), (myFixture.lookupElementStrings?.sorted() ?: emptyList<String>()))
}

fun `test $ - components - messages - UserSignedUp - (double quote)p(double quote)`() {
configureMyFixture("components -> messages -> UserSignedUp -> \"p\".${fileExtension()}")

/*
TODO: to research why completion returns more variants only in tests. In IDEA everything is ok:
expected: ["contentType", "deprecated", "description", "examples"]
actual: ["$ref", "bindings", "contentType", "correlationId", "deprecated", "description", "examples", "externalDocs", "headers", "name", "oneOf", "schemaFormat", "summary", "tags", "title", "traits"]
*/
TestCase.assertTrue(
(myFixture.lookupElementStrings ?: emptyList<String>())
.containsAll(`$ - components - messages - UserSignedUp - p`)
)
}

fun `test $ - components - messages - UserSignedUp - (double quote)p`() {
configureMyFixture("components -> messages -> UserSignedUp -> \"p.${fileExtension()}")

TestCase.assertEquals(
`$ - components - messages - UserSignedUp - p`.sorted().map { it.replace("\"", "") },
(myFixture.lookupElementStrings?.sorted() ?: emptyList<String>())
)
}

fun `test $ - components - messages - UserSignedUp - p`() {
configureMyFixture("components -> messages -> UserSignedUp -> p.${fileExtension()}")

TestCase.assertEquals(
`$ - components - messages - UserSignedUp - p`.sorted(),
(myFixture.lookupElementStrings?.sorted() ?: emptyList<String>())
)
}

fun `test $ - info - (double quote)i(double quote)`() {
configureMyFixture("info -> \"i\".${fileExtension()}")

/*
TODO: to research why completion returns more variants only in tests. In IDEA everything is ok:
expected: ["description", "license", "termsOfService", "title", "version"]
actual: ["contact", "description", "license", "termsOfService", "title", "version"]
*/
TestCase.assertTrue(
(myFixture.lookupElementStrings ?: emptyList<String>())
.containsAll(`$ - info - i`)
)
}

fun `test $ - info - i`() {
configureMyFixture("info -> i.${fileExtension()}")

TestCase.assertEquals(`$ - info - i`.sorted(), (myFixture.lookupElementStrings?.sorted() ?: emptyList<String>()))
}

private fun configureMyFixture(fileName: String) {
myFixture.configureByFile(fileName)
myFixture.complete(CompletionType.BASIC, 1)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.asyncapi.plugin.idea.completion.v3._0_0

import com.asyncapi.plugin.idea.completion.v3.AbstractAsyncAPISpecificationCompletionContributorTest

/**
* @author Pavel Bodiachevskii
* @since 2.4.0
*/
class AsyncAPISpecificationCompletionContributorJsonTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

override fun fileExtension(): String = "json"

override fun asyncAPIVersion(): String = "3.0.0"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.asyncapi.plugin.idea.completion.v3._0_0

import com.asyncapi.plugin.idea.completion.v3.AbstractAsyncAPISpecificationCompletionContributorTest

class AsyncAPISpecificationCompletionContributorYamlTest: AbstractAsyncAPISpecificationCompletionContributorTest() {

override fun fileExtension(): String = "yaml"

override fun asyncAPIVersion(): String = "3.0.0"

override val `$ - c` = super.`$ - c`.sorted().map { it.replace("\"", "") }

override val `$ - components - messages - UserSignedUp - p` = super.`$ - components - messages - UserSignedUp - p`.sorted().map { it.replace("\"", "") }

override val `$ - info - i` = super.`$ - info - i`.sorted().map { it.replace("\"", "") }

}
4 changes: 4 additions & 0 deletions src/test/testData/json/completion/3.0.0/"c".json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"asyncapi": "3.0.0",
"c"<caret>
}
4 changes: 4 additions & 0 deletions src/test/testData/json/completion/3.0.0/c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"asyncapi": "3.0.0",
c<caret>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"asyncapi": "3.0.0",
"info": {
"title": "Account Service",
"version": "1.0.0",
"description": "This service is in charge of processing user signups :rocket:"
},
"channels": {
"userSignedup": {
"address": "user/signedup",
"messages": {
"userSignedupMessage": {
"$ref": "#/components/messages/UserSignedUp"
}
}
}
},
"operations": {
"processUserSignups": {
"action": "receive",
"channel": {
"$ref": "#/channels/userSignedup"
}
}
},
"components": {
"messages": {
"UserSignedUp": {
"p"<caret>
"payload": {
"type": "object",
"properties": {
"displayName": {
"type": "string",
"description": "Name of the user"
},
"email": {
"type": "string",
"format": "email",
"description": "Email of the user"
}
}
}
}
}
}
}
Loading

0 comments on commit 77f4916

Please sign in to comment.