Skip to content

Commit fd57e5b

Browse files
Merge pull request #85 from advanced-rest-client/feat/W-17482615/list-mapping-types
Feat/w 17482615/list mapping types
2 parents 06814ea + a7beb8a commit fd57e5b

File tree

7 files changed

+84
-12
lines changed

7 files changed

+84
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ dist/
6464
!demo/avro.json
6565
!demo/avro2.json
6666

67-
.idea/
67+
.idea/
68+
.codegenie/

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
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.31",
4+
"version": "4.2.33",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",
@@ -28,7 +28,7 @@
2828
"@advanced-rest-client/arc-marked": "^1.1.0",
2929
"@advanced-rest-client/markdown-styles": "^3.1.4",
3030
"@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",
3232
"@api-components/api-annotation-document": "^4.1.0",
3333
"@api-components/api-resource-example-document": "^4.3.3",
3434
"@open-wc/dedupe-mixin": "^1.3.0",

src/ApiTypeDocument.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,19 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
671671
this._hasExamples = value;
672672
}
673673

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+
674687
/**
675688
* @return {TemplateResult[]|string} Templates for object properties
676689
*/
@@ -691,6 +704,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
691704
?graph="${this.graph}"
692705
.mediaType="${this.mediaType}"
693706
?renderReadOnly="${this.renderReadOnly}"
707+
.discriminatorMapping="${this._typesMappings(item)}"
694708
></property-shape-document>`
695709
);
696710
}

src/PropertyShapeDocument.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
143143
* @attribute
144144
*/
145145
deprecated: boolean
146+
/**
147+
* List type mappings
148+
* @attribute
149+
*/
150+
discriminatorMapping: any;
146151

147152
get complexToggleLabel(): string;
148153

src/PropertyShapeDocument.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
159159
* Determines if shape's range is deprecated
160160
*/
161161
deprecated: { type: Boolean, reflect: true },
162+
/**
163+
* Used for discriminator types mappings
164+
*/
165+
discriminatorMapping: { type: Object },
162166
};
163167
}
164168

@@ -247,6 +251,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
247251
this.narrow = false;
248252
this.renderReadOnly = false;
249253
this.deprecated = false;
254+
this.discriminatorMapping = undefined;
250255
}
251256

252257
connectedCallback() {
@@ -936,6 +941,42 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
936941
return ''
937942
}
938943

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+
939980
/**
940981
* @return {TemplateResult} Main render function.
941982
*/
@@ -975,6 +1016,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
9751016
${this._getTypeAliasesAvroTemplate()}
9761017
${this._deprecatedWarningTemplate()}
9771018
${this._descriptionTemplate()}
1019+
${this._typesMappingsTemplate()}
9781020
<property-range-document
9791021
.amf="${this.amf}"
9801022
.shape="${this.shape}"

src/ShapeStyles.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,14 @@ export default css`
163163
border-radius: var(--api-type-document-deprecated-warning-border-radius, 3px);
164164
display: inline-flex;
165165
}
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+
}
166176
`;

0 commit comments

Comments
 (0)