Skip to content

Commit 8897708

Browse files
authored
[W-14588829] show examples to async a pis (#41)
* chore: add AsyncAPI example and update mediaType handling, rawOnly assignment in ApiResourceExampleDocument class * 4.3.9 * chore: add rawOnly assignment in ApiResourceExampleDocument.js
1 parent 82e78f0 commit 8897708

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-resource-example-document",
33
"description": "A viewer for examples in a resource based on AMF model",
4-
"version": "4.3.8",
4+
"version": "4.3.9",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiResourceExampleDocument.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export class ApiResourceExampleDocument extends AmfHelperMixin(LitElement) {
124124
};
125125
}
126126

127+
get isAsyncAPI () {
128+
return this._isAsyncAPI(this.amf)
129+
}
130+
127131
get hasLocalStorage() {
128132
return this._hasLocalStorage;
129133
}
@@ -184,12 +188,9 @@ export class ApiResourceExampleDocument extends AmfHelperMixin(LitElement) {
184188
*/
185189
set mediaType(value) {
186190
const old = this._mediaType;
187-
if (old === value) {
188-
return;
189-
}
190-
this._mediaType = value;
191+
this._mediaType = this.isAsyncAPI && !value ? 'application/json' : value
191192
this.requestUpdate('mediaType', old);
192-
this.isJson = this._computeIsJson(value);
193+
this.isJson = this.isAsyncAPI && !value ? true : this._computeIsJson(value)
193194
this._computeExamples();
194195
}
195196

@@ -239,7 +240,11 @@ export class ApiResourceExampleDocument extends AmfHelperMixin(LitElement) {
239240
if (old === value) {
240241
return;
241242
}
242-
this._rawOnly = value;
243+
// If async api, rawOnly is always false
244+
// rawOnly is only used for json or xml payloads
245+
// and async api payloads are not json or xml
246+
// payloads are messages with a schema
247+
this._rawOnly = this.isAsyncAPI ? false : value;
243248
this.requestUpdate('rawOnly', old);
244249
this._computeExamples();
245250
}

0 commit comments

Comments
 (0)