Skip to content

Commit 06814ea

Browse files
authored
Merge pull request #83 from advanced-rest-client/feat/W-16854965/DisplayName-in-raml-is-not-shown-in-apid-or-exchange
W-16854965 - The displayName is not being shown in the API documentation panel for elements of type "object."
2 parents 7a33f69 + f64772b commit 06814ea

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-type-document",
33
"description": "A documentation table for type (resource) properties. Works with AMF data model",
4-
"version": "4.2.30",
4+
"version": "4.2.31",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/PropertyDocumentMixin.d.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
2525
* This is used to select/generate examples according to current body
2626
* media type. When not set it only renders examples that were defined
2727
* in API spec file in a form as they were written.
28-
*
28+
*
2929
* @attribute
3030
*/
3131
mediaType: string;
@@ -55,7 +55,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
5555
* @param range AMF property range object
5656
* @returns Data type of the property.
5757
*/
58-
_computeRangeDataType(range: Object): String|undefined;
58+
_computeRangeDataType(range: Object): String | undefined;
5959

6060
/**
6161
* Computes type from a scalar shape.
@@ -78,7 +78,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
7878
* @param range Range object of current shape.
7979
* @returns List of Array items.
8080
*/
81-
_computeArrayProperties(range: Object): ArrayPropertyItem[]|undefined;
81+
_computeArrayProperties(range: Object): ArrayPropertyItem[] | undefined;
8282

8383
/**
8484
* Computes value for `isUnion` property.
@@ -110,7 +110,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
110110
/**
111111
* Computes value for `isAnyOf` property.
112112
* AnyOf type is identified as a `http://www.w3.org/ns/shacl#or`
113-
*
113+
*
114114
* @param range Range object of current shape.
115115
*/
116116
_computeIsAnyOf(range: Object): boolean
@@ -141,7 +141,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
141141
* @param items Array's items property or a single property
142142
* @returns Label for the union type.
143143
*/
144-
_computeArrayUnionLabel(items: object|object[]): string|undefined;
144+
_computeArrayUnionLabel(items: object | object[]): string | undefined;
145145

146146
/**
147147
* Computes name label for the shape.
@@ -150,7 +150,9 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
150150
* @param shape The shape of the property.
151151
* @returns Display name of the property
152152
*/
153-
_computeDisplayName(range: Object, shape: Object): string|undefined;
153+
_computeDisplayName(range: Object, shape: Object): string | undefined;
154+
155+
_computeParentName(range: Object, shape: Object): string | undefined;
154156

155157
_computeHasMediaType(mediaType: string): boolean;
156158

@@ -159,5 +161,5 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
159161
_isPropertyReadOnly(property: any): boolean;
160162
_isReadOnly(property: any): boolean;
161163
}
162-
export {PropertyDocumentMixinConstructor};
163-
export {PropertyDocumentMixin};
164+
export { PropertyDocumentMixinConstructor };
165+
export { PropertyDocumentMixin };

src/PropertyDocumentMixin.js

Lines changed: 28 additions & 1 deletion
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,6 +493,33 @@ const mxFunction = (base) => {
493493
if (!shape || !range) {
494494
return undefined;
495495
}
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));
505+
}
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));
517+
}
518+
519+
_computeParentName(range, shape) {
520+
if (!shape || !range) {
521+
return undefined;
522+
}
496523
// let name;
497524
if (
498525
this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)

src/PropertyShapeDocument.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
123123
/**
124124
* A description of the shape to render.
125125
*/
126-
shapeDescription: { type: String },
126+
shapeDescription: { type: String },
127127
/**
128128
* Computed value, true if description is set.
129129
*/
@@ -319,15 +319,15 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
319319

320320
_shapeRangeChanged(shape, range) {
321321
this.displayName = this._computeDisplayName(range, shape);
322+
this.parentName = this.isObject ? this._computeParentName(range, shape) : undefined;
322323
this.propertyName = this._computePropertyName(range, shape);
323324
this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape)
324325
const {size,namespace,aliases, defaultValue} = this._computeAvroProperties(range, shape)
325326
this.size = size
326327
this.namespace = namespace
327328
this.aliases = aliases
328329
this.defaultValue = defaultValue
329-
330-
330+
331331
this.hasDisplayName = this._computeHasDisplayName(
332332
this.displayName,
333333
this.propertyName
@@ -498,7 +498,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
498498
}catch(_){
499499
return undefined
500500
}
501-
501+
502502
}
503503

504504
/**
@@ -518,7 +518,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
518518

519519

520520

521-
522521

523522
/**
524523
* Computes value for `hasDisplayName` property.
@@ -714,6 +713,16 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
714713
return this._hasType(item, this.ns.aml.vocabularies.shapes.ScalarShape);
715714
}
716715

716+
_getParentTypeName() {
717+
if (this.isArray) {
718+
return 'item'
719+
}
720+
if(this.isObject){
721+
return this.parentName
722+
}
723+
return this.displayName
724+
}
725+
717726
/**
718727
* @return {TemplateResult|string} Template for a complex shape (object/array/union)
719728
*/
@@ -722,7 +731,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
722731
return '';
723732
}
724733
const range = this._resolve(this.range);
725-
const parentTypeName = this.isArray ? 'item' : this.displayName;
734+
const parentTypeName = this._getParentTypeName();
726735
return html`<api-type-document
727736
class="children complex"
728737
.amf="${this.amf}"
@@ -843,7 +852,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
843852
`;
844853
}
845854

846-
847855

848856
/**
849857
* @return {TemplateResult|string} Template for the description
@@ -893,7 +901,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
893901
parentTypeName,
894902
hasParentTypeName
895903
} = this;
896-
904+
897905
return html` ${hasDisplayName
898906
? html`<div class="property-display-name">${displayName}</div>`
899907
: ''}

0 commit comments

Comments
 (0)