Skip to content

Feat/w 15607551/show servers name #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@api-components/api-method-documentation",
"description": "A HTTP method documentation build from AMF model",
"version": "5.2.21",
"version": "5.2.22",
"license": "Apache-2.0",
"main": "index.js",
"module": "index.js",
Expand Down
26 changes: 26 additions & 0 deletions src/ApiMethodDocumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
* This is a map of the type name to the binding name.
*/
bindings: {type: Array},
/**
* Adds a servers to async API
*
* @param {string} url - The URL of the server.
* @param {object} [description] - An object containing a string `description` property.
*/
servers: {type:Array},
_servers: {type:Array},
};
}

Expand Down Expand Up @@ -335,6 +343,21 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
this._processServerInfo();
}

get servers() {
return this._servers;
}

set servers(value) {

const old = this._servers;
/* istanbul ignore if */
if (old === value) {
return;
}
this._servers = value;
this.requestUpdate('servers', old);
}

get _titleHidden() {
if (!this.noTryIt) {
return false;
Expand Down Expand Up @@ -897,6 +920,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
<api-url
.amf="${this.amf}"
.server="${this.server}"
.servers="${this.servers}"
.endpoint="${this.endpoint}"
.apiVersion="${this.apiVersion}"
.baseUri="${this.baseUri}"
Expand Down Expand Up @@ -1225,6 +1249,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
amf,
compatibility,
graph,
servers
} = this;
return html`
<div class="callback-section">
Expand All @@ -1233,6 +1258,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
.amf="${amf}"
.method="${method}"
.endpoint="${endpoint}"
.servers="${servers}"
?compatibility="${compatibility}"
?graph="${graph}"
noTryit
Expand Down
40 changes: 27 additions & 13 deletions src/ApiUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
* Optional, operation id that is render only for async api
*/
operationId:{type: String},
/**
* Adds a servers to async API
*
* @param {string} url - The URL of the server.
* @param {object} [description] - An object containing a string `description` property.
*/
servers: {type:Array},
_servers: {type:Array},
_url: { type: String },
_method: { type: String },
_protocol: { type: String },
Expand Down Expand Up @@ -117,6 +125,19 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
this._updateUrl();
}

get servers() {
return this._servers;
}

set servers(value) {
const old = this._servers;
if (old === value) {
return;
}
this._servers = value;
this.requestUpdate('servers', old);
}

get endpoint() {
return this._endpoint;
}
Expand Down Expand Up @@ -173,16 +194,11 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {


get asyncServersNames(){
if(!this.endpoint){
return ''
}
const endpoint = Array.isArray(this.endpoint) ? this.endpoint[0]: this.endpoint
const apiContractServerKey = this._getAmfKey( this.ns.aml.vocabularies.apiContract.server)
const endpointServers = this._ensureArray(endpoint[apiContractServerKey])
const servers = this._ensureArray(this.servers)

// try to find servers in channel level
if(endpointServers){
return endpointServers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name)));
if(servers){
return servers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name)));
}

// try to find root server (only one) that is received by property
Expand Down Expand Up @@ -278,11 +294,9 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
}

renderAsyncApi(asyncServersNames){
const { url, _endpoint } = this;
if(!_endpoint){
return ''
}
return html`
const { url } = this;

return html`
<style>${this.styles}</style>
<section class="async-servers-names-area">
${this._getMethodTemplate()}
Expand Down
4 changes: 2 additions & 2 deletions test/api-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ describe('<api-url>', () => {
await nextFrame();
await nextFrame();

const url = 'mqtt://api.streetlights.smartylighting.com:{port}'
assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), url);
const expectedServer = 'production'
assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), expectedServer);
});
});
});
Expand Down
Loading