Skip to content

Commit 7f4bc49

Browse files
committed
Model changes to add PathItem to Components
1 parent 5f13fd5 commit 7f4bc49

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Map;
55

66
import org.eclipse.microprofile.openapi.models.Components;
7+
import org.eclipse.microprofile.openapi.models.PathItem;
78
import org.eclipse.microprofile.openapi.models.callbacks.Callback;
89
import org.eclipse.microprofile.openapi.models.examples.Example;
910
import org.eclipse.microprofile.openapi.models.headers.Header;
@@ -30,6 +31,7 @@ public class ComponentsImpl extends ExtensibleImpl<Components> implements Compon
3031
private Map<String, SecurityScheme> securitySchemes;
3132
private Map<String, Link> links;
3233
private Map<String, Callback> callbacks;
34+
private Map<String, PathItem> pathItems;
3335

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

343+
@Override
344+
public Map<String, PathItem> getPathItems() {
345+
return ModelUtil.unmodifiableMap(this.pathItems);
346+
}
347+
348+
@Override
349+
public void setPathItems(Map<String, PathItem> pathItems) {
350+
this.pathItems = ModelUtil.replace(pathItems, LinkedHashMap<String, PathItem>::new);
351+
}
352+
353+
@Override
354+
public Components addPathItem(String name, PathItem pathItem) {
355+
this.pathItems = ModelUtil.add(name, pathItem, this.pathItems, LinkedHashMap<String, PathItem>::new);
356+
return this;
357+
}
358+
359+
@Override
360+
public void removePathItem(String name) {
361+
ModelUtil.remove(this.pathItems, name);
362+
}
363+
341364
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.eclipse.microprofile.openapi.models.parameters.Parameter;
1111
import org.eclipse.microprofile.openapi.models.servers.Server;
1212

13+
import io.smallrye.openapi.runtime.io.ReferenceType;
1314
import io.smallrye.openapi.runtime.util.ModelUtil;
1415

1516
/**
@@ -44,6 +45,9 @@ public String getRef() {
4445
*/
4546
@Override
4647
public void setRef(String ref) {
48+
if (ref != null && !ref.contains("/")) {
49+
ref = ReferenceType.PATH_ITEMS.referenceOf(ref);
50+
}
4751
this.ref = ref;
4852
}
4953

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ComponentsIO<V, A extends V, O extends V, AB, OB> extends ModelIO<C
2020
private static final String PROP_PARAMETERS = "parameters";
2121
private static final String PROP_RESPONSES = "responses";
2222
private static final String PROP_SCHEMAS = "schemas";
23+
private static final String PROP_PATH_ITEMS = "pathItems";
2324

2425
public ComponentsIO(IOContext<V, A, O, AB, OB> context) {
2526
super(context, Names.COMPONENTS, Names.create(Components.class));
@@ -64,6 +65,7 @@ public Components readObject(O node) {
6465
components.setResponses(apiResponseIO().readMap(jsonIO().getValue(node, PROP_RESPONSES)));
6566
components.setSchemas(schemaIO().readMap(jsonIO().getValue(node, PROP_SCHEMAS)));
6667
components.setSecuritySchemes(securitySchemeIO().readMap(jsonIO().getValue(node, PROP_SECURITY_SCHEMES)));
68+
components.setPathItems(pathItemIO().readMap(jsonIO().getValue(node, PROP_PATH_ITEMS)));
6769
components.setExtensions(extensionIO().readMap(node));
6870
return components;
6971
}
@@ -79,6 +81,7 @@ public Optional<O> write(Components model) {
7981
setIfPresent(node, PROP_SECURITY_SCHEMES, securitySchemeIO().write(model.getSecuritySchemes()));
8082
setIfPresent(node, PROP_LINKS, linkIO().write(model.getLinks()));
8183
setIfPresent(node, PROP_CALLBACKS, callbackIO().write(model.getCallbacks()));
84+
setIfPresent(node, PROP_PATH_ITEMS, pathItemIO().write(model.getPathItems()));
8285
setAllIfPresent(node, extensionIO().write(model));
8386
return node;
8487
}).map(jsonIO()::buildObject);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum ReferenceType {
2020
RESPONSE("responses"),
2121
PARAMETER("parameters"),
2222
EXAMPLE("examples"),
23-
REQUEST_BODY("requestBodies");
23+
REQUEST_BODY("requestBodies"),
24+
PATH_ITEMS("pathItems");
2425

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

0 commit comments

Comments
 (0)