-
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 7 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
5 changes: 5 additions & 0 deletions
5
...-annotation/src/main/kotlin/org/openfolder/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 org.openfolder.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
30 changes: 30 additions & 0 deletions
30
.../org/openfolder/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,30 @@ | ||
package org.openfolder.kotlinasyncapi.context.annotation.processor | ||
|
||
import org.openfolder.kotlinasyncapi.annotation.AsyncApiComponent | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Channel | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Publish | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Subscribe | ||
import org.openfolder.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 -> | ||
currentFunction.findAnnotation<Channel>()!!.toChannel() | ||
.apply { | ||
subscribe = subscribe ?: currentFunction.findAnnotation<Subscribe>()?.toOperation() | ||
publish = publish ?: currentFunction.findAnnotation<Publish>()?.toOperation() | ||
} | ||
.also { | ||
put(currentFunction.name, it) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
.../openfolder/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 org.openfolder.kotlinasyncapi.context.annotation.processor | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.openfolder.kotlinasyncapi.annotation.AsyncApiComponent | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Channel | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Message | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Parameter | ||
import org.openfolder.kotlinasyncapi.annotation.channel.SecurityRequirement | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Subscribe | ||
import org.openfolder.kotlinasyncapi.context.TestUtils.assertJsonEquals | ||
import org.openfolder.kotlinasyncapi.context.TestUtils.json | ||
import kotlin.reflect.full.findAnnotation | ||
|
||
internal class AsyncApiComponentProcessorTest { | ||
|
||
private val processor = AsyncApiComponentProcessor() | ||
|
||
@Test | ||
fun `should process async api documentation annotation on class`() { | ||
val payload = TestChannelFunction::class | ||
val annotation = payload.findAnnotation<AsyncApiComponent>()!! | ||
|
||
val expected = json("annotation/async_api_documentation_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_documentation_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" : { | ||
"testSubscribe" : { | ||
"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
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.
sorry, there is actually still something missing: you see that componentToChannelMapping above? you have to add the the channels you find in the class to this map. because it is used to bind the channel components to the actual channel top level object. not sure if that makes sense. but currently you would only add the channels under components.channels but you also want them in asyncapi.channels.
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.
@lorenzsimon - Ok. I wasn't sure what the purpose of that map was. I will add it.
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.
Updated.
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.
AsyncApiComponent
annotation does not need the value property. You need to map the value of the channel annotation itself. In your example,some/{parameter}/channel
should be the name of the channel. And this is what the bind method is doing. It checks what the value property is, uses this as the name of the channel and then references the channel component based on the class name (or the function name in your case).I think we should add it to the spring integration test:
kotlin-asyncapi/kotlin-asyncapi-spring-web/src/test/kotlin/org/openfolder/kotlinasyncapi/springweb/controller/AsyncApiControllerIntegrationTest.kt
Line 177 in df0aa85
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.
@lorenzsimon - AsyncApiComponent is the class though not the function, we changed the behavior at your request. There can be multiple channels inside an AsyncApiComponent so you want me to replicate that logic to populate this map?
Something like this (which doesn't work):
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.
Ok. Looking at the integration test was the clue I needed to find the issues with my implementation. This should be resolved now.