-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
59 additions
and
50 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
.../main/java/community/flock/wirespec/examples/spring_boot_integration/TodoApplication.java
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 was deleted.
Oops, something went wrong.
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
7 changes: 5 additions & 2 deletions
7
...jvmMain/kotlin/community/flock/wirespec/integration/spring/java/emit/SpringJavaEmitter.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 |
---|---|---|
@@ -1,19 +1,22 @@ | ||
package community.flock.wirespec.integration.spring.java.emit | ||
|
||
import community.flock.wirespec.compiler.core.emit.JavaEmitter | ||
import community.flock.wirespec.compiler.core.emit.transformer.EndpointClass | ||
import community.flock.wirespec.compiler.core.parse.Endpoint | ||
import community.flock.wirespec.compiler.utils.Logger | ||
|
||
class SpringJavaEmitter(packageName: String, logger: Logger) : JavaEmitter(packageName, logger) { | ||
override fun emitHandleFunction(endpoint: Endpoint): String { | ||
val path = "/${endpoint.path.joinToString("/") { it.emit() }}" | ||
return when (endpoint.method) { | ||
val annotation = when (endpoint.method) { | ||
Endpoint.Method.GET -> "@org.springframework.web.bind.annotation.GetMapping(\"${path}\")\n" | ||
Endpoint.Method.POST -> "@org.springframework.web.bind.annotation.PostMapping(\"${path}\")\n" | ||
Endpoint.Method.PUT -> "@org.springframework.web.bind.annotation.PutMapping(\"${path}\")\n" | ||
Endpoint.Method.DELETE -> "@org.springframework.web.bind.annotation.DeleteMapping(\"${path}\")\n" | ||
else -> error("Method not implemented: ${endpoint.method}") | ||
} | ||
return """ | ||
|${annotation} | ||
|${super.emitHandleFunction(endpoint)} | ||
""".trimMargin() | ||
} | ||
} |
18 changes: 11 additions & 7 deletions
18
...community/flock/wirespec/integration/spring/kotlin/configuration/WirespecConfiguration.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 |
---|---|---|
@@ -1,31 +1,35 @@ | ||
package community.flock.wirespec.integration.spring.kotlin.configuration | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import community.flock.wirespec.integration.jackson.java.WirespecModuleJava | ||
import community.flock.wirespec.integration.jackson.kotlin.WirespecModuleKotlin | ||
import community.flock.wirespec.integration.spring.kotlin.web.WirespecResponseBodyAdvice | ||
import community.flock.wirespec.java.Wirespec | ||
import community.flock.wirespec.kotlin.Wirespec | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Import | ||
import java.lang.reflect.Type | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.javaType | ||
|
||
@Configuration | ||
@Import(WirespecResponseBodyAdvice::class, WirespecWebMvcConfiguration::class) | ||
@OptIn(ExperimentalStdlibApi::class) | ||
open class WirespecConfiguration { | ||
|
||
@Bean | ||
open fun wirespecSerialization(objectMapper: ObjectMapper) = object : Wirespec.Serialization<String> { | ||
|
||
private val wirespecObjectMapper = objectMapper.copy().registerModule(WirespecModuleJava()) | ||
private val wirespecObjectMapper = objectMapper.copy().registerModule(WirespecModuleKotlin()) | ||
|
||
override fun <T : Any?> serialize(body: T, type: Type?): String { | ||
override fun <T> serialize(body: T, kType: KType): String { | ||
return wirespecObjectMapper.writeValueAsString(body) | ||
} | ||
|
||
override fun <T : Any?> deserialize(raw: String?, valueType: Type?): T { | ||
val type = wirespecObjectMapper.constructType(valueType) | ||
override fun <T> deserialize(raw: String, kType: KType): T { | ||
val type = wirespecObjectMapper.constructType(kType.javaType) | ||
val obj: T = wirespecObjectMapper.readValue(raw, type) | ||
return obj | ||
} | ||
|
||
|
||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ity/flock/wirespec/integration/spring/kotlin/configuration/WirespecWebMvcConfiguration.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
11 changes: 2 additions & 9 deletions
11
.../community/flock/wirespec/integration/spring/kotlin/web/WirespecMethodArgumentResolver.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
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