Skip to content

Commit ea9950f

Browse files
Merge pull request #56 from advanced-rest-client/feat/W-15520183/show-message-id
feat: show message id for async api
2 parents ba5b807 + 82c9b48 commit ea9950f

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
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-body-document",
33
"description": "A component to render HTTP method body documentation based on AMF model",
4-
"version": "4.4.8",
4+
"version": "4.4.9",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiBodyDocumentElement.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
126126
* `api-navigation-selection-changed` when clicked.
127127
*/
128128
graph: { type: Boolean },
129+
/**
130+
* Method's endpoint definition as a
131+
* `http://raml.org/vocabularies/http#endpoint` of AMF model.
132+
*/
133+
endpoint: { type: Object },
129134
_hasObjectExamples: { type: Boolean },
130135
/**
131136
* When enabled it renders properties that are marked as `readOnly`
@@ -153,6 +158,24 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
153158
this._renderMediaSelector = this._computeRenderMediaSelector(value);
154159
}
155160

161+
get messageId() {
162+
try {
163+
const apiContractsupportedOperation = this._getAmfKey(this.ns.aml.vocabularies.apiContract.supportedOperation)
164+
const apiContractExpects = this._getAmfKey(this.ns.aml.vocabularies.apiContract.expects)
165+
const apiContractMessageId = this._getAmfKey(this.ns.aml.vocabularies.apiContract.messageId)
166+
const coreName = this._getAmfKey(this.ns.schema.name)
167+
const expects = this.endpoint[apiContractsupportedOperation][0][apiContractExpects][0];
168+
const messageId = expects[apiContractMessageId] || expects[coreName]
169+
return messageId[0]['@value']
170+
} catch(e) {
171+
return ''
172+
}
173+
}
174+
175+
get hasMessageId() {
176+
return this._isAsyncAPI(this.amf) && !!this.messageId
177+
}
178+
156179
get _selectedBody() {
157180
return this.__selectedBody;
158181
}
@@ -245,11 +268,16 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
245268
const dataTypeKey = this._getAmfKey(this.ns.w3.shacl.datatype)
246269
const descriptionKey = this._getAmfKey(this.ns.aml.vocabularies.core.description)
247270

248-
this._bindings = value?.map((item) => ({
249-
key: item[messageKey][0][descriptionKey][0]['@value'],
250-
dataType: item[messageKey][0][dataTypeKey] ? this._getDataType(item[messageKey][0][dataTypeKey][0]['@id']) : 'any', // integer, number, long, float, double, boolean
251-
bindingType: this._getValue(item, typeKey), // kafka, AMQP, etc
252-
}))
271+
try {
272+
this._bindings = value?.map((item) => ({
273+
key: item[messageKey][0][descriptionKey][0]['@value'],
274+
dataType: item[messageKey][0][dataTypeKey] ? this._getDataType(item[messageKey][0][dataTypeKey][0]['@id']) : 'any', // integer, number, long, float, double, boolean
275+
bindingType: this._getValue(item, typeKey), // kafka, AMQP, etc
276+
}))
277+
} catch(e) {
278+
console.log(e)
279+
}
280+
253281
}
254282

255283
_getDataType(type){
@@ -561,7 +589,9 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
561589
amf,
562590
narrow,
563591
renderReadOnly,
564-
bodyDescription
592+
bodyDescription,
593+
hasMessageId,
594+
messageId
565595
} = this;
566596
const hasBodyName = !!_bodyName;
567597
const hasDescription = !!_description;
@@ -575,6 +605,7 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
575605
this._mediaTypesTemplate() :
576606
html`<span class="media-type-label">${_selectedMediaType}</span>`}
577607
</div>
608+
${hasMessageId ? html`<div class="message-id-container">Message ID <span class="message-id-tag">${messageId}</span></div>` : ''}
578609
${hasBodyDescription ? html`
579610
<arc-marked .markdown="${bodyDescription}" sanitize>
580611
<div slot="markdown-html" class="markdown-html" part="markdown-html"></div>

src/Styles.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,18 @@ arc-marked {
143143
.bindings-container-list li .bindings-body > .binding-data-type {
144144
text-transform: capitalize;
145145
}
146+
147+
.message-id-container {
148+
background-color: white;
149+
font-size: 14px;
150+
padding: 1em;
151+
}
152+
153+
.message-id-tag {
154+
border: 1px solid #D67300;
155+
border-radius: 4px;
156+
padding: 4px 19px;
157+
color: #D67300;
158+
margin-left: 20px;
159+
}
146160
`;

0 commit comments

Comments
 (0)