Skip to content

Commit 03543dd

Browse files
committed
Add initial openapi module
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 9087cb9 commit 03543dd

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

impl/openapi/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>io.serverlessworkflow</groupId>
5+
<artifactId>serverlessworkflow-impl</artifactId>
6+
<version>7.0.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>serverlessworkflow-impl-openapi</artifactId>
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.glassfish.jersey.core</groupId>
12+
<artifactId>jersey-client</artifactId>
13+
</dependency>
14+
<dependency>
15+
<groupId>org.glassfish.jersey.media</groupId>
16+
<artifactId>jersey-media-json-jackson</artifactId>
17+
</dependency>
18+
<dependency>
19+
<groupId>io.serverlessworkflow</groupId>
20+
<artifactId>serverlessworkflow-impl-core</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.junit.jupiter</groupId>
24+
<artifactId>junit-jupiter-api</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.junit.jupiter</groupId>
29+
<artifactId>junit-jupiter-engine</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.junit.jupiter</groupId>
34+
<artifactId>junit-jupiter-params</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.assertj</groupId>
39+
<artifactId>assertj-core</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.executors;
17+
18+
import com.fasterxml.jackson.databind.JsonNode;
19+
import io.serverlessworkflow.api.types.CallOpenAPI;
20+
import io.serverlessworkflow.api.types.TaskBase;
21+
import io.serverlessworkflow.impl.TaskContext;
22+
import io.serverlessworkflow.impl.WorkflowContext;
23+
import io.serverlessworkflow.impl.WorkflowDefinition;
24+
25+
public class OpenAPIExecutor implements CallableTask<CallOpenAPI> {
26+
27+
@Override
28+
public void init(CallOpenAPI task, WorkflowDefinition definition) {}
29+
30+
@Override
31+
public JsonNode apply(
32+
WorkflowContext workflowContext, TaskContext<CallOpenAPI> taskContext, JsonNode input) {
33+
return input;
34+
}
35+
36+
@Override
37+
public boolean accept(Class<? extends TaskBase> clazz) {
38+
return clazz.isAssignableFrom(CallOpenAPI.class);
39+
}
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.serverlessworkflow.impl.executors.OpenAPIExecutor
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
19+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
20+
21+
import com.fasterxml.jackson.databind.JsonNode;
22+
import java.io.IOException;
23+
import java.util.Map;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.Test;
26+
27+
public class OpenAPIWorkflowDefinitionTest {
28+
29+
private static WorkflowApplication app;
30+
31+
@BeforeAll
32+
static void init() {
33+
app = WorkflowApplication.builder().build();
34+
}
35+
36+
@Test
37+
void testWorkflowExecution() throws IOException {
38+
Object output =
39+
app.workflowDefinition(readWorkflowFromClasspath("findPetsByStatus.yaml"))
40+
.execute(Map.of("status", "sold"))
41+
.outputAsJsonNode();
42+
assertThat(output)
43+
.isInstanceOf(JsonNode.class)
44+
.satisfies(
45+
(obj) -> {
46+
JsonNode json = (JsonNode) obj;
47+
assertThat(json.get("status").asText()).isEqualTo("sold");
48+
});
49+
}
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: test
4+
name: openapi-example
5+
version: '0.1.0'
6+
do:
7+
- findPet:
8+
call: openapi
9+
with:
10+
document:
11+
endpoint: https://petstore.swagger.io/v2/swagger.json
12+
operationId: findPetsByStatus
13+
parameters:
14+
status: available

impl/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
<module>http</module>
3939
<module>core</module>
4040
<module>bom</module>
41+
<module>openapi</module>
4142
</modules>
4243
</project>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy