@api-components/api-view-model-transformer

中文文档
4.2.2发布于 2020/11/11Apache-2.0ESM + CJS近 30 天下载 3120

AMF model transformer to a form view model used in API components.

此软件包已被标记为弃用

Use @api-components/api-forms instead

原始使用文档
文档目录10 节
  1. Version compatibility
  2. Deprecation notice
  3. Usage
  4. Installation
  5. Example
  6. Deprecated example
  7. ld+json context
  8. Development
  9. Running the demo locally
  10. Running the tests

Published on NPM

Build Status

Published on webcomponents.org

ApiViewModel

A library to transform AMF's ld-json model into a form view model. The form view is used to power editors embedded in the api-request-editor element. The model should be used to build a form view for request parameters like header, query parameters, uri parameters or the body.

Version compatibility

This version only works with AMF model version 2 (AMF parser >= 4.0.0). For compatibility with previous model version use 3.x.x version of the component.

Deprecation notice

The api-view-model-transformer custom element was build when the AmfHelperMixin was requiring a HTMLElement as a base class. Since it is not the case any more this element is being transformed into a JS library. The custom element has only previously accessible public properties. With the next major release the custom element will be removed. Please, use ApiViewModel class instead of element.

Usage

Installation

npm install --save @api-components/api-view-model-transformer

Example

import { ApiViewModel } from '@api-components/api-view-model-transformer';
const amf = getAmfFromRamlOrOas();
const headers = extractHeadersForMethod(amf); // or other types.
const worker = new ApiViewModel();
const viewModel = worker.computeViewModel(headers);

This example uses getAmfFromRamlOrOas() function where you implement the logic of getting AMF json/ld data. It can be stored in file or parsed using AMF parsers. The extractHeadersForMethod() represents a logic to extract properties that you want to transform. It can be headers, query parameters or body type.

Deprecated example

<api-view-model-transformer></api-view-model-transformer>
<script>
const amfModel = getAmfFromRamlOrOas();
const processor = document.querySelector('api-view-model-transformer');
processor.amf = amfModel;
processor.shape = extractHeadersForMethod(amfModel);
processor.addEventListener('view-model-changed', (e) => {
 console.log(e.detail.value);
});
</script>

ld+json context

JSON schema may contain @context property. It can be used to reduce size of the schema by replacing namespace ids with defined in @context keyword. For the component to properly compute AMF values the full AMF model has to be set on amf property.

Development

git clone https://github.com/advanced-rest-client/api-view-model-transformer
cd api-view-model-transformer
npm install

Running the demo locally

npm start

Running the tests

npm test

版本与发布记录

@api-components/api-view-model-transformer 共发布 20 个版本,首次发布于 2018/05/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.2.2latest2020/11/115 年前
4.2.02020/07/256 年前
4.1.12020/04/266 年前
4.1.02020/04/256 年前
4.0.42020/04/256 年前
4.0.32020/04/216 年前

关于 @api-components/api-view-model-transformer 的常见问题

@api-components/api-view-model-transformer 是什么?

AMF model transformer to a form view model used in API components.注意:该包已被作者标记为弃用——Use @api-components/api-forms instead

如何安装 @api-components/api-view-model-transformer?

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

@api-components/api-view-model-transformer 支持 TypeScript 吗?

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

@api-components/api-view-model-transformer 支持 ESM 还是 CommonJS?

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

@api-components/api-view-model-transformer 可以商用吗?

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

@api-components/api-view-model-transformer 的下载量有多少?

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

@api-components/api-view-model-transformer 还在维护吗?

最新版本 4.2.2 发布于 2020/11/11(5 年前);至今共发布 20 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/05/19。作者已将其标记为弃用,新项目建议寻找替代方案。