@api-components/api-type-document 4.2.30 → 4.2.33
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.
|
|
4
|
+
"version": "4.2.33",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@advanced-rest-client/arc-marked": "^1.1.0",
|
|
29
29
|
"@advanced-rest-client/markdown-styles": "^3.1.4",
|
|
30
30
|
"@anypoint-web-components/anypoint-button": "^1.2.3",
|
|
31
|
-
"@api-components/amf-helper-mixin": "^4.5.
|
|
31
|
+
"@api-components/amf-helper-mixin": "^4.5.29",
|
|
32
32
|
"@api-components/api-annotation-document": "^4.1.0",
|
|
33
33
|
"@api-components/api-resource-example-document": "^4.3.3",
|
|
34
34
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
package/src/ApiTypeDocument.js
CHANGED
|
@@ -671,6 +671,19 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
671
671
|
this._hasExamples = value;
|
|
672
672
|
}
|
|
673
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Return the type mappings
|
|
676
|
+
*/
|
|
677
|
+
_typesMappings(item) {
|
|
678
|
+
const itemName = this._getValue(item, this._getAmfKey(this.ns.w3.shacl.name));
|
|
679
|
+
const typeTarget = this._getValue(this.type, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminator));
|
|
680
|
+
let type;
|
|
681
|
+
if (itemName && typeTarget && itemName === typeTarget) {
|
|
682
|
+
type = this.type;
|
|
683
|
+
}
|
|
684
|
+
return type;
|
|
685
|
+
}
|
|
686
|
+
|
|
674
687
|
/**
|
|
675
688
|
* @return {TemplateResult[]|string} Templates for object properties
|
|
676
689
|
*/
|
|
@@ -691,6 +704,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
691
704
|
?graph="${this.graph}"
|
|
692
705
|
.mediaType="${this.mediaType}"
|
|
693
706
|
?renderReadOnly="${this.renderReadOnly}"
|
|
707
|
+
.discriminatorMapping="${this._typesMappings(item)}"
|
|
694
708
|
></property-shape-document>`
|
|
695
709
|
);
|
|
696
710
|
}
|
|
@@ -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)
|
|
@@ -143,6 +143,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
143
143
|
* @attribute
|
|
144
144
|
*/
|
|
145
145
|
deprecated: boolean
|
|
146
|
+
/**
|
|
147
|
+
* List type mappings
|
|
148
|
+
* @attribute
|
|
149
|
+
*/
|
|
150
|
+
discriminatorMapping: any;
|
|
146
151
|
|
|
147
152
|
get complexToggleLabel(): string;
|
|
148
153
|
|
|
@@ -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
|
*/
|
|
@@ -159,6 +159,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
159
159
|
* Determines if shape's range is deprecated
|
|
160
160
|
*/
|
|
161
161
|
deprecated: { type: Boolean, reflect: true },
|
|
162
|
+
/**
|
|
163
|
+
* Used for discriminator types mappings
|
|
164
|
+
*/
|
|
165
|
+
discriminatorMapping: { type: Object },
|
|
162
166
|
};
|
|
163
167
|
}
|
|
164
168
|
|
|
@@ -247,6 +251,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
247
251
|
this.narrow = false;
|
|
248
252
|
this.renderReadOnly = false;
|
|
249
253
|
this.deprecated = false;
|
|
254
|
+
this.discriminatorMapping = undefined;
|
|
250
255
|
}
|
|
251
256
|
|
|
252
257
|
connectedCallback() {
|
|
@@ -319,6 +324,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
319
324
|
|
|
320
325
|
_shapeRangeChanged(shape, range) {
|
|
321
326
|
this.displayName = this._computeDisplayName(range, shape);
|
|
327
|
+
this.parentName = this.isObject ? this._computeParentName(range, shape) : undefined;
|
|
322
328
|
this.propertyName = this._computePropertyName(range, shape);
|
|
323
329
|
this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape)
|
|
324
330
|
const {size,namespace,aliases, defaultValue} = this._computeAvroProperties(range, shape)
|
|
@@ -326,8 +332,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
326
332
|
this.namespace = namespace
|
|
327
333
|
this.aliases = aliases
|
|
328
334
|
this.defaultValue = defaultValue
|
|
329
|
-
|
|
330
|
-
|
|
335
|
+
|
|
331
336
|
this.hasDisplayName = this._computeHasDisplayName(
|
|
332
337
|
this.displayName,
|
|
333
338
|
this.propertyName
|
|
@@ -498,7 +503,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
498
503
|
}catch(_){
|
|
499
504
|
return undefined
|
|
500
505
|
}
|
|
501
|
-
|
|
506
|
+
|
|
502
507
|
}
|
|
503
508
|
|
|
504
509
|
/**
|
|
@@ -518,7 +523,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
518
523
|
|
|
519
524
|
|
|
520
525
|
|
|
521
|
-
|
|
522
526
|
|
|
523
527
|
/**
|
|
524
528
|
* Computes value for `hasDisplayName` property.
|
|
@@ -714,6 +718,16 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
714
718
|
return this._hasType(item, this.ns.aml.vocabularies.shapes.ScalarShape);
|
|
715
719
|
}
|
|
716
720
|
|
|
721
|
+
_getParentTypeName() {
|
|
722
|
+
if (this.isArray) {
|
|
723
|
+
return 'item'
|
|
724
|
+
}
|
|
725
|
+
if(this.isObject){
|
|
726
|
+
return this.parentName
|
|
727
|
+
}
|
|
728
|
+
return this.displayName
|
|
729
|
+
}
|
|
730
|
+
|
|
717
731
|
/**
|
|
718
732
|
* @return {TemplateResult|string} Template for a complex shape (object/array/union)
|
|
719
733
|
*/
|
|
@@ -722,7 +736,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
722
736
|
return '';
|
|
723
737
|
}
|
|
724
738
|
const range = this._resolve(this.range);
|
|
725
|
-
const parentTypeName = this.
|
|
739
|
+
const parentTypeName = this._getParentTypeName();
|
|
726
740
|
return html`<api-type-document
|
|
727
741
|
class="children complex"
|
|
728
742
|
.amf="${this.amf}"
|
|
@@ -843,7 +857,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
843
857
|
`;
|
|
844
858
|
}
|
|
845
859
|
|
|
846
|
-
|
|
847
860
|
|
|
848
861
|
/**
|
|
849
862
|
* @return {TemplateResult|string} Template for the description
|
|
@@ -893,7 +906,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
893
906
|
parentTypeName,
|
|
894
907
|
hasParentTypeName
|
|
895
908
|
} = this;
|
|
896
|
-
|
|
909
|
+
|
|
897
910
|
return html` ${hasDisplayName
|
|
898
911
|
? html`<div class="property-display-name">${displayName}</div>`
|
|
899
912
|
: ''}
|
|
@@ -928,6 +941,42 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
928
941
|
return ''
|
|
929
942
|
}
|
|
930
943
|
|
|
944
|
+
_navigateItem(e) {
|
|
945
|
+
e.preventDefault();
|
|
946
|
+
const data = e.composedPath()[0].dataset;
|
|
947
|
+
if (!data.id || !data.shapeType) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const ev = new CustomEvent("api-navigation-selection-changed", {
|
|
951
|
+
bubbles: true,
|
|
952
|
+
composed: true,
|
|
953
|
+
detail: {
|
|
954
|
+
selected: data.id,
|
|
955
|
+
type: data.shapeType,
|
|
956
|
+
},
|
|
957
|
+
});
|
|
958
|
+
this.dispatchEvent(ev);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
_keydownNavigateItem(e) {
|
|
962
|
+
if (e.key === "Enter") {
|
|
963
|
+
this._navigateItem(e);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
_typesMappingsTemplate() {
|
|
968
|
+
const mappings = this._getValueArray(this.discriminatorMapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValueMapping));
|
|
969
|
+
if (!mappings) return html``;
|
|
970
|
+
|
|
971
|
+
return html`<ul class="types-mappings-container">
|
|
972
|
+
${mappings.map((mapping) => {
|
|
973
|
+
const name = this._getValue(mapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValue));
|
|
974
|
+
const target = this._getLinkValue(mapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValueTarget));
|
|
975
|
+
return html`<li class="types-mappings-item" data-id="${target}" data-shape-type="type" @click="${this._navigateItem}" @keydown="${this._keydownNavigateItem}">${name}</li>`;
|
|
976
|
+
})}
|
|
977
|
+
</ul>`;
|
|
978
|
+
}
|
|
979
|
+
|
|
931
980
|
/**
|
|
932
981
|
* @return {TemplateResult} Main render function.
|
|
933
982
|
*/
|
|
@@ -967,6 +1016,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
967
1016
|
${this._getTypeAliasesAvroTemplate()}
|
|
968
1017
|
${this._deprecatedWarningTemplate()}
|
|
969
1018
|
${this._descriptionTemplate()}
|
|
1019
|
+
${this._typesMappingsTemplate()}
|
|
970
1020
|
<property-range-document
|
|
971
1021
|
.amf="${this.amf}"
|
|
972
1022
|
.shape="${this.shape}"
|
package/src/ShapeStyles.js
CHANGED
|
@@ -163,4 +163,14 @@ export default css`
|
|
|
163
163
|
border-radius: var(--api-type-document-deprecated-warning-border-radius, 3px);
|
|
164
164
|
display: inline-flex;
|
|
165
165
|
}
|
|
166
|
+
.types-mappings-container {
|
|
167
|
+
margin-top: -10px;
|
|
168
|
+
}
|
|
169
|
+
.types-mappings-item {
|
|
170
|
+
cursor: pointer;
|
|
171
|
+
color: var(--link-color, #0277bd);
|
|
172
|
+
}
|
|
173
|
+
.types-mappings-item:hover {
|
|
174
|
+
text-decoration: underline;
|
|
175
|
+
}
|
|
166
176
|
`;
|