Skip to content

Commit efd5a2b

Browse files
fjtiradoCopilot
andauthored
[Fix #1323] OpenAPI module without Jackson dependency (#1330)
Update impl/openapi/src/main/java/io/serverlessworkflow/impl/executors/openapi/OpenAPIExecutor.java Update impl/pom.xml Update impl/README.md Signed-off-by: fjtirado <ftirados@redhat.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 03f3cfb commit efd5a2b

16 files changed

Lines changed: 347 additions & 49 deletions

File tree

api/src/main/java/io/serverlessworkflow/api/ObjectMapperFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ private static ObjectMapper configure(ObjectMapper mapper) {
5454
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
5555
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
5656
.registerModule(validationModule)
57-
.registerModule(new JacksonMixInModule());
57+
.registerModule(new JacksonMixInModule())
58+
.findAndRegisterModules();
5859
}
5960

6061
private ObjectMapperFactory() {}

impl/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ This SDK is modular by design—pull in only what you need:
102102
Optimized entity converter for Jackson model and OAuth2/OIDC helpers for HTTP calls.
103103

104104
* **serverlessworkflow-impl-openapi**
105-
OpenAPI support
105+
OpenAPI support using Jackson
106106

107+
* **serverlessworkflow-impl-openapi-base**
108+
Base OpenAPI support intended to be extended for a specific JSON library
109+
107110
* **serverlessworkflow-impl-grpc**
108111
gRPC support
109112

impl/openapi-jackson/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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>8.0.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>serverlessworkflow-impl-openapi</artifactId>
9+
<name>Serverless Workflow :: Impl :: OpenAPI:: Jackson</name>
10+
<dependencies>
11+
<dependency>
12+
<groupId>io.serverlessworkflow</groupId>
13+
<artifactId>serverlessworkflow-impl-openapi-base</artifactId>
14+
</dependency>
15+
<dependency>
16+
<groupId>io.serverlessworkflow</groupId>
17+
<artifactId>serverlessworkflow-api</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.serverlessworkflow</groupId>
21+
<artifactId>serverlessworkflow-impl-openapi-base</artifactId>
22+
<type>test-jar</type>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter-engine</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
</dependencies>
32+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.openapi.jackson;
17+
18+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
@JsonIgnoreProperties(ignoreUnknown = true)
24+
public class JacksonUnifiedOpenAPIMixIn {
25+
@JsonIgnoreProperties(ignoreUnknown = true)
26+
public class Server {}
27+
28+
@JsonIgnoreProperties(ignoreUnknown = true)
29+
public class RequestBody {}
30+
31+
@JsonIgnoreProperties(ignoreUnknown = true)
32+
public class Parameter {}
33+
34+
@JsonIgnoreProperties(ignoreUnknown = true)
35+
public class PathItem {}
36+
37+
@JsonIgnoreProperties(ignoreUnknown = true)
38+
public class HttpOperation {}
39+
40+
@JsonIgnoreProperties(ignoreUnknown = true)
41+
public class Operation {}
42+
43+
@JsonIgnoreProperties(ignoreUnknown = true)
44+
public class MediaType {}
45+
46+
@JsonIgnoreProperties(ignoreUnknown = true)
47+
public class Components {}
48+
49+
@JsonIgnoreProperties(ignoreUnknown = true)
50+
public record Content(@JsonProperty("application/json") MediaType applicationJson) {}
51+
52+
@JsonIgnoreProperties(ignoreUnknown = true)
53+
public record Schema(
54+
String type,
55+
Map<String, Schema> properties,
56+
List<String> required,
57+
@JsonProperty("$ref") String ref,
58+
@JsonProperty("default") Object _default) {}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.openapi.jackson;
17+
18+
import com.fasterxml.jackson.databind.module.SimpleModule;
19+
import io.serverlessworkflow.impl.executors.openapi.UnifiedOpenAPI;
20+
21+
public class JacksonUnifiedOpenAPIMixInModule extends SimpleModule {
22+
23+
private static final long serialVersionUID = 1L;
24+
25+
public void setupModule(SetupContext context) {
26+
setMixInAnnotation(UnifiedOpenAPI.class, JacksonUnifiedOpenAPIMixIn.class);
27+
setMixInAnnotation(
28+
UnifiedOpenAPI.Components.class, JacksonUnifiedOpenAPIMixIn.Components.class);
29+
setMixInAnnotation(UnifiedOpenAPI.Content.class, JacksonUnifiedOpenAPIMixIn.Content.class);
30+
setMixInAnnotation(UnifiedOpenAPI.MediaType.class, JacksonUnifiedOpenAPIMixIn.MediaType.class);
31+
setMixInAnnotation(UnifiedOpenAPI.Operation.class, JacksonUnifiedOpenAPIMixIn.Operation.class);
32+
setMixInAnnotation(
33+
UnifiedOpenAPI.HttpOperation.class, JacksonUnifiedOpenAPIMixIn.HttpOperation.class);
34+
setMixInAnnotation(UnifiedOpenAPI.Parameter.class, JacksonUnifiedOpenAPIMixIn.Parameter.class);
35+
setMixInAnnotation(UnifiedOpenAPI.PathItem.class, JacksonUnifiedOpenAPIMixIn.PathItem.class);
36+
setMixInAnnotation(
37+
UnifiedOpenAPI.RequestBody.class, JacksonUnifiedOpenAPIMixIn.RequestBody.class);
38+
setMixInAnnotation(UnifiedOpenAPI.Schema.class, JacksonUnifiedOpenAPIMixIn.Schema.class);
39+
setMixInAnnotation(UnifiedOpenAPI.Server.class, JacksonUnifiedOpenAPIMixIn.Server.class);
40+
super.setupModule(context);
41+
}
42+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.openapi.jackson;
17+
18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import io.serverlessworkflow.api.WorkflowFormat;
20+
import io.serverlessworkflow.impl.executors.openapi.UnifiedOpenAPI;
21+
import io.serverlessworkflow.impl.executors.openapi.UnifiedOpenAPIReader;
22+
import io.serverlessworkflow.impl.resources.ExternalResourceHandler;
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
26+
public class JacksonUnifiedOpenAPIReader implements UnifiedOpenAPIReader {
27+
28+
@Override
29+
public UnifiedOpenAPI read(ExternalResourceHandler handler) throws IOException {
30+
ObjectMapper objectMapper = WorkflowFormat.fromFileName(handler.name()).mapper();
31+
try (InputStream is = handler.open()) {
32+
return objectMapper.readValue(is, UnifiedOpenAPI.class);
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.openapi.jackson;
17+
18+
import io.serverlessworkflow.impl.TaskContextData;
19+
import io.serverlessworkflow.impl.WorkflowContextData;
20+
import io.serverlessworkflow.impl.additional.NamedWorkflowAdditionalObject;
21+
22+
public class JacksonUnifiedOpenAPIReaderFactory
23+
implements NamedWorkflowAdditionalObject<JacksonUnifiedOpenAPIReader> {
24+
25+
private static class JacksonUnifiedOpenAPIReaderHolder {
26+
private static JacksonUnifiedOpenAPIReader instance = new JacksonUnifiedOpenAPIReader();
27+
}
28+
29+
@Override
30+
public JacksonUnifiedOpenAPIReader apply(WorkflowContextData t, TaskContextData u) {
31+
return JacksonUnifiedOpenAPIReaderHolder.instance;
32+
}
33+
34+
@Override
35+
public String name() {
36+
return JacksonUnifiedOpenAPIReader.UNIFIED_OPEN_API_READER;
37+
}
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.serverlessworkflow.impl.executors.openapi.jackson.JacksonUnifiedOpenAPIMixInModule
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.serverlessworkflow.impl.executors.openapi.jackson.JacksonUnifiedOpenAPIReaderFactory
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.openapi.jackson;
17+
18+
import io.serverlessworkflow.impl.executors.openapi.OpenAPIProcessorTest;
19+
import io.serverlessworkflow.impl.executors.openapi.UnifiedOpenAPIReader;
20+
import org.junit.jupiter.api.BeforeAll;
21+
22+
public class JacksonOpenAPIProcessorTest extends OpenAPIProcessorTest {
23+
24+
private static JacksonUnifiedOpenAPIReader reader;
25+
26+
@BeforeAll
27+
static void init() {
28+
reader = new JacksonUnifiedOpenAPIReaderFactory().apply(null, null);
29+
}
30+
31+
@Override
32+
protected UnifiedOpenAPIReader getUnifiedOpenAPIReader() {
33+
return reader;
34+
}
35+
}

0 commit comments

Comments
 (0)