diff --git a/components/openapi/src/it/resources/enrichers-with-optional-fields.yaml b/components/openapi/src/it/resources/enrichers-with-optional-fields.yaml new file mode 100644 index 00000000000..50bb27252db --- /dev/null +++ b/components/openapi/src/it/resources/enrichers-with-optional-fields.yaml @@ -0,0 +1,54 @@ +openapi: "3.0.0" +info: + title: Simple API overview + version: 2.0.0 +paths: + /customer: + post: + summary: Returns ComponentsBykeys. + requestBody: + description: + Keys of the Customers. + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/MultiKeys' + responses: + '201': + description: + OK + content: + application/json: + schema: + $ref: '#/components/schemas/Customer' + +components: + schemas: + MultiKeys: + type: array + minItems: 1 + items: + type: object + properties: + primaryKey: + type: string + additionalKey: + type: string + validFor: + type: integer + format: int64 + minimum: 1 + maximum: 2592000 + required: + - primaryKey + - additionalKey + Customer: + type: object + properties: + name: + type: string + category: + type: string + id: + type: integer diff --git a/components/openapi/src/it/scala/pl/touk/nussknacker/openapi/functional/OpenApiScenarioIntegrationTest.scala b/components/openapi/src/it/scala/pl/touk/nussknacker/openapi/functional/OpenApiScenarioIntegrationTest.scala index fd2671fdab0..0e8290c1789 100644 --- a/components/openapi/src/it/scala/pl/touk/nussknacker/openapi/functional/OpenApiScenarioIntegrationTest.scala +++ b/components/openapi/src/it/scala/pl/touk/nussknacker/openapi/functional/OpenApiScenarioIntegrationTest.scala @@ -12,6 +12,7 @@ import pl.touk.nussknacker.engine.api.typed.TypedMap import pl.touk.nussknacker.engine.build.ScenarioBuilder import pl.touk.nussknacker.engine.flink.test.FlinkSpec import pl.touk.nussknacker.engine.graph.expression.Expression +import pl.touk.nussknacker.engine.spel import pl.touk.nussknacker.engine.util.test.{ClassBasedTestScenarioRunner, RunResult, TestScenarioRunner} import pl.touk.nussknacker.openapi.enrichers.SwaggerEnricher import pl.touk.nussknacker.openapi.parser.SwaggerParser @@ -53,6 +54,11 @@ class OpenApiScenarioIntegrationTest test(prepareScenarioRunner(port, sttpBackend, _.copy(allowedMethods = List("POST")))) } + def withRequestBody(sttpBackend: SttpBackend[Future, Any])(test: ClassBasedTestScenarioRunner => Any) = + new StubService("/enrichers-with-optional-fields.yaml").withCustomerService { port => + test(prepareScenarioRunner(port, sttpBackend, _.copy(allowedMethods = List("POST")))) + } + val stubbedBackend: SttpBackendStub[Future, Any] = SttpBackendStub.asynchronousFuture.whenRequestMatchesPartial { case request => request.headers match { @@ -93,6 +99,21 @@ class OpenApiScenarioIntegrationTest ) } + it should "call enricher with request body" in withRequestBody(stubbedBackend) { testScenarioRunner => + // given + val data = List("10") + val scenario = + scenarioWithEnricher((SingleBodyParameter.name, """{{additionalKey:"sss", primaryKey:"dfgdf"}}""".spel)) + + // when + val result = testScenarioRunner.runWithData(scenario, data) + + // then + result.validValue shouldBe RunResult.success( + TypedMap(Map("name" -> "Robert Wright", "id" -> 10L, "category" -> "GOLD")) + ) + } + it should "call enricher returning string" in withPrimitiveReturnType( SttpBackendStub.asynchronousFuture.whenRequestMatchesPartial { case _ => Response.ok((s""""justAString""""))