@api-components/api-server-selector

中文文档
0.7.2发布于 2021/10/10Apache-2.0ESM + CJS近 30 天下载 3156

一个使OAS的服务器成为选择API服务器的下拉选项的组件.

中文使用文档
文档目录10 节
  1. 版本兼容性
  2. 使用量
  3. 安装
  4. 在 html 文件内
  5. 在一个LitElement中
  6. 订阅更改事件
  7. 自定义服务器
  8. 发展
  9. 本地运行演示
  10. 运行测试

被否决

这一部分正在贬值。 代码基础已移动到 amf 组件 模块。 此模块将在 PR 1 常规文件 合并.


自定义元素使一个服务器列表在API规格中编码,由AMF模型提供动力.

Published on NPM

Tests and publishing

版本兼容性

此版本仅与AMF模式版本2(AMF parser QQ 4.0.0)相通.

使用量

安装

npm install --save @api-components/api-server-selector

在 html 文件内

<html>
  <head>
    <script type="module">
      import '@api-components/api-server-selector/api-server-selector.js';
    </script>
  </head>
  <body>
    <api-server-selector amf="..."></api-server-selector>
  </body>
</html>

在一个LitElement中

import { LitElement, html } from 'lit-element';
import '@api-components/api-server-selector/api-server-selector.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <api-server-selector .amf="${this.model}"></api-server-selector>
    `;
  }
}
customElements.define('sample-element', SampleElement);

订阅更改事件

服务器更改事件

该组件发送 apiserverchanged 服务器选择变更时的自定义事件.

element.addEventListener('apiserverchanged', function(e) {
    const { value, type } = e.detail;
    // value is the selected base URI
    // type tells whether it's a server defined value of a custom property
    // This is also the same as const { value, type } = e.target;
});

何时 Custom URL 输入字段发送的更改 api-server-changed 带有输入当前值的事件.

此外,该要素支持 onapiserverchange 事件召回函数设置器 :

element.onapiserverchange = (e) => {
  // ...
};

服务器计数已更改的事件

当一些服务器变换时会发出此事件 .

element.addEventListener('serverscountchanged', function(e) {
    const { value } = e.detail;
    // value is the number of rendered servers
});
element.onserverscountchange = (e) => {
  // ...
};

自定义服务器

有时,除API sepcification中定义的服务器外,主机应用程序可能想要定义选择器中要渲染的附加服务器列表. 这可以涉及与代用服务或模拟服务等组件合作的其他服务.

元素接受列表项为在 API 定义服务器后被插入的子项目 . 我们建议使用 anypoint-item 因为它已经用来建造取精器。 然而,它可以是任何HTML元素. 要提供清单项目,必须 slot="custom-base-uri" 属性。 要在列表中选择项目,它必须具备 value="..." 属性. 如果缺少该值, 则该项会显示, 但选择器不会在列表项上单击 .

<api-server-selector>
  <div slot="custom-base-uri">Other options</div>
  <anypoint-item slot="custom-base-uri" data-value="http://mocking.com">Mocking service</anypoint-item>
  <anypoint-item slot="custom-base-uri"><input type="checkbox"/> Configuration option</anypoint-item>
</api-server-selector>

当您决定使用一个没有数值的列表项目时,单击一个项目不会关闭选择器. 当用户执行与项目相关的动作时, 然后使用 opened 属性在选择器上关闭掉落.

<api-server-selector>
  <div slot="custom-base-uri">Other options</div>
  <anypoint-item slot="custom-base-uri"><input type="checkbox" id="option"/> Configuration option</anypoint-item>
</api-server-selector>

<script>
option.onclick = (e) => {
  e.target.parentNode.opened = false;
};
</script>

发展

git clone https://github.com/advanced-rest-client/api-server-selector
cd api-server-selector
npm install

本地运行演示

npm start

运行测试

npm test

版本与发布记录

@api-components/api-server-selector 共发布 29 个版本,首次发布于 2020/03/31;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.7.2latest2021/10/105 年前
0.7.12021/09/265 年前
0.7.02021/09/255 年前
0.6.42021/08/275 年前
0.6.32021/01/145 年前
0.6.22021/01/085 年前

关于 @api-components/api-server-selector 的常见问题

@api-components/api-server-selector 是什么?

一个使OAS的服务器成为选择API服务器的下拉选项的组件.

如何安装 @api-components/api-server-selector?

在项目目录运行 npm install @api-components/api-server-selector,或使用 pnpm add / yarn add / bun add。

@api-components/api-server-selector 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/api-components__api-server-selector 是否存在。

@api-components/api-server-selector 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@api-components/api-server-selector 可以商用吗?

@api-components/api-server-selector 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@api-components/api-server-selector 的下载量有多少?

根据 npm 官方下载统计,@api-components/api-server-selector 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,156 次,日均约 105 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@api-components/api-server-selector 还在维护吗?

最新版本 0.7.2 发布于 2021/10/10(5 年前);至今共发布 29 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/03/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。