Skip to content

Commit 8dffa1c

Browse files
author
alexperez
committed
W-16854965 - Refactor mxFunction to improve type checks and streamline value retrieval
1 parent 7a33f69 commit 8dffa1c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/PropertyDocumentMixin.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ const mxFunction = (base) => {
379379
}catch(_){
380380
return undefined
381381
}
382-
382+
383383
}
384384

385385
/**
@@ -493,25 +493,27 @@ const mxFunction = (base) => {
493493
if (!shape || !range) {
494494
return undefined;
495495
}
496-
// let name;
497-
if (
498-
this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)
499-
) {
500-
return /** @type string */ (this._getValue(
501-
range,
502-
this.ns.aml.vocabularies.core.name
503-
));
496+
497+
const coreName = this.ns.aml.vocabularies.core.name;
498+
const shaclName = this.ns.w3.shacl.name;
499+
const parameterType = this.ns.aml.vocabularies.apiContract.Parameter;
500+
const nodeShapeType = this.ns.w3.shacl.NodeShape;
501+
502+
// Check if the shape is of type Parameter
503+
if (this._hasType(shape, parameterType)) {
504+
return /** @type string */ (this._getValue(range, coreName));
504505
}
505-
if (this._hasType(range, this.ns.w3.shacl.NodeShape)) {
506-
return /** @type string */ (this._getValue(
507-
shape,
508-
this.ns.w3.shacl.name
509-
));
510-
}
511-
return /** @type string */ (this._getValue(
512-
range,
513-
this.ns.aml.vocabularies.core.name
514-
));
506+
507+
// Check if the range is of type NodeShape
508+
if (this._hasType(range, nodeShapeType)) {
509+
return (
510+
/** @type string */ (this._getValue(range, coreName)) ||
511+
/** @type string */ (this._getValue(shape, shaclName))
512+
);
513+
}
514+
515+
// Default case: return the core name from the range
516+
return /** @type string */ (this._getValue(range, coreName));
515517
}
516518

517519
_computeHasMediaType(mediaType) {

0 commit comments

Comments
 (0)