Try this, or adapt this code to suit your needs:
go.Shape.defineFigureGenerator("HCapsule3", function(shape, w, h) {
var geo = new go.Geometry();
if (w < 20 || h < 20) {
var fig = new go.PathFigure(w/2, 0, true);
fig.add(new go.PathSegment(go.PathSegment.Bezier, w/2, h, w, 0, w, h));
fig.add(new go.PathSegment(go.PathSegment.Bezier, w/2, 0, 0, h, 0, 0));
geo.add(fig);
return geo;
} else {
const ox = 4;
w -= ox*3;
const oy = 4;
h -= oy*3;
if (w < 2*h) {
var fig = new go.PathFigure(2*ox + w/2, 2*oy + 0, true);
fig.add(new go.PathSegment(go.PathSegment.Bezier, 2*ox + w/2, 2*oy + h, 2*ox + w, 2*oy + 0, 2*ox + w, 2*oy + h));
fig.add(new go.PathSegment(go.PathSegment.Bezier, 2*ox + w/2, 0, 2*ox + 0, 2*oy + h, 2*ox + 0, 2*oy + 0));
geo.add(fig);
fig = new go.PathFigure(ox + w/2, oy + 0, true);
fig.add(new go.PathSegment(go.PathSegment.Bezier, ox + w/2, oy + h, ox + w, oy + 0, ox + w, oy + h));
fig.add(new go.PathSegment(go.PathSegment.Bezier, ox + w/2, oy + 0, ox + 0, oy + h, ox + 0, oy + 0));
geo.add(fig);
fig = new go.PathFigure(w/2, 0, true);
fig.add(new go.PathSegment(go.PathSegment.Bezier, w/2, h, w, 0, w, h));
fig.add(new go.PathSegment(go.PathSegment.Bezier, w/2, 0, 0, h, 0, 0));
geo.add(fig);
} else {
var fig = new go.PathFigure(2*ox + h/2, 2*oy + 0, true);
// Outline
fig.add(new go.PathSegment(go.PathSegment.Line, 2*ox + w-h/2, 2*oy + 0));
fig.add(new go.PathSegment(go.PathSegment.Arc, 270, 180, 2*ox + w-h/2, 2*oy + h/2, h/2, h/2));
fig.add(new go.PathSegment(go.PathSegment.Line, 2*ox + w-h/2, 2*oy + h));
fig.add(new go.PathSegment(go.PathSegment.Arc, 90, 180, 2*ox + h/2, 2*oy + h/2, h/2, h/2));
geo.add(fig);
fig = new go.PathFigure(ox + h/2, 0, true);
// Outline
fig.add(new go.PathSegment(go.PathSegment.Line, ox + w-h/2, oy + 0));
fig.add(new go.PathSegment(go.PathSegment.Arc, 270, 180, ox + w-h/2, oy + h/2, h/2, h/2));
fig.add(new go.PathSegment(go.PathSegment.Line, ox + w-h/2, oy + h));
fig.add(new go.PathSegment(go.PathSegment.Arc, 90, 180, ox + h/2, oy + h/2, h/2, h/2));
geo.add(fig);
fig = new go.PathFigure(h/2, 0, true);
// Outline
fig.add(new go.PathSegment(go.PathSegment.Line, w-h/2, 0));
fig.add(new go.PathSegment(go.PathSegment.Arc, 270, 180, w-h/2, h/2, h/2, h/2));
fig.add(new go.PathSegment(go.PathSegment.Line, w-h/2, h));
fig.add(new go.PathSegment(go.PathSegment.Arc, 90, 180, h/2, h/2, h/2, h/2));
geo.add(fig);
}
geo.spot2 = new go.Spot(1, 1, -ox*2, -oy*2);
return geo;
}
});