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

Model changes to add PathItem to Components #1852

Merged
merged 1 commit into from
Jun 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Map;

import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.PathItem;
import org.eclipse.microprofile.openapi.models.callbacks.Callback;
import org.eclipse.microprofile.openapi.models.examples.Example;
import org.eclipse.microprofile.openapi.models.headers.Header;
Expand All @@ -30,6 +31,7 @@ public class ComponentsImpl extends ExtensibleImpl<Components> implements Compon
private Map<String, SecurityScheme> securitySchemes;
private Map<String, Link> links;
private Map<String, Callback> callbacks;
private Map<String, PathItem> pathItems;

/**
* @see org.eclipse.microprofile.openapi.models.Components#getSchemas()
Expand Down Expand Up @@ -338,4 +340,25 @@ public void removeCallback(String key) {
ModelUtil.remove(this.callbacks, key);
}

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

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

@Override
public Components addPathItem(String name, PathItem pathItem) {
this.pathItems = ModelUtil.add(name, pathItem, this.pathItems, LinkedHashMap<String, PathItem>::new);
return this;
}

@Override
public void removePathItem(String name) {
ModelUtil.remove(this.pathItems, name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.eclipse.microprofile.openapi.models.parameters.Parameter;
import org.eclipse.microprofile.openapi.models.servers.Server;

import io.smallrye.openapi.runtime.io.ReferenceType;
import io.smallrye.openapi.runtime.util.ModelUtil;

/**
Expand Down Expand Up @@ -44,6 +45,9 @@ public String getRef() {
*/
@Override
public void setRef(String ref) {
if (ref != null && !ref.contains("/")) {
ref = ReferenceType.PATH_ITEMS.referenceOf(ref);
}
this.ref = ref;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ComponentsIO<V, A extends V, O extends V, AB, OB> extends ModelIO<C
private static final String PROP_PARAMETERS = "parameters";
private static final String PROP_RESPONSES = "responses";
private static final String PROP_SCHEMAS = "schemas";
private static final String PROP_PATH_ITEMS = "pathItems";

public ComponentsIO(IOContext<V, A, O, AB, OB> context) {
super(context, Names.COMPONENTS, Names.create(Components.class));
Expand Down Expand Up @@ -64,6 +65,7 @@ public Components readObject(O node) {
components.setResponses(apiResponseIO().readMap(jsonIO().getValue(node, PROP_RESPONSES)));
components.setSchemas(schemaIO().readMap(jsonIO().getValue(node, PROP_SCHEMAS)));
components.setSecuritySchemes(securitySchemeIO().readMap(jsonIO().getValue(node, PROP_SECURITY_SCHEMES)));
components.setPathItems(pathItemIO().readMap(jsonIO().getValue(node, PROP_PATH_ITEMS)));
components.setExtensions(extensionIO().readMap(node));
return components;
}
Expand All @@ -79,6 +81,7 @@ public Optional<O> write(Components model) {
setIfPresent(node, PROP_SECURITY_SCHEMES, securitySchemeIO().write(model.getSecuritySchemes()));
setIfPresent(node, PROP_LINKS, linkIO().write(model.getLinks()));
setIfPresent(node, PROP_CALLBACKS, callbackIO().write(model.getCallbacks()));
setIfPresent(node, PROP_PATH_ITEMS, pathItemIO().write(model.getPathItems()));
setAllIfPresent(node, extensionIO().write(model));
return node;
}).map(jsonIO()::buildObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum ReferenceType {
RESPONSE("responses"),
PARAMETER("parameters"),
EXAMPLE("examples"),
REQUEST_BODY("requestBodies");
REQUEST_BODY("requestBodies"),
PATH_ITEMS("pathItems");

private static final Pattern COMPONENT_KEY_PATTERN = Pattern.compile("^[a-zA-Z0-9\\.\\-_]+$");
public static final String PROP_ANNOTATION = "ref";
Expand Down
Loading