diff --git a/.gitignore b/.gitignore index b08b465..e4dcaf8 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ dist/ !demo/avro.json !demo/avro2.json -.idea/ \ No newline at end of file +.idea/ +.codegenie/ \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2e6832e..c34b239 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "@api-components/api-type-document", - "version": "4.2.31", + "version": "4.2.33", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@api-components/api-type-document", - "version": "4.2.31", + "version": "4.2.33", "license": "Apache-2.0", "dependencies": { "@advanced-rest-client/arc-marked": "^1.1.0", "@advanced-rest-client/markdown-styles": "^3.1.4", "@anypoint-web-components/anypoint-button": "^1.2.3", - "@api-components/amf-helper-mixin": "^4.5.24", + "@api-components/amf-helper-mixin": "^4.5.29", "@api-components/api-annotation-document": "^4.1.0", "@api-components/api-resource-example-document": "^4.3.3", "@open-wc/dedupe-mixin": "^1.3.0", @@ -578,9 +578,9 @@ } }, "node_modules/@api-components/amf-helper-mixin": { - "version": "4.5.27", - "resolved": "https://registry.npmjs.org/@api-components/amf-helper-mixin/-/amf-helper-mixin-4.5.27.tgz", - "integrity": "sha512-ZXkO5T77unKr0jkhgu4gQ3TuY7Doto6QHuIbUdMwW30CgR6nV7HrtVplilqvtI1kJsz2DDBD5w9wbTCKZkydCg==", + "version": "4.5.29", + "resolved": "https://registry.npmjs.org/@api-components/amf-helper-mixin/-/amf-helper-mixin-4.5.29.tgz", + "integrity": "sha512-SvwsUrbyij4sagr1/TWdA+atvGEkBBwZeX3VGnWlXLKlBiGS9zdJHoFTeMAeR3jtspu9UkyLOIZ5KU5Gt+BkHg==", "dependencies": { "amf-json-ld-lib": "0.0.14" } @@ -16008,9 +16008,9 @@ } }, "@api-components/amf-helper-mixin": { - "version": "4.5.27", - "resolved": "https://registry.npmjs.org/@api-components/amf-helper-mixin/-/amf-helper-mixin-4.5.27.tgz", - "integrity": "sha512-ZXkO5T77unKr0jkhgu4gQ3TuY7Doto6QHuIbUdMwW30CgR6nV7HrtVplilqvtI1kJsz2DDBD5w9wbTCKZkydCg==", + "version": "4.5.29", + "resolved": "https://registry.npmjs.org/@api-components/amf-helper-mixin/-/amf-helper-mixin-4.5.29.tgz", + "integrity": "sha512-SvwsUrbyij4sagr1/TWdA+atvGEkBBwZeX3VGnWlXLKlBiGS9zdJHoFTeMAeR3jtspu9UkyLOIZ5KU5Gt+BkHg==", "requires": { "amf-json-ld-lib": "0.0.14" } diff --git a/package.json b/package.json index 4fd5ce1..a2b03e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@api-components/api-type-document", "description": "A documentation table for type (resource) properties. Works with AMF data model", - "version": "4.2.31", + "version": "4.2.33", "license": "Apache-2.0", "main": "index.js", "module": "index.js", @@ -28,7 +28,7 @@ "@advanced-rest-client/arc-marked": "^1.1.0", "@advanced-rest-client/markdown-styles": "^3.1.4", "@anypoint-web-components/anypoint-button": "^1.2.3", - "@api-components/amf-helper-mixin": "^4.5.24", + "@api-components/amf-helper-mixin": "^4.5.29", "@api-components/api-annotation-document": "^4.1.0", "@api-components/api-resource-example-document": "^4.3.3", "@open-wc/dedupe-mixin": "^1.3.0", diff --git a/src/ApiTypeDocument.js b/src/ApiTypeDocument.js index 5d1f118..6189ced 100644 --- a/src/ApiTypeDocument.js +++ b/src/ApiTypeDocument.js @@ -671,6 +671,19 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) { this._hasExamples = value; } + /** + * Return the type mappings + */ + _typesMappings(item) { + const itemName = this._getValue(item, this._getAmfKey(this.ns.w3.shacl.name)); + const typeTarget = this._getValue(this.type, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminator)); + let type; + if (itemName && typeTarget && itemName === typeTarget) { + type = this.type; + } + return type; + } + /** * @return {TemplateResult[]|string} Templates for object properties */ @@ -691,6 +704,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) { ?graph="${this.graph}" .mediaType="${this.mediaType}" ?renderReadOnly="${this.renderReadOnly}" + .discriminatorMapping="${this._typesMappings(item)}" >` ); } diff --git a/src/PropertyShapeDocument.d.ts b/src/PropertyShapeDocument.d.ts index 4c38e65..09de535 100644 --- a/src/PropertyShapeDocument.d.ts +++ b/src/PropertyShapeDocument.d.ts @@ -143,6 +143,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { * @attribute */ deprecated: boolean + /** + * List type mappings + * @attribute + */ + discriminatorMapping: any; get complexToggleLabel(): string; diff --git a/src/PropertyShapeDocument.js b/src/PropertyShapeDocument.js index 876fdd0..6eb2bd1 100644 --- a/src/PropertyShapeDocument.js +++ b/src/PropertyShapeDocument.js @@ -159,6 +159,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { * Determines if shape's range is deprecated */ deprecated: { type: Boolean, reflect: true }, + /** + * Used for discriminator types mappings + */ + discriminatorMapping: { type: Object }, }; } @@ -247,6 +251,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { this.narrow = false; this.renderReadOnly = false; this.deprecated = false; + this.discriminatorMapping = undefined; } connectedCallback() { @@ -936,6 +941,42 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { return '' } + _navigateItem(e) { + e.preventDefault(); + const data = e.composedPath()[0].dataset; + if (!data.id || !data.shapeType) { + return; + } + const ev = new CustomEvent("api-navigation-selection-changed", { + bubbles: true, + composed: true, + detail: { + selected: data.id, + type: data.shapeType, + }, + }); + this.dispatchEvent(ev); + } + + _keydownNavigateItem(e) { + if (e.key === "Enter") { + this._navigateItem(e); + } + } + + _typesMappingsTemplate() { + const mappings = this._getValueArray(this.discriminatorMapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValueMapping)); + if (!mappings) return html``; + + return html``; + } + /** * @return {TemplateResult} Main render function. */ @@ -975,6 +1016,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) { ${this._getTypeAliasesAvroTemplate()} ${this._deprecatedWarningTemplate()} ${this._descriptionTemplate()} + ${this._typesMappingsTemplate()}