Skip to content

Commit a9f82ac

Browse files
Merge pull request #81 from advanced-rest-client/feat/avro
Feat/avro
2 parents d479490 + 537388a commit a9f82ac

File tree

10 files changed

+3014
-63
lines changed

10 files changed

+3014
-63
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: 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.29",
4+
"version": "4.2.30",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",
@@ -99,4 +99,4 @@
9999
"eslint --fix"
100100
]
101101
}
102-
}
102+
}

src/ApiTypeDocument.js

Lines changed: 14 additions & 6 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]
@@ -819,6 +819,14 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
819819
return this._multiTypeTemplate({ label, items, typeName, selected, selectTypeCallback, type });
820820
}
821821

822+
_getItemLabel(item){
823+
if(item.label==='Unknown type' && item.avroValue){
824+
return item.avroValue
825+
}
826+
return item.label
827+
828+
}
829+
822830
/**
823831
*
824832
* @param {Object} args
@@ -843,8 +851,8 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
843851
aria-pressed="${selected === index ? 'true' : 'false'}"
844852
@click="${selectTypeCallback}"
845853
?compatibility="${this.compatibility}"
846-
title="Select ${item.label} type"
847-
>${item.label}</anypoint-button
854+
title="Select ${this._getItemLabel(item)} type"
855+
>${this._getItemLabel(item)}</anypoint-button
848856
>`
849857
)}
850858
</div>

src/PropertyDocumentMixin.js

Lines changed: 38 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
}
@@ -356,6 +361,37 @@ const mxFunction = (base) => {
356361
return this._hasProperty(range, this.ns.w3.shacl.and);
357362
}
358363

364+
/**
365+
* Computes source values of the property. Only for async / avro
366+
*
367+
* @param {Object} data Range object of current shape.
368+
*/
369+
_computeAvroSourceMap(data) {
370+
try{
371+
const sourcesKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources)
372+
const avroSchemaKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.avroSchema)
373+
const valueKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.value)
374+
if(data[sourcesKey] && data[sourcesKey][0][avroSchemaKey]){
375+
const avroValues = this._ensureArray(data[sourcesKey][0][avroSchemaKey])
376+
return avroValues[0][valueKey][0]['@value']
377+
}
378+
return undefined
379+
}catch(_){
380+
return undefined
381+
}
382+
383+
}
384+
385+
/**
386+
* Computes source values of the property. Only for async / avro
387+
*
388+
* @param {Object} data Range object of current shape.
389+
* @return {Object} Size of the property
390+
*/
391+
_computeAvroShapeRangeSourceMap(data) {
392+
return this._computeAvroSourceMap(data)
393+
}
394+
359395
/**
360396
* Computes list of type labels to render.
361397
*
@@ -369,6 +405,7 @@ const mxFunction = (base) => {
369405
return undefined;
370406
}
371407
return list.map((obj) => {
408+
const avroValue = this._computeAvroShapeRangeSourceMap(obj) || null
372409
let item = obj;
373410
if (Array.isArray(item)) {
374411
[item] = item;
@@ -419,6 +456,7 @@ const mxFunction = (base) => {
419456
isArray,
420457
isType,
421458
label,
459+
avroValue
422460
};
423461
});
424462
}

0 commit comments

Comments
 (0)