npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-alain-sts

v0.0.2

Published

Swagger to sf schema & st column in ng-alain

Downloads

2,605

Readme

ng-alain-sts Build Status NPM version

Convert Swagger API to sf Schema & st columns in ng-alain projects.

如何使用

ng-alain-sts 是一个 Node 插件,你可以使用命令行或直接调用 generator 方法来获取转换后的 sf Schema 和 st 列描述。

# via npm
npm i ng-alain-sts --save-dev
# via yarn
yarn add -D ng-alain-sts

ng-alain

ng-alain-sts 是专注于 NG-ALAIN,因此在 NG-ALAIN CLI 提供一个快捷命令:

ng g ng-alain:sts

它包含 listedit 两个自定义模板,可以通过指令根据 Swagger API 接口来生成列表、编辑页。

ng g ng-alain:module trade
ng g ng-alain:tpl swagger-list list -m=trade -t=trade --swaggerPath=/pet/findByStatus

更多请参考sts插件。

命令行

ng-alain-sts -t=sf -p=/pet swagger.json

参数

| 参数名 | 类型 | 默认 | 描述 | |-----------------|----------|-----------------------|--------------------------| | -t --type | sf,st | sf | 指定生成类型 | | -p --path | string | - | 必填 指定 paths 路径 | | -m --method | string | get | 指定请求方法 | | -c --config | string | swagger-config.json | 指定配置文件路径 |

调用

const sts = require('ng-alain-sts/src/generator');

await sts.generator(
  'https://petstore.swagger.io/v2/swagger.json',
  { type: 'sf' },
  { descriptionIsTitle: true }
);

配置文件

Swagger API 接口对于每一个后端语言或企业风格有着统一的编码风格、约定,如何更好的利用这些约定使生成的结构更符合当前的开发风格,从而进一步提升开发体验;配置文件给予了一些更自由空间,我们建议针对自己的接口风格定制不同的配置信息。

Config

| 参数 | 说明 | 类型 | 默认值 | |------------------|-------------------------|-------|--------| | requestOptions | Swagger JSON 文件网络请求配置项 | any | - | | pathPrefix | 路径前缀 | string | - | | propertyMapNames | 自定义属性名称映射 | { [name: string]: string } | { id: '编号', name: '名称' } | | descriptionIsTitle | 指定 descriptiontitle,并删除 description | boolean | true | | sf | sf 配置项 | SFConfig | - | | st | st 配置项 | STConfig | - |

SFConfig

| 参数 | 说明 | 类型 | 默认值 | |------------------|-------------------------|-------|--------| | method | 指定默认方法名 | string | put | | singleArray | 由于 sf 并不支持这种类型,默认被转化为 select 小部件 | SFSchema | - | | properties | 自定义属性的 Schema | PathConfig[] | - | | xmlBlackNames | XML 属性白名单,这些信息会以优先级最高直接传递给 ui | string[] | - | | propertyCallback | 递归属性回调 | (optinos: SFPropertyCallbackOptions) => void | - | | finishedCallback | 完成时回调 | (optinos: SFFinishedCallbackOptions) => void | - |

singleArray

单类型数组默认被转化为 select 小部件:

{
  type: 'string',
  ui: {
    widget: 'select',
    mode: 'tags',
  },
  default: null,
}

STConfig

| 参数 | 说明 | 类型 | 默认值 | |------------------|-------------------------|-------|--------| | method | 指定默认方法名 | string | get | | properties | 自定义属性的 Schema | PathConfig[] | - | | nameToType | 根据名称自定义类型 | { [name: string]: STColumnType } | - | | xmlBlackNames | XML 属性白名单,这些信息会以优先级最高直接传递给 STColumn | string[] | ['i18n'] | | propertyCallback | 递归属性回调 | (optinos: STPropertyCallbackOptions) => void | - | | finishedCallback | 完成时回调 | (optinos: STFinishedCallbackOptions) => void | - |

nameToType

定制根据名称自定义类型,默认值为:

{
  price: 'currency',
  amount: 'currency',
  num: 'number',
  count: 'number',
  avatar: 'img',
  mp: 'img',
  modified: 'date',
  created: 'date',
}

PathConfig

| 参数 | 说明 | 类型 | 默认值 | |--------|---------|-------|--------| | name | 属性名称 | string | - | | path | 指定路径,若不指定则该属性名对所有 path 有效 | string | - | | value | 值分为 SFSchemaSTColumn 类型 | SFSchema | STColumn | - |

License

MIT