Skip to content

Commit 72944f4

Browse files
Merge pull request #79 from advanced-rest-client/feat/W-16216524/show-original-data
Feat/w-16216524/show original data
2 parents d479490 + 70960fd commit 72944f4

File tree

9 files changed

+2908
-14
lines changed

9 files changed

+2908
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ dist/
6161
# AMF models
6262
/demo/*.json
6363
!demo/apis.json
64+
!demo/avro.json
65+
!demo/avro2.json
6466

6567
.idea/

demo/avro.json

Lines changed: 617 additions & 0 deletions
Large diffs are not rendered by default.

demo/avro2.json

Lines changed: 2053 additions & 0 deletions
Large diffs are not rendered by default.

demo/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ApiDemo extends ApiDemoPage {
2828

2929
_navChanged(e) {
3030
const { selected, type } = e.detail;
31-
this.hasType = false;
31+
this.hasType = false;
3232
this.mediaType = undefined;
3333
this.mediaTypes = undefined;
3434

@@ -40,7 +40,7 @@ class ApiDemo extends ApiDemoPage {
4040
}
4141

4242
setBodyData(id) {
43-
const webApi = this._computeWebApi(this.amf);
43+
const webApi = this._computeWebApi(this.amf) || this._computeApi(this.amf);
4444
const method = this._computeMethodModel(webApi, id);
4545
const expects = this._computeExpects(method);
4646
const payload = expects ? this._computePayload(expects)[0] : {};
@@ -100,6 +100,9 @@ class ApiDemo extends ApiDemoPage {
100100
_apiListTemplate() {
101101
return [
102102
['demo-api', 'Demo API'],
103+
['avro', 'avro'],
104+
['avro2', 'avro2'],
105+
['jldAsync26', 'jldAsync26'],
103106
['APIC-649', 'Deprecated properties'],
104107
['APIC-429', 'APIC 429'],
105108
['read-only-properties', 'Read Only Properties API'],

package-lock.json

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

src/ApiTypeDocument.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,9 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
560560
if (Array.isArray(item)) {
561561
return item;
562562
}
563-
563+
564564
const propertyKey = this._getAmfKey(this.ns.w3.shacl.property);
565-
const itemProperties = this._ensureArray(item[propertyKey])
565+
const itemProperties = this._ensureArray(item[propertyKey]||[])
566566
const additionalPropertiesKey = this._getAmfKey(this.ns.w3.shacl.additionalPropertiesSchema);
567567

568568
// If the item doesn't have additional properties, filter the read-only properties and return
@@ -571,9 +571,9 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
571571
}
572572

573573
const additionalPropertiesSchema = this._ensureArray(item[additionalPropertiesKey])
574-
574+
575575
// If the item does have additional properties, ensure they are in an array
576-
const additionalProperties = this._ensureArray(additionalPropertiesSchema[0][propertyKey])
576+
const additionalProperties = this._ensureArray(additionalPropertiesSchema[0][propertyKey] || additionalPropertiesSchema[0])
577577

578578
// Combine the item's properties and additional properties
579579
const combinedProperties = [...itemProperties, ...additionalProperties]

src/PropertyDocumentMixin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const mxFunction = (base) => {
172172
return 'String';
173173
case this._getAmfKey(sc.integer):
174174
case sc.integer:
175+
case sc.int:
175176
return 'Integer';
176177
case this._getAmfKey(sc.long):
177178
case sc.long:
@@ -205,6 +206,10 @@ const mxFunction = (base) => {
205206
case this._getAmfKey(rs.password):
206207
case rs.password:
207208
return 'Password';
209+
case sc.bytes:
210+
return 'Bytes'
211+
case sc.fixed:
212+
return 'Fixed'
208213
default:
209214
return 'Unknown type';
210215
}

src/PropertyShapeDocument.js

Lines changed: 211 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
3434
* `displayName` was specified in the API spec for this property.
3535
*/
3636
propertyName: { type: String },
37+
/**
38+
* A type size.
39+
* Is only used for async / avro api
40+
*/
41+
size: { type: String },
42+
/**
43+
* A type defaultValue.
44+
* Is only used for async / avro api
45+
*/
46+
defaultValue: { type: String },
47+
/**
48+
* A type namespace.
49+
* Is only used for async / avro api
50+
*/
51+
namespace: { type: String },
52+
/**
53+
* A type aliases.
54+
* Is only used for async / avro api
55+
*/
56+
aliases: { type: Array },
57+
/**
58+
* Avro original value type.
59+
* Is only used for async / avro api
60+
*/
61+
avroValue: { type: String },
3762
/**
3863
* Computed value, true if `displayName` has been defined for this
3964
* property.
@@ -211,6 +236,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
211236

212237
constructor() {
213238
super();
239+
this.avroValue = undefined
240+
this.defaultValue = undefined
241+
this.size = undefined
242+
this.namespace = undefined
243+
this.aliases = undefined
214244
this.hasDisplayName = false;
215245
this.hasParentTypeName = false;
216246
this.hasPropertyDescription = false;
@@ -290,6 +320,14 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
290320
_shapeRangeChanged(shape, range) {
291321
this.displayName = this._computeDisplayName(range, shape);
292322
this.propertyName = this._computePropertyName(range, shape);
323+
this.avroValue = this._computeAvroShapeRangeSourceMap(range, shape)
324+
const {size,namespace,aliases, defaultValue} = this._computeAvroProperties(range, shape)
325+
this.size = size
326+
this.namespace = namespace
327+
this.aliases = aliases
328+
this.defaultValue = defaultValue
329+
330+
293331
this.hasDisplayName = this._computeHasDisplayName(
294332
this.displayName,
295333
this.propertyName
@@ -369,6 +407,119 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
369407
return undefined;
370408
}
371409

410+
/**
411+
* Computes avro property. Only for async / avro
412+
*
413+
* @param {Object} range Range object of current shape.
414+
* @param {Object} shape The shape object
415+
* @return {String|undefined} Size of the property
416+
*/
417+
_computeAvroProperty(range, shape, prop) {
418+
if (!shape && !range) {
419+
return undefined;
420+
}
421+
let result
422+
if (shape) {
423+
shape = this._resolve(shape);
424+
result = /** @type string */ (this._getValue(
425+
shape,
426+
this.ns.aml.vocabularies.shapes[prop]
427+
));
428+
429+
}
430+
if (range && !result) {
431+
range = this._resolve(range);
432+
result = this._getValue(range, this.ns.aml.vocabularies.shapes[prop]);
433+
}
434+
return result ? String(result): undefined;
435+
}
436+
437+
/**
438+
* Computes avro defaultValue. Only for async / avro
439+
*
440+
* @param {Object} range Range object of current shape.
441+
* @param {Object} shape The shape object
442+
* @return {String|undefined} Size of the property
443+
*/
444+
_computeAvroDefaultValue(range, shape) {
445+
if (!shape && !range) {
446+
return undefined;
447+
}
448+
const defaultValueKey = this.ns.w3.shacl.defaultValue
449+
let result
450+
if (shape) {
451+
shape = this._resolve(shape);
452+
if(shape[defaultValueKey]){
453+
result = this._getValue(shape[defaultValueKey][0], this.ns.aml.vocabularies.data.value)
454+
}
455+
}
456+
if (range && !result) {
457+
range = this._resolve(range);
458+
if(range[defaultValueKey]){
459+
result = this._getValue(range[defaultValueKey], this.ns.aml.vocabularies.data.value)
460+
}
461+
}
462+
return result ? String(result): undefined;
463+
}
464+
465+
/**
466+
* Computes size of the property. Only for async / avro
467+
*
468+
* @param {Object} range Range object of current shape.
469+
* @param {Object} shape The shape object
470+
* @return {Object|undefined} Size,namespace,aliases,defaultValue of the property (only when has avroValues)
471+
*/
472+
_computeAvroProperties(range, shape) {
473+
if(!this.avroValue){
474+
return {size:undefined, namespace:undefined, aliases:undefined, defaultValue:undefined}
475+
}
476+
const size = this._computeAvroProperty(range,shape,"size")
477+
const namespace = this._computeAvroProperty(range,shape,"namespace")
478+
const aliases = this._computeAvroProperty(range,shape,"aliases")
479+
const defaultValue = this._computeAvroDefaultValue(range,shape)
480+
return {size, namespace, aliases, defaultValue}
481+
}
482+
483+
/**
484+
* Computes source values of the property. Only for async / avro
485+
*
486+
* @param {Object} data Range object of current shape.
487+
*/
488+
_computeAvroSourceMap(data) {
489+
try{
490+
const sourcesKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources)
491+
const avroSchemaKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.avroSchema)
492+
const valueKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.value)
493+
if(data[sourcesKey] && data[sourcesKey][0][avroSchemaKey]){
494+
const avroValues = this._ensureArray(data[sourcesKey][0][avroSchemaKey])
495+
return avroValues[0][valueKey][0]['@value']
496+
}
497+
return undefined
498+
}catch(_){
499+
return undefined
500+
}
501+
502+
}
503+
504+
/**
505+
* Computes source values of the property. Only for async / avro
506+
*
507+
* @param {Object} range Range object of current shape.
508+
* @param {Object} shape The shape object
509+
* @return {Object} Size of the property
510+
*/
511+
_computeAvroShapeRangeSourceMap(range,shape) {
512+
const shapeValue = this._computeAvroSourceMap(shape)
513+
if(shapeValue){
514+
return shapeValue
515+
}
516+
return this._computeAvroSourceMap(range)
517+
}
518+
519+
520+
521+
522+
372523
/**
373524
* Computes value for `hasDisplayName` property.
374525
* Indicates that `displayName` has been defined in the API specification.
@@ -613,9 +764,64 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
613764
const itemType = this.arrayScalarTypeName;
614765
dataType = `${dataType} of ${itemType}`;
615766
}
616-
return html`<span class="data-type">${dataType}</span>`;
767+
return html`
768+
<span class="data-type">${dataType}</span>`;
769+
617770
}
618771

772+
/**
773+
* @return {TemplateResult | String} Template size value (only for async / avro)
774+
*/
775+
_getFixedTypeSizeAvroTemplate() {
776+
const { size } = this;
777+
if(!size){
778+
return ''
779+
}
780+
return html`
781+
<div class="fixed-type-size"><span>Size: ${size}</span></div>`;
782+
}
783+
784+
/**
785+
* @return {TemplateResult | String} Template size value (only for async / avro)
786+
*/
787+
_getDefaultValueAvroTemplate() {
788+
const { defaultValue } = this;
789+
if(!defaultValue){
790+
return ''
791+
}
792+
return html`
793+
<div class="fixed-type-size"><span>Default Value: ${defaultValue}</span></div>`;
794+
}
795+
796+
/**
797+
* @return {TemplateResult | String} Template namespace value (only for async / avro)
798+
*/
799+
_getTypeNamespaceAvroTemplate() {
800+
const { namespace } = this;
801+
if(!namespace){
802+
return ''
803+
}
804+
return html`
805+
<div class="fixed-type-size"><span>Namespace: ${namespace}</span></div>`;
806+
}
807+
808+
/**
809+
* @return {TemplateResult | String} Template namespace value (only for async / avro)
810+
*/
811+
_getTypeAliasesAvroTemplate() {
812+
const { aliases } = this;
813+
if (!aliases) {
814+
return '';
815+
}
816+
return html`
817+
<div class="fixed-type-size">
818+
Aliases: ${aliases.map(alias => html`<span>${alias}</span>`)}
819+
</div>
820+
`;
821+
}
822+
823+
824+
619825
/**
620826
* @return {TemplateResult|string} Template for the description
621827
*/
@@ -716,6 +922,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
716922
>`
717923
: ''}
718924
</div>
925+
${this._getDefaultValueAvroTemplate()}
926+
${this._getFixedTypeSizeAvroTemplate()}
927+
${this._getTypeNamespaceAvroTemplate()}
928+
${this._getTypeAliasesAvroTemplate()}
719929
${this._deprecatedWarningTemplate()}
720930
${this._descriptionTemplate()}
721931
<property-range-document

src/ShapeStyles.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export default css`
134134
font-weight: var(--api-type-document-trait-data-type-font-weight, normal);
135135
}
136136
137+
.property-traits > span.fixed-type-size {
138+
padding: var(--api-type-document-trait-fixed-type-size-padding, 2px 1px);
139+
}
140+
137141
arc-marked {
138142
background-color: transparent;
139143
padding: 0;

0 commit comments

Comments
 (0)