Skip to content

Commit d479490

Browse files
authored
Merge pull request #78 from advanced-rest-client/fix/W-14874965/-swagger-Json-file-not-displaying-valid-Json-examples-in-response-in-Design-center-and-Exchange
[W-14874965] Swagger-Json-file-not-displaying-valid-Json-examples-in-response-in-Design-center-and-Exchange
2 parents a2d6516 + 5b5055d commit d479490

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 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.28",
4+
"version": "4.2.29",
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.6",
31+
"@api-components/amf-helper-mixin": "^4.5.24",
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",
@@ -99,4 +99,4 @@
9999
"eslint --fix"
100100
]
101101
}
102-
}
102+
}

src/ApiTypeDocument.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,26 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
560560
if (Array.isArray(item)) {
561561
return item;
562562
}
563-
const key = this._getAmfKey(this.ns.w3.shacl.property);
564-
return this._filterReadOnlyProperties(this._ensureArray(item[key]));
563+
564+
const propertyKey = this._getAmfKey(this.ns.w3.shacl.property);
565+
const itemProperties = this._ensureArray(item[propertyKey])
566+
const additionalPropertiesKey = this._getAmfKey(this.ns.w3.shacl.additionalPropertiesSchema);
567+
568+
// If the item doesn't have additional properties, filter the read-only properties and return
569+
if (!item[additionalPropertiesKey]) {
570+
return this._filterReadOnlyProperties(itemProperties)
571+
}
572+
573+
const additionalPropertiesSchema = this._ensureArray(item[additionalPropertiesKey])
574+
575+
// If the item does have additional properties, ensure they are in an array
576+
const additionalProperties = this._ensureArray(additionalPropertiesSchema[0][propertyKey])
577+
578+
// Combine the item's properties and additional properties
579+
const combinedProperties = [...itemProperties, ...additionalProperties]
580+
581+
// Filter the read-only properties and return
582+
return this._filterReadOnlyProperties(combinedProperties);
565583
}
566584

567585
/**
@@ -702,7 +720,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
702720
/**
703721
* @return {TemplateResult} Templates for object properties
704722
*/
705-
_arrayTemplate() {
723+
_arrayTemplate() {
706724
const items = this._computeArrayProperties(this._resolvedType) || [];
707725
const documents = items.map(
708726
(item) => html`
@@ -742,9 +760,9 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
742760
<span>Array of:</span>
743761
<div class="array-children">
744762
${documents}
745-
</div>`
763+
</div>`
746764
: html`${documents}`
747-
}
765+
}
748766
749767
${this._arrayPropertiesTemplate()}
750768
`;
@@ -758,7 +776,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
758776
const selected = this.selectedUnion;
759777
const selectTypeCallback = this._selectType.bind(this, 'selectedUnion');
760778
const key = this._getAmfKey(this.ns.aml.vocabularies.shapes.anyOf);
761-
const type = this._computeProperty(this._resolvedType, key,selected);
779+
const type = this._computeProperty(this._resolvedType, key, selected);
762780
const typeName = 'union'
763781
const label = 'Any of'
764782
return this._multiTypeTemplate({ label, items, typeName, selected, selectTypeCallback, type });
@@ -855,10 +873,10 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
855873
}
856874
return html` ${items.map(
857875
(item) => html` ${item.label
858-
? html`<p class="inheritance-label">
876+
? html`<p class="inheritance-label">
859877
Properties inherited from <b>${item.label}</b>.
860878
</p>`
861-
: html`<p class="inheritance-label">Properties defined inline.</p>`}
879+
: html`<p class="inheritance-label">Properties defined inline.</p>`}
862880
<api-type-document
863881
class="and-document"
864882
.amf="${this.amf}"
@@ -887,12 +905,12 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
887905
return html`<style>${this.styles}</style>
888906
<section class="examples" ?hidden="${!this._renderMainExample}">
889907
${this.shouldRenderMediaSelector
890-
? html`<div class="media-type-selector">
908+
? html`<div class="media-type-selector">
891909
<span>Media type:</span>
892910
${mediaTypes.map((item, index) => {
893-
const selected = this.selectedMediaType === index;
894-
const pressed = selected ? 'true' : 'false';
895-
return html`<anypoint-button
911+
const selected = this.selectedMediaType === index;
912+
const pressed = selected ? 'true' : 'false';
913+
return html`<anypoint-button
896914
part="content-action-button"
897915
class="media-toggle"
898916
data-index="${index}"
@@ -903,9 +921,9 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
903921
title="Select ${item} media type"
904922
>${item}</anypoint-button
905923
>`;
906-
})}
924+
})}
907925
</div>`
908-
: ''}
926+
: ''}
909927
910928
<api-resource-example-document
911929
.amf="${this.amf}"

0 commit comments

Comments
 (0)