Skip to content

Commit 2983bdc

Browse files
committed
Add webhooks to model API
1 parent 46c6d3c commit 2983bdc

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.smallrye.openapi.api.models;
22

33
import java.util.ArrayList;
4+
import java.util.LinkedHashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
import org.eclipse.microprofile.openapi.models.Components;
79
import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
810
import org.eclipse.microprofile.openapi.models.OpenAPI;
11+
import org.eclipse.microprofile.openapi.models.PathItem;
912
import org.eclipse.microprofile.openapi.models.Paths;
1013
import org.eclipse.microprofile.openapi.models.info.Info;
1114
import org.eclipse.microprofile.openapi.models.security.SecurityRequirement;
@@ -26,6 +29,7 @@ public class OpenAPIImpl extends ExtensibleImpl<OpenAPI> implements OpenAPI, Mod
2629
private List<SecurityRequirement> security;
2730
private List<Tag> tags;
2831
private Paths paths;
32+
private Map<String, PathItem> webhooks;
2933
private Components components;
3034

3135
/**
@@ -226,4 +230,25 @@ public Components getComponents() {
226230
public void setComponents(Components components) {
227231
this.components = components;
228232
}
233+
234+
@Override
235+
public Map<String, PathItem> getWebhooks() {
236+
return ModelUtil.unmodifiableMap(this.webhooks);
237+
}
238+
239+
@Override
240+
public void setWebhooks(Map<String, PathItem> webhooks) {
241+
this.webhooks = ModelUtil.replace(webhooks, LinkedHashMap<String, PathItem>::new);
242+
}
243+
244+
@Override
245+
public OpenAPI addWebhook(String name, PathItem webhook) {
246+
this.webhooks = ModelUtil.add(name, webhook, this.webhooks, LinkedHashMap<String, PathItem>::new);
247+
return this;
248+
}
249+
250+
@Override
251+
public void removeWebhook(String name) {
252+
ModelUtil.remove(this.webhooks, name);
253+
}
229254
}

core/src/main/java/io/smallrye/openapi/runtime/io/OpenAPIDefinitionIO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class OpenAPIDefinitionIO<V, A extends V, O extends V, AB, OB> extends Mo
1919
public static final String PROP_SECURITY_SETS = "securitySets";
2020
public static final String PROP_SERVERS = "servers";
2121
public static final String PROP_TAGS = "tags";
22+
public static final String PROP_WEBHOOKS = "webhooks";
2223

2324
public OpenAPIDefinitionIO(IOContext<V, A, O, AB, OB> context) {
2425
super(context, Names.OPENAPI_DEFINITION, Names.create(OpenAPI.class));
@@ -60,6 +61,7 @@ public OpenAPI readObject(O node) {
6061
openApi.setExternalDocs(extDocIO().readValue(jsonIO().getValue(node, PROP_EXTERNAL_DOCS)));
6162
openApi.setComponents(componentsIO().readValue(jsonIO().getValue(node, PROP_COMPONENTS)));
6263
openApi.setPaths(pathsIO().readValue(jsonIO().getValue(node, PROP_PATHS)));
64+
openApi.setWebhooks(pathItemIO().readMap(jsonIO().getValue(node, PROP_WEBHOOKS)));
6365
openApi.setExtensions(extensionIO().readMap(node));
6466
return openApi;
6567
}
@@ -74,6 +76,7 @@ public Optional<O> write(OpenAPI model) {
7476
setIfPresent(node, PROP_SECURITY, securityIO().write(model.getSecurity()));
7577
setIfPresent(node, PROP_TAGS, tagIO().write(model.getTags()));
7678
setIfPresent(node, PROP_PATHS, pathsIO().write(model.getPaths()));
79+
setIfPresent(node, PROP_WEBHOOKS, pathItemIO().write(model.getWebhooks()));
7780
setIfPresent(node, PROP_COMPONENTS, componentsIO().write(model.getComponents()));
7881
setAllIfPresent(node, extensionIO().write(model));
7982
return node;

core/src/main/java/io/smallrye/openapi/runtime/io/PathItemIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import io.smallrye.openapi.api.models.PathItemImpl;
1616

17-
public class PathItemIO<V, A extends V, O extends V, AB, OB> extends ModelIO<PathItem, V, A, O, AB, OB>
17+
public class PathItemIO<V, A extends V, O extends V, AB, OB> extends MapModelIO<PathItem, V, A, O, AB, OB>
1818
implements ReferenceIO<V, A, O, AB, OB> {
1919

2020
private static final String PROP_DESCRIPTION = "description";

0 commit comments

Comments
 (0)