@api-components/api-type-document 4.2.30 → 4.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-components/api-type-document",
3
3
  "description": "A documentation table for type (resource) properties. Works with AMF data model",
4
- "version": "4.2.30",
4
+ "version": "4.2.31",
5
5
  "license": "Apache-2.0",
6
6
  "main": "index.js",
7
7
  "module": "index.js",
@@ -25,7 +25,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
25
25
  * This is used to select/generate examples according to current body
26
26
  * media type. When not set it only renders examples that were defined
27
27
  * in API spec file in a form as they were written.
28
- *
28
+ *
29
29
  * @attribute
30
30
  */
31
31
  mediaType: string;
@@ -55,7 +55,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
55
55
  * @param range AMF property range object
56
56
  * @returns Data type of the property.
57
57
  */
58
- _computeRangeDataType(range: Object): String|undefined;
58
+ _computeRangeDataType(range: Object): String | undefined;
59
59
 
60
60
  /**
61
61
  * Computes type from a scalar shape.
@@ -78,7 +78,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
78
78
  * @param range Range object of current shape.
79
79
  * @returns List of Array items.
80
80
  */
81
- _computeArrayProperties(range: Object): ArrayPropertyItem[]|undefined;
81
+ _computeArrayProperties(range: Object): ArrayPropertyItem[] | undefined;
82
82
 
83
83
  /**
84
84
  * Computes value for `isUnion` property.
@@ -110,7 +110,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
110
110
  /**
111
111
  * Computes value for `isAnyOf` property.
112
112
  * AnyOf type is identified as a `http://www.w3.org/ns/shacl#or`
113
- *
113
+ *
114
114
  * @param range Range object of current shape.
115
115
  */
116
116
  _computeIsAnyOf(range: Object): boolean
@@ -141,7 +141,7 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
141
141
  * @param items Array's items property or a single property
142
142
  * @returns Label for the union type.
143
143
  */
144
- _computeArrayUnionLabel(items: object|object[]): string|undefined;
144
+ _computeArrayUnionLabel(items: object | object[]): string | undefined;
145
145
 
146
146
  /**
147
147
  * Computes name label for the shape.
@@ -150,7 +150,9 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
150
150
  * @param shape The shape of the property.
151
151
  * @returns Display name of the property
152
152
  */
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;
154
156
 
155
157
  _computeHasMediaType(mediaType: string): boolean;
156
158
 
@@ -159,5 +161,5 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
159
161
  _isPropertyReadOnly(property: any): boolean;
160
162
  _isReadOnly(property: any): boolean;
161
163
  }
162
- export {PropertyDocumentMixinConstructor};
163
- export {PropertyDocumentMixin};
164
+ export { PropertyDocumentMixinConstructor };
165
+ export { PropertyDocumentMixin };
@@ -379,7 +379,7 @@ const mxFunction = (base) => {
379
379
  }catch(_){
380
380
  return undefined
381
381
  }
382
-
382
+
383
383
  }
384
384
 
385
385
  /**
@@ -493,6 +493,33 @@ const mxFunction = (base) => {
493
493
  if (!shape || !range) {
494
494
  return undefined;
495
495
  }
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
+ }
496
523
  // let name;
497
524
  if (
498
525
  this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)
@@ -123,7 +123,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
123
123
  /**
124
124
  * A description of the shape to render.
125
125
  */
126
- shapeDescription: { type: String },
126
+ shapeDescription: { type: String },
127
127
  /**
128
128
  * Computed value, true if description is set.
129
129
  */
@@ -319,6 +319,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
319
319
 
320
320
  _shapeRangeChanged(shape, range) {
321
321
  this.displayName = this._computeDisplayName(range, shape);
322
+ this.parentName = this.isObject ? this._computeParentName(range, shape) : undefined;
322
323
  this.propertyName = this._computePropertyName(range, shape);
323
324
  this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape)
324
325
  const {size,namespace,aliases, defaultValue} = this._computeAvroProperties(range, shape)
@@ -326,8 +327,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
326
327
  this.namespace = namespace
327
328
  this.aliases = aliases
328
329
  this.defaultValue = defaultValue
329
-
330
-
330
+
331
331
  this.hasDisplayName = this._computeHasDisplayName(
332
332
  this.displayName,
333
333
  this.propertyName
@@ -498,7 +498,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
498
498
  }catch(_){
499
499
  return undefined
500
500
  }
501
-
501
+
502
502
  }
503
503
 
504
504
  /**
@@ -518,7 +518,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
518
518
 
519
519
 
520
520
 
521
-
522
521
 
523
522
  /**
524
523
  * Computes value for `hasDisplayName` property.
@@ -714,6 +713,16 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
714
713
  return this._hasType(item, this.ns.aml.vocabularies.shapes.ScalarShape);
715
714
  }
716
715
 
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
+
717
726
  /**
718
727
  * @return {TemplateResult|string} Template for a complex shape (object/array/union)
719
728
  */
@@ -722,7 +731,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
722
731
  return '';
723
732
  }
724
733
  const range = this._resolve(this.range);
725
- const parentTypeName = this.isArray ? 'item' : this.displayName;
734
+ const parentTypeName = this._getParentTypeName();
726
735
  return html`<api-type-document
727
736
  class="children complex"
728
737
  .amf="${this.amf}"
@@ -843,7 +852,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
843
852
  `;
844
853
  }
845
854
 
846
-
847
855
 
848
856
  /**
849
857
  * @return {TemplateResult|string} Template for the description
@@ -893,7 +901,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
893
901
  parentTypeName,
894
902
  hasParentTypeName
895
903
  } = this;
896
-
904
+
897
905
  return html` ${hasDisplayName
898
906
  ? html`<div class="property-display-name">${displayName}</div>`
899
907
  : ''}