From 8dffa1c38cff5a0e58b9f758bc7eb1977b21dcf2 Mon Sep 17 00:00:00 2001 From: alexperez Date: Mon, 14 Oct 2024 18:20:58 -0300 Subject: [PATCH 1/3] W-16854965 - Refactor mxFunction to improve type checks and streamline value retrieval --- src/PropertyDocumentMixin.js | 40 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/PropertyDocumentMixin.js b/src/PropertyDocumentMixin.js index 410bd2b..c90bfe1 100644 --- a/src/PropertyDocumentMixin.js +++ b/src/PropertyDocumentMixin.js @@ -379,7 +379,7 @@ const mxFunction = (base) => { }catch(_){ return undefined } - + } /** @@ -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) { From d897e17407863f17c0faeddecbc31a39e392d409 Mon Sep 17 00:00:00 2001 From: alexperez Date: Mon, 14 Oct 2024 19:38:13 -0300 Subject: [PATCH 2/3] Enhance PropertyDocumentMixin with parent name computation and improve code formatting --- src/PropertyDocumentMixin.d.ts | 18 ++++++++++-------- src/PropertyDocumentMixin.js | 25 +++++++++++++++++++++++++ src/PropertyShapeDocument.js | 24 ++++++++++++++++-------- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/PropertyDocumentMixin.d.ts b/src/PropertyDocumentMixin.d.ts index d6cd6d1..810bafb 100644 --- a/src/PropertyDocumentMixin.d.ts +++ b/src/PropertyDocumentMixin.d.ts @@ -25,7 +25,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin { * This is used to select/generate examples according to current body * media type. When not set it only renders examples that were defined * in API spec file in a form as they were written. - * + * * @attribute */ mediaType: string; @@ -55,7 +55,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin { * @param range AMF property range object * @returns Data type of the property. */ - _computeRangeDataType(range: Object): String|undefined; + _computeRangeDataType(range: Object): String | undefined; /** * Computes type from a scalar shape. @@ -78,7 +78,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin { * @param range Range object of current shape. * @returns List of Array items. */ - _computeArrayProperties(range: Object): ArrayPropertyItem[]|undefined; + _computeArrayProperties(range: Object): ArrayPropertyItem[] | undefined; /** * Computes value for `isUnion` property. @@ -110,7 +110,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin { /** * Computes value for `isAnyOf` property. * AnyOf type is identified as a `http://www.w3.org/ns/shacl#or` - * + * * @param range Range object of current shape. */ _computeIsAnyOf(range: Object): boolean @@ -141,7 +141,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin { * @param items Array's items property or a single property * @returns Label for the union type. */ - _computeArrayUnionLabel(items: object|object[]): string|undefined; + _computeArrayUnionLabel(items: object | object[]): string | undefined; /** * Computes name label for the shape. @@ -150,7 +150,9 @@ interface PropertyDocumentMixin extends AmfHelperMixin { * @param shape The shape of the property. * @returns Display name of the property */ - _computeDisplayName(range: Object, shape: Object): string|undefined; + _computeDisplayName(range: Object, shape: Object): string | undefined; + + _computeParentName(range: Object, shape: Object): string | undefined; _computeHasMediaType(mediaType: string): boolean; @@ -159,5 +161,5 @@ interface PropertyDocumentMixin extends AmfHelperMixin { _isPropertyReadOnly(property: any): boolean; _isReadOnly(property: any): boolean; } -export {PropertyDocumentMixinConstructor}; -export {PropertyDocumentMixin}; +export { PropertyDocumentMixinConstructor }; +export { PropertyDocumentMixin }; diff --git a/src/PropertyDocumentMixin.js b/src/PropertyDocumentMixin.js index c90bfe1..286f6a7 100644 --- a/src/PropertyDocumentMixin.js +++ b/src/PropertyDocumentMixin.js @@ -516,6 +516,31 @@ const mxFunction = (base) => { return /** @type string */ (this._getValue(range, coreName)); } + _computeParentName(range, shape) { + 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 + )); + } + 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 + )); + } + _computeHasMediaType(mediaType) { return !!mediaType; } diff --git a/src/PropertyShapeDocument.js b/src/PropertyShapeDocument.js index c1f3b29..876fdd0 100644 --- a/src/PropertyShapeDocument.js +++ b/src/PropertyShapeDocument.js @@ -123,7 +123,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { /** * A description of the shape to render. */ - shapeDescription: { type: String }, + shapeDescription: { type: String }, /** * Computed value, true if description is set. */ @@ -319,6 +319,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { _shapeRangeChanged(shape, range) { this.displayName = this._computeDisplayName(range, shape); + this.parentName = this.isObject ? this._computeParentName(range, shape) : undefined; this.propertyName = this._computePropertyName(range, shape); this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape) const {size,namespace,aliases, defaultValue} = this._computeAvroProperties(range, shape) @@ -326,8 +327,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { this.namespace = namespace this.aliases = aliases this.defaultValue = defaultValue - - + this.hasDisplayName = this._computeHasDisplayName( this.displayName, this.propertyName @@ -498,7 +498,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { }catch(_){ return undefined } - + } /** @@ -518,7 +518,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { - /** * Computes value for `hasDisplayName` property. @@ -714,6 +713,16 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { return this._hasType(item, this.ns.aml.vocabularies.shapes.ScalarShape); } + _getParentTypeName() { + if (this.isArray) { + return 'item' + } + if(this.isObject){ + return this.parentName + } + return this.displayName + } + /** * @return {TemplateResult|string} Template for a complex shape (object/array/union) */ @@ -722,7 +731,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { return ''; } const range = this._resolve(this.range); - const parentTypeName = this.isArray ? 'item' : this.displayName; + const parentTypeName = this._getParentTypeName(); return html`${displayName}` : ''} From f64772b55de55abb52284c4fb080dd3b4bdae24c Mon Sep 17 00:00:00 2001 From: alexperez Date: Tue, 15 Oct 2024 10:43:48 -0300 Subject: [PATCH 3/3] 4.2.31 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80e14e7..2e6832e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@api-components/api-type-document", - "version": "4.2.30", + "version": "4.2.31", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@api-components/api-type-document", - "version": "4.2.30", + "version": "4.2.31", "license": "Apache-2.0", "dependencies": { "@advanced-rest-client/arc-marked": "^1.1.0", diff --git a/package.json b/package.json index 6d7ca15..4fd5ce1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@api-components/api-type-document", "description": "A documentation table for type (resource) properties. Works with AMF data model", - "version": "4.2.30", + "version": "4.2.31", "license": "Apache-2.0", "main": "index.js", "module": "index.js",