Skip to content

Commit

Permalink
W-16854965 - Refactor mxFunction to improve type checks and streamlin…
Browse files Browse the repository at this point in the history
…e value retrieval
  • Loading branch information
alexpmule committed Oct 14, 2024
1 parent 7a33f69 commit 8dffa1c
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/PropertyDocumentMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const mxFunction = (base) => {
}catch(_){
return undefined
}

}

/**
Expand Down Expand Up @@ -493,25 +493,27 @@ const mxFunction = (base) => {
if (!shape || !range) {
return undefined;
}
// let name;
if (
this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)
) {
return /** @type string */ (this._getValue(
range,
this.ns.aml.vocabularies.core.name
));

const coreName = this.ns.aml.vocabularies.core.name;
const shaclName = this.ns.w3.shacl.name;
const parameterType = this.ns.aml.vocabularies.apiContract.Parameter;
const nodeShapeType = this.ns.w3.shacl.NodeShape;

// Check if the shape is of type Parameter
if (this._hasType(shape, parameterType)) {
return /** @type string */ (this._getValue(range, coreName));
}
if (this._hasType(range, this.ns.w3.shacl.NodeShape)) {
return /** @type string */ (this._getValue(
shape,
this.ns.w3.shacl.name
));
}
return /** @type string */ (this._getValue(
range,
this.ns.aml.vocabularies.core.name
));

// Check if the range is of type NodeShape
if (this._hasType(range, nodeShapeType)) {
return (
/** @type string */ (this._getValue(range, coreName)) ||
/** @type string */ (this._getValue(shape, shaclName))
);
}

// Default case: return the core name from the range
return /** @type string */ (this._getValue(range, coreName));
}

_computeHasMediaType(mediaType) {
Expand Down

0 comments on commit 8dffa1c

Please sign in to comment.