+ ? html`
`
- : ''}
+ : ""}
- ${this.isObject ? this._objectTemplate() : ''}
- ${this.isArray ? this._arrayTemplate() : ''}
+ ${this.isObject ? this._objectTemplate() : ""} ${this.isArray ? this._arrayTemplate() : ""}
${this.isScalar
? html`
`
- : ''}
- ${this.isUnion ? this._unionTemplate() : ''}
- ${this.isAnd ? this._anyTemplate() : ''}
- ${this.isAnyOf ? this._anyOfTemplate() : ''}
- ${this.isOneOf ? this._oneOfTemplate() : ''}`;
+ : ""}
+ ${this.isUnion ? this._unionTemplate() : ""} ${this.isAnd ? this._anyTemplate() : ""} ${this.isAnyOf ? this._anyOfTemplate() : ""} ${this.isOneOf ? this._oneOfTemplate() : ""}`;
}
_filterReadOnlyProperties(properties) {
diff --git a/src/PropertyShapeDocument.d.ts b/src/PropertyShapeDocument.d.ts
index 4c38e65..3d5a483 100644
--- a/src/PropertyShapeDocument.d.ts
+++ b/src/PropertyShapeDocument.d.ts
@@ -1,10 +1,10 @@
-import { LitElement, CSSResult, TemplateResult } from 'lit-element';
-import { PropertyDocumentMixin } from './PropertyDocumentMixin.js';
+import { LitElement, CSSResult, TemplateResult } from "lit-element";
+import { PropertyDocumentMixin } from "./PropertyDocumentMixin.js";
/**
* Renders a documentation for a shape property of AMF model.
*/
-export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
+export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
readonly styles: CSSResult[];
range: any;
/**
@@ -142,7 +142,12 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* Determines if shape's range is deprecated
* @attribute
*/
- deprecated: boolean
+ deprecated: boolean;
+ /**
+ * List type mappings
+ * @attribute
+ */
+ discriminatorMapping: any;
get complexToggleLabel(): string;
@@ -172,7 +177,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* @param shape The shape object
* @returns Display name of the property
*/
- _computePropertyName(range: object, shape: object): string|undefined;
+ _computePropertyName(range: object, shape: object): string | undefined;
/**
* Computes value for `hasDisplayName` property.
@@ -210,7 +215,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* @param range Range model
* @returns Description to render.
*/
- _computeDescription(range: object): string|undefined;
+ _computeDescription(range: object): string | undefined;
/**
* Computes value for `isComplex` property.
@@ -242,7 +247,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
/**
* @returns Template for a complex shape (object/array/union)
*/
- _complexTemplate(): TemplateResult|string;
+ _complexTemplate(): TemplateResult | string;
/**
* @returns Template for a type name label
@@ -252,7 +257,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
/**
* @returns Template for the description
*/
- _descriptionTemplate(): TemplateResult|string;
+ _descriptionTemplate(): TemplateResult | string;
/**
* @returns Template for type name header
diff --git a/src/PropertyShapeDocument.js b/src/PropertyShapeDocument.js
index 876fdd0..fda42fa 100644
--- a/src/PropertyShapeDocument.js
+++ b/src/PropertyShapeDocument.js
@@ -1,9 +1,9 @@
-import { LitElement, html } from 'lit-element';
-import markdownStyles from '@advanced-rest-client/markdown-styles/markdown-styles.js';
-import '@advanced-rest-client/arc-marked/arc-marked.js';
-import '@anypoint-web-components/anypoint-button/anypoint-button.js';
-import { PropertyDocumentMixin } from './PropertyDocumentMixin.js';
-import shapeStyles from './ShapeStyles.js';
+import { LitElement, html } from "lit-element";
+import markdownStyles from "@advanced-rest-client/markdown-styles/markdown-styles.js";
+import "@advanced-rest-client/arc-marked/arc-marked.js";
+import "@anypoint-web-components/anypoint-button/anypoint-button.js";
+import { PropertyDocumentMixin } from "./PropertyDocumentMixin.js";
+import shapeStyles from "./ShapeStyles.js";
/** @typedef {import('lit-element').TemplateResult} TemplateResult */
@@ -67,15 +67,15 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
/**
* Computed value, true if current property is an union.
*/
- isUnion: { type: Boolean, reflect: true, },
+ isUnion: { type: Boolean, reflect: true },
/**
* Computed value, true if current property is an object.
*/
- isObject: { type: Boolean, reflect: true, },
+ isObject: { type: Boolean, reflect: true },
/**
* Computed value, true if current property is an array.
*/
- isArray: { type: Boolean, reflect: true, },
+ isArray: { type: Boolean, reflect: true },
/**
* Computed value, true if current property is an array and the item
* is a scalar.
@@ -84,7 +84,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
/**
* Computed value, true if current property is one of.
*/
- isOneOf: { type: Boolean, reflect: true, },
+ isOneOf: { type: Boolean, reflect: true },
/**
* Computed value, true if this property contains a complex
* structure. It is computed when the property is and array,
@@ -137,7 +137,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* view. To be used with mobile rendering or when the
* components occupies only small part of the screen.
*/
- narrow: { type: Boolean, reflect: true, },
+ narrow: { type: Boolean, reflect: true },
/**
* When set it removes actions bar from the examples render.
*/
@@ -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 },
};
}
@@ -174,7 +178,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
this._shape = value;
this._shapeChanged(value);
this._shapeRangeChanged(value, this.range);
- this.requestUpdate('shape', old);
+ this.requestUpdate("shape", old);
}
get range() {
@@ -189,7 +193,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
this._range = value;
this._rangeChanged(value);
this._shapeRangeChanged(this._shape, value);
- this.requestUpdate('range', old);
+ this.requestUpdate("range", old);
}
get parentTypeName() {
@@ -203,11 +207,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
}
this._parentTypeName = value;
this.hasParentTypeName = !!value;
- this.requestUpdate('hasParentTypeName', old);
+ this.requestUpdate("hasParentTypeName", old);
}
get complexToggleLabel() {
- return this.opened ? 'Hide' : 'Show';
+ return this.opened ? "Hide" : "Show";
}
get _renderToggleButton() {
@@ -224,29 +228,30 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
const dataKey = this._getAmfKey(this.ns.w3.shacl.datatype);
let type = this._ensureArray(item[dataKey]);
[type] = type;
- let typed = String(type['@id']);
- typed = typed.replace(this.ns.w3.xmlSchema.key, '');
- typed = typed.replace(this.ns.aml.vocabularies.shapes.toString(), '');
+ let typed = String(type["@id"]);
+ typed = typed.replace(this.ns.w3.xmlSchema.key, "");
+ typed = typed.replace(this.ns.aml.vocabularies.shapes.toString(), "");
const stLetter = typed[0].toUpperCase();
return `${stLetter}${typed.substr(1)}`;
} catch (_) {
- return 'Unknown';
+ return "Unknown";
}
}
constructor() {
super();
- this.avroValue = undefined
- this.defaultValue = undefined
- this.size = undefined
- this.namespace = undefined
- this.aliases = undefined
+ this.avroValue = undefined;
+ this.defaultValue = undefined;
+ this.size = undefined;
+ this.namespace = undefined;
+ this.aliases = undefined;
this.hasDisplayName = false;
this.hasParentTypeName = false;
this.hasPropertyDescription = false;
this.narrow = false;
this.renderReadOnly = false;
this.deprecated = false;
+ this.discriminatorMapping = undefined;
}
connectedCallback() {
@@ -271,9 +276,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
this.range = this._computeRange(shape);
this.isRequired = this._computeIsRequired(shape);
this.shapeDescription = this._computeDescription(shape);
- this.hasShapeDescription = this._computeHasStringValue(
- this.shapeDescription
- );
+ this.hasShapeDescription = this._computeHasStringValue(this.shapeDescription);
}
/**
@@ -292,9 +295,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
_rangeChanged(range) {
this.propertyDescription = this._computeDescription(range);
- this.hasPropertyDescription = this._computeHasStringValue(
- this.propertyDescription
- );
+ this.hasPropertyDescription = this._computeHasStringValue(this.propertyDescription);
this.isUnion = this._computeIsUnion(range);
this.isObject = this._computeIsObject(range);
this.isArray = this._computeIsArray(range);
@@ -303,17 +304,8 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
this.isAnyOf = this._computeIsAnyOf(range);
this.isOneOf = this._computeIsOneOf(range);
this.isAllOf = this._computeIsAllOf(range);
- this.isComplex = this._computeIsComplex(
- this.isUnion,
- this.isObject,
- this.isArray,
- this.isAnyOf,
- this.isOneOf,
- this.isAllOf
- );
- this.isScalarArray = this.isArray
- ? this._computeIsScalarArray(range)
- : false;
+ this.isComplex = this._computeIsComplex(this.isUnion, this.isObject, this.isArray, this.isAnyOf, this.isOneOf, this.isAllOf);
+ this.isScalarArray = this.isArray ? this._computeIsScalarArray(range) : false;
this._evaluateGraph();
}
@@ -321,23 +313,20 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
this.displayName = this._computeDisplayName(range, shape);
this.parentName = this.isObject ? this._computeParentName(range, shape) : undefined;
this.propertyName = this._computePropertyName(range, shape);
- this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape)
- const {size,namespace,aliases, defaultValue} = this._computeAvroProperties(range, shape)
- this.size = size
- this.namespace = namespace
- this.aliases = aliases
- this.defaultValue = defaultValue
-
- this.hasDisplayName = this._computeHasDisplayName(
- this.displayName,
- this.propertyName
- );
+ this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape);
+ const { size, namespace, aliases, defaultValue } = this._computeAvroProperties(range, shape);
+ this.size = size;
+ this.namespace = namespace;
+ this.aliases = aliases;
+ this.defaultValue = defaultValue;
+
+ this.hasDisplayName = this._computeHasDisplayName(this.displayName, this.propertyName);
this.propertyDataType = this._computeObjectDataType(range, shape);
this.deprecated = Boolean(this._computeIsDeprecated(range));
}
_computeIsDeprecated(range) {
- return this._getValue(range, this._getAmfKey(this.ns.aml.vocabularies.shapes.deprecated))
+ return this._getValue(range, this._getAmfKey(this.ns.aml.vocabularies.shapes.deprecated));
}
_computeObjectDataType(range, shape) {
@@ -362,32 +351,20 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
}
if (shape) {
shape = this._resolve(shape);
- if (
- this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)
- ) {
+ if (this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)) {
// https://www.mulesoft.org/jira/browse/APIC-289
- let name = this._getValue(
- shape,
- this.ns.aml.vocabularies.apiContract.paramName
- );
+ let name = this._getValue(shape, this.ns.aml.vocabularies.apiContract.paramName);
if (!name) {
name = this._getValue(shape, this.ns.aml.vocabularies.core.name);
}
return String(name);
}
- if (
- this._hasType(shape, this.ns.w3.shacl.PropertyShape) ||
- this._hasType(shape, this.ns.aml.vocabularies.shapes.NilShape) ||
- this._hasType(shape, this.ns.aml.vocabularies.shapes.AnyShape)
- ) {
- const name = /** @type string */ (this._getValue(
- shape,
- this.ns.w3.shacl.name
- ));
+ if (this._hasType(shape, this.ns.w3.shacl.PropertyShape) || this._hasType(shape, this.ns.aml.vocabularies.shapes.NilShape) || this._hasType(shape, this.ns.aml.vocabularies.shapes.AnyShape)) {
+ const name = /** @type string */ (this._getValue(shape, this.ns.w3.shacl.name));
if (name === undefined) {
- return undefined
+ return undefined;
}
- if (name && name.indexOf('amf_inline_type') === 0) {
+ if (name && name.indexOf("amf_inline_type") === 0) {
return undefined;
}
return String(name);
@@ -396,10 +373,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
if (range) {
range = this._resolve(range);
const name = this._getValue(range, this.ns.w3.shacl.name);
- if (
- name === 'items' &&
- this._hasType(shape, this.ns.aml.vocabularies.shapes.ScalarShape)
- ) {
+ if (name === "items" && this._hasType(shape, this.ns.aml.vocabularies.shapes.ScalarShape)) {
return undefined;
}
return String(name);
@@ -418,20 +392,16 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
if (!shape && !range) {
return undefined;
}
- let result
+ let result;
if (shape) {
shape = this._resolve(shape);
- result = /** @type string */ (this._getValue(
- shape,
- this.ns.aml.vocabularies.shapes[prop]
- ));
-
+ result = /** @type string */ (this._getValue(shape, this.ns.aml.vocabularies.shapes[prop]));
}
if (range && !result) {
range = this._resolve(range);
result = this._getValue(range, this.ns.aml.vocabularies.shapes[prop]);
}
- return result ? String(result): undefined;
+ return result ? String(result) : undefined;
}
/**
@@ -445,21 +415,21 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
if (!shape && !range) {
return undefined;
}
- const defaultValueKey = this.ns.w3.shacl.defaultValue
- let result
+ const defaultValueKey = this.ns.w3.shacl.defaultValue;
+ let result;
if (shape) {
shape = this._resolve(shape);
- if(shape[defaultValueKey]){
- result = this._getValue(shape[defaultValueKey][0], this.ns.aml.vocabularies.data.value)
+ if (shape[defaultValueKey]) {
+ result = this._getValue(shape[defaultValueKey][0], this.ns.aml.vocabularies.data.value);
}
}
if (range && !result) {
range = this._resolve(range);
- if(range[defaultValueKey]){
- result = this._getValue(range[defaultValueKey], this.ns.aml.vocabularies.data.value)
+ if (range[defaultValueKey]) {
+ result = this._getValue(range[defaultValueKey], this.ns.aml.vocabularies.data.value);
}
}
- return result ? String(result): undefined;
+ return result ? String(result) : undefined;
}
/**
@@ -470,14 +440,14 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* @return {Object|undefined} Size,namespace,aliases,defaultValue of the property (only when has avroValues)
*/
_computeAvroProperties(range, shape) {
- if(!this.avroValue){
- return {size:undefined, namespace:undefined, aliases:undefined, defaultValue:undefined}
+ if (!this.avroValue) {
+ return { size: undefined, namespace: undefined, aliases: undefined, defaultValue: undefined };
}
- const size = this._computeAvroProperty(range,shape,"size")
- const namespace = this._computeAvroProperty(range,shape,"namespace")
- const aliases = this._computeAvroProperty(range,shape,"aliases")
- const defaultValue = this._computeAvroDefaultValue(range,shape)
- return {size, namespace, aliases, defaultValue}
+ const size = this._computeAvroProperty(range, shape, "size");
+ const namespace = this._computeAvroProperty(range, shape, "namespace");
+ const aliases = this._computeAvroProperty(range, shape, "aliases");
+ const defaultValue = this._computeAvroDefaultValue(range, shape);
+ return { size, namespace, aliases, defaultValue };
}
/**
@@ -486,19 +456,18 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* @param {Object} data Range object of current shape.
*/
_computeAvroSourceMap(data) {
- try{
- const sourcesKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources)
- const avroSchemaKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.avroSchema)
- const valueKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.value)
- if(data[sourcesKey] && data[sourcesKey][0][avroSchemaKey]){
- const avroValues = this._ensureArray(data[sourcesKey][0][avroSchemaKey])
- return avroValues[0][valueKey][0]['@value']
+ try {
+ const sourcesKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources);
+ const avroSchemaKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.avroSchema);
+ const valueKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.value);
+ if (data[sourcesKey] && data[sourcesKey][0][avroSchemaKey]) {
+ const avroValues = this._ensureArray(data[sourcesKey][0][avroSchemaKey]);
+ return avroValues[0][valueKey][0]["@value"];
}
- return undefined
- }catch(_){
- return undefined
+ return undefined;
+ } catch (_) {
+ return undefined;
}
-
}
/**
@@ -508,17 +477,14 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* @param {Object} shape The shape object
* @return {Object} Size of the property
*/
- _computeAvroShapeRangeSourceMap(range,shape) {
- const shapeValue = this._computeAvroSourceMap(shape)
- if(shapeValue){
- return shapeValue
- }
- return this._computeAvroSourceMap(range)
+ _computeAvroShapeRangeSourceMap(range, shape) {
+ const shapeValue = this._computeAvroSourceMap(shape);
+ if (shapeValue) {
+ return shapeValue;
+ }
+ return this._computeAvroSourceMap(range);
}
-
-
-
/**
* Computes value for `hasDisplayName` property.
* Indicates that `displayName` has been defined in the API specification.
@@ -541,10 +507,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
}
_toBoolean(value) {
- if (typeof value === 'boolean') {
- return value
+ if (typeof value === "boolean") {
+ return value;
}
- return value === 'true'
+ return value === "true";
}
/**
@@ -561,10 +527,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
}
shape = this._resolve(shape);
if (this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)) {
- const required = this._getValue(
- shape,
- this.ns.aml.vocabularies.apiContract.required
- )
+ const required = this._getValue(shape, this.ns.aml.vocabularies.apiContract.required);
return this._toBoolean(required);
}
const data = this._getValue(shape, this.ns.w3.shacl.minCount);
@@ -613,10 +576,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
if (!range) {
return undefined;
}
- return /** @type string */ (this._getValue(
- range,
- this.ns.aml.vocabularies.core.description
- ));
+ return /** @type string */ (this._getValue(range, this.ns.aml.vocabularies.core.description));
}
/**
@@ -643,24 +603,17 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
if (!amf || !range) {
return;
}
- const sKey = this._getAmfKey(
- this.ns.aml.vocabularies.docSourceMaps.sources
- );
+ const sKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources);
const maps = this._ensureArray(range[sKey]);
if (!maps) {
return;
}
- const dKey = this._getAmfKey(
- this.ns.aml.vocabularies.docSourceMaps.declaredElement
- );
+ const dKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.declaredElement);
const dElm = this._ensureArray(maps[0][dKey]);
if (!dElm) {
return;
}
- const id = this._getValue(
- dElm[0],
- this.ns.aml.vocabularies.docSourceMaps.element
- );
+ const id = this._getValue(dElm[0], this.ns.aml.vocabularies.docSourceMaps.element);
this._targetTypeId = id;
const type = this._getType(amf, id);
if (!type) {
@@ -677,19 +630,19 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
}
_navigateType() {
- const e = new CustomEvent('api-navigation-selection-changed', {
+ const e = new CustomEvent("api-navigation-selection-changed", {
bubbles: true,
composed: true,
detail: {
selected: this._targetTypeId,
- type: 'type',
+ type: "type",
},
});
this.dispatchEvent(e);
}
_linkKeydown(e) {
- if (e.key === 'Enter') {
+ if (e.key === "Enter") {
this._navigateType();
}
}
@@ -715,12 +668,12 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
_getParentTypeName() {
if (this.isArray) {
- return 'item'
+ return "item";
}
- if(this.isObject){
- return this.parentName
+ if (this.isObject) {
+ return this.parentName;
}
- return this.displayName
+ return this.displayName;
}
/**
@@ -728,7 +681,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
*/
_complexTemplate() {
if (!this.isComplex || !this.opened || this.isScalarArray) {
- return '';
+ return "";
}
const range = this._resolve(this.range);
const parentTypeName = this._getParentTypeName();
@@ -748,15 +701,15 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
>`;
}
- _getTypeLabelData(){
+ _getTypeLabelData() {
const { propertyDataType, avroValue } = this;
- if(avroValue==='map'){
- return {dataType:'Map',customValue:false}
+ if (avroValue === "map") {
+ return { dataType: "Map", customValue: false };
}
- if(propertyDataType==='Unknown type' && avroValue){
- return {dataType:avroValue,customValue:true}
+ if (propertyDataType === "Unknown type" && avroValue) {
+ return { dataType: avroValue, customValue: true };
}
- return {dataType:propertyDataType,customValue:false}
+ return { dataType: propertyDataType, customValue: false };
}
/**
@@ -764,19 +717,12 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
*/
_getTypeNameTemplate() {
const { isScalarArray } = this;
- let {dataType} = this._getTypeLabelData();
+ let { dataType } = this._getTypeLabelData();
const id = this._targetTypeId;
if (id) {
const label = this._targetTypeName;
return html`
-
${label}
+
${label}
${dataType}
`;
}
@@ -784,9 +730,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
const itemType = this.arrayScalarTypeName;
dataType = `${dataType} of ${itemType}`;
}
- return html`
-
${dataType}`;
-
+ return html`
${dataType}`;
}
/**
@@ -794,23 +738,21 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
*/
_getFixedTypeSizeAvroTemplate() {
const { size } = this;
- if(!size){
- return ''
+ if (!size) {
+ return "";
}
- return html`
-
Size: ${size}
`;
+ return html`
Size: ${size}
`;
}
/**
* @return {TemplateResult | String} Template size value (only for async / avro)
*/
_getCustomAvroValueTemplate() {
- const {customValue} = this._getTypeLabelData()
- if(!customValue){
- return ''
+ const { customValue } = this._getTypeLabelData();
+ if (!customValue) {
+ return "";
}
- return html`
-
This is a custom Avro type. You can read the definitions for this value in the specification.
`;
+ return html`
This is a custom Avro type. You can read the definitions for this value in the specification.
`;
}
/**
@@ -818,11 +760,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
*/
_getDefaultValueAvroTemplate() {
const { defaultValue } = this;
- if(!defaultValue){
- return ''
+ if (!defaultValue) {
+ return "";
}
- return html`
-
Default Value: ${defaultValue}
`;
+ return html`
Default Value: ${defaultValue}
`;
}
/**
@@ -830,35 +771,29 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
*/
_getTypeNamespaceAvroTemplate() {
const { namespace } = this;
- if(!namespace){
- return ''
+ if (!namespace) {
+ return "";
}
- return html`
-
Namespace: ${namespace}
`;
+ return html`
Namespace: ${namespace}
`;
}
/**
* @return {TemplateResult | String} Template namespace value (only for async / avro)
*/
_getTypeAliasesAvroTemplate() {
- const { aliases } = this;
- if (!aliases) {
- return '';
- }
- return html`
-
- Aliases: ${aliases.map(alias => html`${alias}`)}
-
- `;
-}
-
+ const { aliases } = this;
+ if (!aliases) {
+ return "";
+ }
+ return html`
Aliases: ${aliases.map((alias) => html`${alias}`)}
`;
+ }
/**
* @return {TemplateResult|string} Template for the description
*/
_descriptionTemplate() {
if (!(this.hasPropertyDescription || this.hasShapeDescription)) {
- return '';
+ return "";
}
return html`
@@ -874,18 +809,8 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
const { isComplex, _renderToggleButton } = this;
return isComplex
? html``
: this._headerNameTemplate();
}
@@ -894,46 +819,66 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
* @return {TemplateResult} Template for a type name label
*/
_headerNameTemplate() {
- const {
- hasDisplayName,
- displayName,
- propertyName,
- parentTypeName,
- hasParentTypeName
- } = this;
-
- return html` ${hasDisplayName
- ? html`${displayName}
`
- : ''}
+ const { hasDisplayName, displayName, propertyName, parentTypeName, hasParentTypeName } = this;
+
+ return html` ${hasDisplayName ? html`${displayName}
` : ""}
${propertyName
? html`
- ${parentTypeName}.
+ ${parentTypeName}.
${propertyName}
`
- : ''}`;
+ : ""}`;
}
_deprecatedWarningTemplate() {
if (!this.deprecated) {
- return '';
+ return "";
+ }
+ return html`Warning: Deprecated
`;
+ }
+
+ _navigateItem(e) {
+ e.preventDefault();
+ const data = e.composedPath()[0].dataset;
+ if (!data.id || !data.shapeType) {
+ return;
}
- return html`Warning: Deprecated
`
+ 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`
+ ${mappings.map((mapping) => {
+ const name = this._getValue(mapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValue));
+ const target = this._getLinkValue(mapping, this._getAmfKey(this.ns.aml.vocabularies.shapes.discriminatorValueTarget));
+ return html`- ${name}
`;
+ })}
+
`;
}
_noNameAvroClass() {
- const {
- hasDisplayName,
- propertyName,
- isComplex,
- avroValue,
- _renderToggleButton
- } = this;
- if(!hasDisplayName && !propertyName && isComplex && avroValue && _renderToggleButton){
- return ' no-name'
+ const { hasDisplayName, propertyName, isComplex, avroValue, _renderToggleButton } = this;
+ if (!hasDisplayName && !propertyName && isComplex && avroValue && _renderToggleButton) {
+ return " no-name";
}
- return ''
+ return "";
}
/**
@@ -945,36 +890,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
${this._headerTemplate()}
- ${this._getTypeNameTemplate()}
- ${this.isRequired
- ? html`Required`
- : ''}
- ${this.isEnum
- ? html`Enum`
- : ''}
- ${this.isReadOnly
- ? html`Read only`
- : ''}
+ ${this._getTypeNameTemplate()} ${this.isRequired ? html`Required` : ""}
+ ${this.isEnum ? html`Enum` : ""} ${this.isReadOnly ? html`Read only` : ""}
- ${this._getCustomAvroValueTemplate()}
- ${this._getDefaultValueAvroTemplate()}
- ${this._getFixedTypeSizeAvroTemplate()}
- ${this._getTypeNamespaceAvroTemplate()}
- ${this._getTypeAliasesAvroTemplate()}
- ${this._deprecatedWarningTemplate()}
- ${this._descriptionTemplate()}
+ ${this._getCustomAvroValueTemplate()} ${this._getDefaultValueAvroTemplate()} ${this._getFixedTypeSizeAvroTemplate()} ${this._getTypeNamespaceAvroTemplate()} ${this._getTypeAliasesAvroTemplate()} ${this._deprecatedWarningTemplate()}
+ ${this._descriptionTemplate()} ${this._typesMappingsTemplate()}