Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement webhooks model #1836

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.smallrye.openapi.api.models;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.eclipse.microprofile.openapi.models.PathItem;
import org.eclipse.microprofile.openapi.models.Paths;
import org.eclipse.microprofile.openapi.models.info.Info;
import org.eclipse.microprofile.openapi.models.security.SecurityRequirement;
Expand All @@ -26,6 +29,7 @@ public class OpenAPIImpl extends ExtensibleImpl<OpenAPI> implements OpenAPI, Mod
private List<SecurityRequirement> security;
private List<Tag> tags;
private Paths paths;
private Map<String, PathItem> webhooks;
private Components components;

/**
Expand Down Expand Up @@ -226,4 +230,25 @@ public Components getComponents() {
public void setComponents(Components components) {
this.components = components;
}

@Override
public Map<String, PathItem> getWebhooks() {
return ModelUtil.unmodifiableMap(this.webhooks);
}

@Override
public void setWebhooks(Map<String, PathItem> webhooks) {
this.webhooks = ModelUtil.replace(webhooks, LinkedHashMap<String, PathItem>::new);
}

@Override
public OpenAPI addWebhook(String name, PathItem webhook) {
this.webhooks = ModelUtil.add(name, webhook, this.webhooks, LinkedHashMap<String, PathItem>::new);
return this;
}

@Override
public void removeWebhook(String name) {
ModelUtil.remove(this.webhooks, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class OpenAPIDefinitionIO<V, A extends V, O extends V, AB, OB> extends Mo
public static final String PROP_SECURITY_SETS = "securitySets";
public static final String PROP_SERVERS = "servers";
public static final String PROP_TAGS = "tags";
public static final String PROP_WEBHOOKS = "webhooks";

public OpenAPIDefinitionIO(IOContext<V, A, O, AB, OB> context) {
super(context, Names.OPENAPI_DEFINITION, Names.create(OpenAPI.class));
Expand Down Expand Up @@ -60,6 +61,7 @@ public OpenAPI readObject(O node) {
openApi.setExternalDocs(extDocIO().readValue(jsonIO().getValue(node, PROP_EXTERNAL_DOCS)));
openApi.setComponents(componentsIO().readValue(jsonIO().getValue(node, PROP_COMPONENTS)));
openApi.setPaths(pathsIO().readValue(jsonIO().getValue(node, PROP_PATHS)));
openApi.setWebhooks(pathItemIO().readMap(jsonIO().getValue(node, PROP_WEBHOOKS)));
openApi.setExtensions(extensionIO().readMap(node));
return openApi;
}
Expand All @@ -74,6 +76,7 @@ public Optional<O> write(OpenAPI model) {
setIfPresent(node, PROP_SECURITY, securityIO().write(model.getSecurity()));
setIfPresent(node, PROP_TAGS, tagIO().write(model.getTags()));
setIfPresent(node, PROP_PATHS, pathsIO().write(model.getPaths()));
setIfPresent(node, PROP_WEBHOOKS, pathItemIO().write(model.getWebhooks()));
setIfPresent(node, PROP_COMPONENTS, componentsIO().write(model.getComponents()));
setAllIfPresent(node, extensionIO().write(model));
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

public class PathItemIO<V, A extends V, O extends V, AB, OB> extends ModelIO<PathItem, V, A, O, AB, OB>
public class PathItemIO<V, A extends V, O extends V, AB, OB> extends MapModelIO<PathItem, V, A, O, AB, OB>
implements ReferenceIO<V, A, O, AB, OB> {

private static final String PROP_DESCRIPTION = "description";
Expand Down
Loading