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

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.31",
4
+ "version": "4.2.34",
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.24",
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",
@@ -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
  }
@@ -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
 
@@ -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() {
@@ -748,6 +753,24 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
748
753
  ></api-type-document>`;
749
754
  }
750
755
 
756
+ _extractElementsDataType(namespaceKey){
757
+ const key = this._getAmfKey(namespaceKey)
758
+ const dataTypes = this.range[key]
759
+ if(!dataTypes){
760
+ return 'Any'
761
+ }
762
+ let dataType = ''
763
+ for(const dataTypeValue of dataTypes){
764
+ const computeDataType = this._computeRangeDataType(dataTypeValue)
765
+
766
+ if(dataType!=='' && dataType!==computeDataType){
767
+ return 'Any'
768
+ }
769
+ dataType = String(computeDataType)
770
+ }
771
+ return dataType
772
+ }
773
+
751
774
  _getTypeLabelData(){
752
775
  const { propertyDataType, avroValue } = this;
753
776
  if(avroValue==='map'){
@@ -756,6 +779,15 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
756
779
  if(propertyDataType==='Unknown type' && avroValue){
757
780
  return {dataType:avroValue,customValue:true}
758
781
  }
782
+
783
+ if(this.isAllOf){
784
+ const dataType = this._extractElementsDataType(this.ns.w3.shacl.and)
785
+ return {dataType,customValue:false}
786
+ }
787
+ if(this.isAnyOf){
788
+ const dataType = this._extractElementsDataType(this.ns.w3.shacl.or)
789
+ return {dataType,customValue:false}
790
+ }
759
791
  return {dataType:propertyDataType,customValue:false}
760
792
  }
761
793
 
@@ -936,6 +968,42 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
936
968
  return ''
937
969
  }
938
970
 
971
+ _navigateItem(e) {
972
+ e.preventDefault();
973
+ const data = e.composedPath()[0].dataset;
974
+ if (!data.id || !data.shapeType) {
975
+ return;
976
+ }
977
+ const ev = new CustomEvent("api-navigation-selection-changed", {
978
+ bubbles: true,
979
+ composed: true,
980
+ detail: {
981
+ selected: data.id,
982
+ type: data.shapeType,
983
+ },
984
+ });
985
+ this.dispatchEvent(ev);
986
+ }
987
+
988
+ _keydownNavigateItem(e) {
989
+ if (e.key === "Enter") {
990
+ this._navigateItem(e);
991
+ }
992
+ }
993
+
994
+ _typesMappingsTemplate() {
995
+ const mappings = this._getValueArray(this.discriminatorMapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValueMapping));
996
+ if (!mappings) return html``;
997
+
998
+ return html`<ul class="types-mappings-container">
999
+ ${mappings.map((mapping) => {
1000
+ const name = this._getValue(mapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValue));
1001
+ const target = this._getLinkValue(mapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValueTarget));
1002
+ return html`<li class="types-mappings-item" data-id="${target}" data-shape-type="type" @click="${this._navigateItem}" @keydown="${this._keydownNavigateItem}">${name}</li>`;
1003
+ })}
1004
+ </ul>`;
1005
+ }
1006
+
939
1007
  /**
940
1008
  * @return {TemplateResult} Main render function.
941
1009
  */
@@ -975,6 +1043,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
975
1043
  ${this._getTypeAliasesAvroTemplate()}
976
1044
  ${this._deprecatedWarningTemplate()}
977
1045
  ${this._descriptionTemplate()}
1046
+ ${this._typesMappingsTemplate()}
978
1047
  <property-range-document
979
1048
  .amf="${this.amf}"
980
1049
  .shape="${this.shape}"
@@ -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
  `;