@devkong/cli-nx 0.0.67-alpha.15 → 0.0.67-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/generators/preset/files/kotlin/gradle.properties +1 -1
- package/src/generators/preset/files/kotlin/settings.gradle.kts +2 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/InputData.kt +0 -8
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/Main.kt +0 -5
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/OutputData.kt +0 -2
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/{RegisterKongFrontend.kt → RegisterFrontend.kt} +1 -1
- package/src/generators/preset/files/kotlin/src/test/kotlin/io/kong/extension/Test.kt +1 -16
- package/src/generators/preset/files/python/src/input_data.py +0 -7
- package/src/generators/preset/files/python/src/main.py +0 -9
- package/src/generators/preset/files/python/src/main_test.py +0 -2
- package/src/generators/preset/files/python/src/output_data.py +0 -4
package/package.json
CHANGED
|
@@ -2,11 +2,13 @@ pluginManagement {
|
|
|
2
2
|
val quarkusVersion: String by settings
|
|
3
3
|
val kotlinVersion: String by settings
|
|
4
4
|
val nxGradleVersion: String by settings
|
|
5
|
+
val jlleitschuhGradlePluginVersion: String by settings
|
|
5
6
|
|
|
6
7
|
plugins {
|
|
7
8
|
id("org.jetbrains.kotlin.jvm") version kotlinVersion
|
|
8
9
|
id("org.jetbrains.kotlin.plugin.allopen") version kotlinVersion
|
|
9
10
|
id("dev.nx.gradle.project-graph") version nxGradleVersion
|
|
10
11
|
id("io.quarkus") version quarkusVersion
|
|
12
|
+
id("org.jlleitschuh.gradle.ktlint") version jlleitschuhGradlePluginVersion
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -5,14 +5,6 @@ import io.kong.sdk.KongFunctionRequest
|
|
|
5
5
|
import io.kong.sdk.function.template.Field
|
|
6
6
|
import io.quarkus.runtime.annotations.RegisterForReflection
|
|
7
7
|
|
|
8
|
-
// Define the structure of the input data that your extension will accept.
|
|
9
|
-
// Be sure to include example values for each field. These examples help generate
|
|
10
|
-
// sample objects in the UI, making it easier to work with the models.
|
|
11
|
-
//
|
|
12
|
-
// InputData implements KongFunctionContract: `request.operation` selects which
|
|
13
|
-
// calculation Main.handle runs, and the operand payload for that operation
|
|
14
|
-
// (`sum`, `sub`, `multiply` or `divide`) is the one it reads.
|
|
15
|
-
|
|
16
8
|
@RegisterForReflection
|
|
17
9
|
data class OperationData(
|
|
18
10
|
@Field(description = "An integer number", examples = ["1"]) val a: Int,
|
|
@@ -7,9 +7,6 @@ import io.kong.sdk.KongFunctionContext
|
|
|
7
7
|
import jakarta.inject.Inject
|
|
8
8
|
import jakarta.inject.Singleton
|
|
9
9
|
|
|
10
|
-
// This is the main entry point for developing an extension for Kong.
|
|
11
|
-
// For more details, please refer to the README.md file.
|
|
12
|
-
|
|
13
10
|
@Singleton
|
|
14
11
|
class Main : KongFunction<InputData>(InputData::class.java) {
|
|
15
12
|
private val logger = AppLogger(Main::class.simpleName)
|
|
@@ -21,8 +18,6 @@ class Main : KongFunction<InputData>(InputData::class.java) {
|
|
|
21
18
|
data: InputData,
|
|
22
19
|
context: KongFunctionContext,
|
|
23
20
|
): ByteArray? {
|
|
24
|
-
// `request.operation` comes from the KongFunctionContract the input implements;
|
|
25
|
-
// branch on it and read the matching operand payload.
|
|
26
21
|
val operation = data.request.operation
|
|
27
22
|
|
|
28
23
|
logger.info("handle operation") {
|
|
@@ -3,10 +3,8 @@ package io.kong.extension
|
|
|
3
3
|
import io.kong.sdk.function.template.Field
|
|
4
4
|
import io.quarkus.runtime.annotations.RegisterForReflection
|
|
5
5
|
|
|
6
|
-
// Define the structure of the output data that your extension will return.
|
|
7
6
|
@RegisterForReflection
|
|
8
7
|
data class OutputData(
|
|
9
|
-
// REPLACE BELLOW WITH YOUR FIELDS
|
|
10
8
|
@Field(description = "Result of applying the operation to a and b", examples = ["3"])
|
|
11
9
|
val result: Int,
|
|
12
10
|
@Field(
|
|
@@ -28,7 +28,7 @@ class Test {
|
|
|
28
28
|
runTest {
|
|
29
29
|
val input =
|
|
30
30
|
InputData(
|
|
31
|
-
request = KongFunctionRequest(operation = "sum"
|
|
31
|
+
request = KongFunctionRequest(operation = "sum"),
|
|
32
32
|
sum = OperationData(a = 1, b = 2),
|
|
33
33
|
)
|
|
34
34
|
|
|
@@ -37,19 +37,4 @@ class Test {
|
|
|
37
37
|
|
|
38
38
|
assertEquals(3, output.result)
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
@Test
|
|
42
|
-
fun `when operation is multiply then returns the product`() =
|
|
43
|
-
runTest {
|
|
44
|
-
val input =
|
|
45
|
-
InputData(
|
|
46
|
-
request = KongFunctionRequest(operation = "multiply", form = null),
|
|
47
|
-
multiply = OperationData(a = 4, b = 5),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
val bytes = extension.handle(input, testContext.create())
|
|
51
|
-
val output = jsonMapper.readValue(bytes, OutputData::class.java)
|
|
52
|
-
|
|
53
|
-
assertEquals(20, output.result)
|
|
54
|
-
}
|
|
55
40
|
}
|
|
@@ -2,13 +2,6 @@ from pydantic import BaseModel, Field
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class InputData(BaseModel):
|
|
5
|
-
# Define the structure of the input data that your extension will accept.
|
|
6
|
-
# Be sure to include example values for each field. These examples help generate
|
|
7
|
-
# sample objects in the UI, making it easier to work with the models.
|
|
8
|
-
# For more standard types, refer to: https://docs.pydantic.dev/latest/concepts/types/
|
|
9
|
-
|
|
10
|
-
# REPLACE BELLOW WITH YOUR FIELDS
|
|
11
|
-
|
|
12
5
|
a: int = Field(
|
|
13
6
|
examples=[1],
|
|
14
7
|
description="An integer number",
|
|
@@ -8,18 +8,9 @@ from frontend import frontend
|
|
|
8
8
|
from input_data import InputData
|
|
9
9
|
from output_data import OutputData
|
|
10
10
|
|
|
11
|
-
# This script is for developing an extension for Kong.
|
|
12
|
-
# For more details, please refer to the README.md file.
|
|
13
|
-
|
|
14
11
|
|
|
15
12
|
class Main(KongFunction):
|
|
16
|
-
# This is where you implement the logic to handle the input data
|
|
17
|
-
# and produce the output.
|
|
18
|
-
|
|
19
|
-
# OVERRIDE BELLOW TO CUSTOMIZE THE PROCESSING.
|
|
20
|
-
|
|
21
13
|
async def handle(self, data: InputData, context: KongFunctionContext) -> OutputData:
|
|
22
|
-
# `context.secret.get("<purpose>")` resolves secrets declared in frontend.py.
|
|
23
14
|
return OutputData(
|
|
24
15
|
sum_of=data.a + data.b,
|
|
25
16
|
comment=f"sum of {data.a} and {data.b}",
|
|
@@ -5,13 +5,11 @@ from input_data import InputData
|
|
|
5
5
|
from main import Main
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
# The test function to validate the behavior of the extension
|
|
9
8
|
async def test_should_return_value_from_string_field_when_input_is_provided(
|
|
10
9
|
create_extension: ExtensionFixture,
|
|
11
10
|
):
|
|
12
11
|
extension = create_extension(Main, InputData)
|
|
13
12
|
|
|
14
|
-
# Prepare the input data
|
|
15
13
|
input_data = InputData(
|
|
16
14
|
a=1,
|
|
17
15
|
b=2,
|
|
@@ -4,10 +4,6 @@ from pydantic import BaseModel, Field
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class OutputData(BaseModel):
|
|
7
|
-
# Define the structure of the output data that your extension will return.
|
|
8
|
-
|
|
9
|
-
# REPLACE BELLOW WITH YOUR FIELDS
|
|
10
|
-
|
|
11
7
|
sum_of: int = Field(
|
|
12
8
|
examples=[3],
|
|
13
9
|
description="Result of a + b",
|