-
Notifications
You must be signed in to change notification settings - Fork 2
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: create new annotation for classes that allows you to have multiple channels within #76
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cf25fe0
allow annotation to target function also.
7bb9a5b
add support for channel on functions instead of just classes.
c45fba1
Merge branch 'cbaz/new-build' into azizabah/add-channel
e6c5479
split into a separate processor with new annotation to handle finding…
f85697d
match previous white space
1a2a12f
name updates per PR comments.
2d97e67
fix annotation location
6e158c4
add AsyncApiComponent population of channel map behavior to match Cha…
eaf536d
chore: move domain (#77)
lorenzsimon 2a168e5
chore: Update repositories
lorenzsimon 7a428bd
change how the map is populated for channels found via AsyncApiCompon…
6340f6b
Update CODEOWNERS
lorenzsimon fe761cd
chore: Update pom.xml
lorenzsimon 123efad
Update CODEOWNERS
lorenzsimon bc83ab4
changes per PR requests.
89a93dc
Merge branch 'master' into azizabah/add-channel
ca2c5d0
updates to handle merge conflicts.
ddd398b
Merge branch 'dev' into azizabah/add-channel
azizabah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Default owners | ||
* @lorenzsimon @sueskind @gimlet2 | ||
* @lorenzsimon @gimlet2 @asyncapi-bot-eve |
5 changes: 5 additions & 0 deletions
5
...pi-annotation/src/main/kotlin/com/asyncapi/kotlinasyncapi/annotation/AsyncApiComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.asyncapi.kotlinasyncapi.annotation | ||
|
||
@Target(AnnotationTarget.CLASS) | ||
@AsyncApiAnnotation | ||
annotation class AsyncApiComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...in/com/asyncapi/kotlinasyncapi/context/annotation/processor/AsyncApiComponentProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.asyncapi.kotlinasyncapi.context.annotation.processor | ||
|
||
import com.asyncapi.kotlinasyncapi.annotation.AsyncApiComponent | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Channel | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Publish | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Subscribe | ||
import com.asyncapi.kotlinasyncapi.model.component.Components | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.full.findAnnotation | ||
import kotlin.reflect.full.functions | ||
import kotlin.reflect.full.hasAnnotation | ||
|
||
class AsyncApiComponentProcessor : AnnotationProcessor<AsyncApiComponent, KClass<*>> { | ||
override fun process(annotation: AsyncApiComponent, context: KClass<*>): Components { | ||
return Components().apply { | ||
channels { | ||
context.functions.filter { it.hasAnnotation<Channel>() }.forEach { currentFunction -> | ||
var currentAnnotation = currentFunction.findAnnotation<Channel>()!! | ||
currentAnnotation.toChannel() | ||
.apply { | ||
subscribe = subscribe ?: currentFunction.findAnnotation<Subscribe>()?.toOperation() | ||
publish = publish ?: currentFunction.findAnnotation<Publish>()?.toOperation() | ||
} | ||
.also { | ||
put(currentAnnotation.value, it) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...om/asyncapi/kotlinasyncapi/context/annotation/processor/AsyncApiComponentProcessorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.asyncapi.kotlinasyncapi.context.annotation.processor | ||
|
||
import org.junit.jupiter.api.Test | ||
import com.asyncapi.kotlinasyncapi.annotation.AsyncApiComponent | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Channel | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Message | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Parameter | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.SecurityRequirement | ||
import com.asyncapi.kotlinasyncapi.annotation.channel.Subscribe | ||
import com.asyncapi.kotlinasyncapi.context.TestUtils.assertJsonEquals | ||
import com.asyncapi.kotlinasyncapi.context.TestUtils.json | ||
import kotlin.reflect.full.findAnnotation | ||
|
||
internal class AsyncApiComponentProcessorTest { | ||
|
||
private val processor = AsyncApiComponentProcessor() | ||
|
||
@Test | ||
fun `should process async api component annotation on class`() { | ||
val payload = TestChannelFunction::class | ||
val annotation = payload.findAnnotation<AsyncApiComponent>()!! | ||
|
||
val expected = json("annotation/async_api_component.json") | ||
val actual = json(processor.process(annotation, payload)) | ||
|
||
assertJsonEquals(expected, actual) | ||
} | ||
|
||
|
||
@AsyncApiComponent | ||
class TestChannelFunction { | ||
@Channel( | ||
value = "some/{parameter}/channel", | ||
description = "testDescription", | ||
servers = ["dev"], | ||
parameters = [ | ||
Parameter( | ||
value = "parameter", | ||
description = "testDescription" | ||
) | ||
] | ||
) | ||
@Subscribe( | ||
operationId = "testOperationId", | ||
security = [ | ||
SecurityRequirement( | ||
key = "petstore_auth", | ||
values = ["write:pets", "read:pets"] | ||
) | ||
], | ||
message = Message(TestSubscribeMessage::class) | ||
) | ||
fun testSubscribe() {} | ||
} | ||
|
||
@Message | ||
data class TestSubscribeMessage( | ||
val id: Int = 0, | ||
val name: String, | ||
val isTest: Boolean | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
kotlin-asyncapi-context/src/test/resources/annotation/async_api_component.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"channels" : { | ||
"some/{parameter}/channel" : { | ||
"description" : "testDescription", | ||
"servers" : [ "dev" ], | ||
"subscribe" : { | ||
"operationId" : "testOperationId", | ||
"security" : [ { | ||
"petstore_auth" : [ "write:pets", "read:pets" ] | ||
} ], | ||
"message" : { | ||
"$ref" : "#/components/messages/TestSubscribeMessage" | ||
} | ||
}, | ||
"parameters" : { | ||
"parameter" : { | ||
"description" : "testDescription" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...in-asyncapi-spring-web/src/test/resources/async_api_component_annotation_integration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"asyncapi": "2.4.0", | ||
"info": { | ||
"title": "testTitle", | ||
"version": "testVersion" | ||
}, | ||
"channels": { | ||
"my/channel": { | ||
"$ref": "#/components/channels/TestChannel" | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"TestMessage": { | ||
"required": [ | ||
"value" | ||
], | ||
"type": "object", | ||
"properties": { | ||
"value": { | ||
"type": "string", | ||
"exampleSetFlag": false, | ||
"types": [ | ||
"string" | ||
] | ||
}, | ||
"optionalValue": { | ||
"type": "boolean", | ||
"exampleSetFlag": false, | ||
"types": [ | ||
"boolean" | ||
] | ||
} | ||
}, | ||
"exampleSetFlag": false | ||
} | ||
}, | ||
"channels": { | ||
"my/channel": { | ||
"publish": { | ||
"description": "testDescription", | ||
"message": { | ||
"$ref": "#/components/messages/TestMessage" | ||
} | ||
} | ||
} | ||
}, | ||
"messages": { | ||
"TestMessage": { | ||
"payload": { | ||
"$ref": "#/components/schemas/TestMessage" | ||
}, | ||
"schemaFormat": "application/schema+json;version=draft-07" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
TestChannel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - in places where the channel is inside a class, it should be the value of the annotation not the name of the class. https://github.com/azizabah/kotlin-asyncapi/blob/bc83ab4f5825d56f7741f126fce481bad57e8c6b/kotlin-asyncapi-spring-web/src/test/kotlin/org/openfolder/kotlinasyncapi/springweb/controller/AsyncApiControllerIntegrationTest.kt#L251
If you do it as the value of the class, you will run into conflicts when you have multiple inside the same class which is the exact functionality this entire PR is about.