Gathering detailed insights and metrics for sm2tsservice
Gathering detailed insights and metrics for sm2tsservice
Gathering detailed insights and metrics for sm2tsservice
Gathering detailed insights and metrics for sm2tsservice
npm install sm2tsservice
Typescript
Module System
Node Version
NPM Version
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
2 Stars
1 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Sep 25, 2023
Latest Version
3.4.2
Package Id
sm2tsservice@3.4.2
Unpacked Size
14.27 MB
Size
12.52 MB
File Count
73
NPM Version
6.4.1
Node Version
10.15.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
15
30
import { Props } from 'docz'; import { IGuardConfig, IYAPIConfig, ISwaggerParser, IJson2Service, IRequest, ISwaggerConfig } from './tests/Doc.tsx';
npm i -D sm2tsservice
根据 swagger 或者 yapi mock json 生成 typescript service 代码
edit json2service.json
,也可用 xxx.js
,然后配置 -c xxx.js
swaggerParser
guardConfig
yapiConfig
requestConfig
swaggerConfig
1{ 2 "url": "./api.json", // 文件路径 3 "remoteUrl": "http://**", // url 4 "requestConfig": { 5 "url": "./api.json" // 文件路径或url 6 // 以下所有 request 支持的参数 7 // headers?: Headers; 8 // baseUrl?: string; 9 // callback?: RequestCallback; 10 // jar?: CookieJar | boolean; 11 // formData?: { [key: string]: any }; 12 // form?: { [key: string]: any } | string; 13 // auth?: AuthOptions; 14 // oauth?: OAuthOptions; 15 // aws?: AWSOptions; 16 // hawk?: HawkOptions; 17 // qs?: any; 18 // qsStringifyOptions?: any; 19 // qsParseOptions?: any; 20 // json?: any; 21 // jsonReviver?: (key: string, value: any) => any; 22 // jsonReplacer?: (key: string, value: any) => any; 23 // multipart?: RequestPart[] | Multipart; 24 // agent?: http.Agent | https.Agent; 25 // agentOptions?: http.AgentOptions | https.AgentOptions; 26 // agentClass?: any; 27 // forever?: any; 28 // host?: string; 29 // port?: number; 30 // method?: string; 31 // body?: any; 32 // family?: 4 | 6; 33 // followRedirect?: boolean | ((response: http.IncomingMessage) => boolean); 34 // followAllRedirects?: boolean; 35 // followOriginalHttpMethod?: boolean; 36 // maxRedirects?: number; 37 // removeRefererHeader?: boolean; 38 // encoding?: string | null; 39 // pool?: any; 40 // timeout?: number; 41 // localAddress?: string; 42 // proxy?: any; 43 // tunnel?: boolean; 44 // strictSSL?: boolean; 45 // rejectUnauthorized?: boolean; 46 // time?: boolean; 47 // gzip?: boolean; 48 // preambleCRLF?: boolean; 49 // postambleCRLF?: boolean; 50 // withCredentials?: boolean; 51 // key?: Buffer; 52 // cert?: Buffer; 53 // passphrase?: string; 54 // ca?: string | Buffer | string[] | Buffer[]; 55 // har?: HttpArchiveRequest; 56 // useQuerystring?: boolean; 57 }, 58 "type": "yapi", 59 "yapiConfig": { 60 "required": false, 61 "bodyJsonRequired": false, 62 "categoryMap": { 63 "中文": "English" // yapi 接口分类中英文映射 64 } 65 }, 66 "swaggerParser": { 67 "-o": "tmp/services" 68 }, 69 "validateResponse": false, // 是否生成校验逻辑 70 "guardConfig": { 71 // + strict 严格模式 72 // - 校验 swagger tags【yapi 接口分类】是否是纯英文 73 // - 方法名使用 http method + url 驼峰形式 74 // - 新项目采用 75 // + safe 安全模式 76 // - 方法名使用 http method + url 驼峰形式 77 // - 老项目升级,不会校验 tags,会生成方法调用替换映射表 78 // + 默认 79 // - http method + url => operationId 映射锁定 80 // - 老项目维持现状 81 "mode": "strict", 82 // swagger 处理重复 operationId 逻辑有风险,因此需要锁定映射关系 83 "methodUrl2OperationIdMap": { 84 "get /api/xxx/xxx": "operationId" 85 } 86 } 87}
1 ./node_modules/.bin/sm2tsservice # 使用默认配置 2 ./node_modules/.bin/sm2tsservice -c config.json # 指定配置文件 3 ./node_modules/.bin/sm2tsservice --clear # 清空上次生成产物 4 ./node_modules/.bin/sm2tsservice --quiet # 自动全量使用远程文档,不显示 diff & merge 页面 5 ./node_modules/.bin/sm2tsservice --models # 仅生成 models 6 ./node_modules/.bin/sm2tsservice --models --apis # 仅生成 models & apis 7 ./node_modules/.bin/sm2tsservice --typeScriptDataFile TypeSciptData.json # 仅生成类型信息 json 到 TypeSciptData.json
写入 package.json
,通过 npm run api
使用
1{ 2 "scripts": { 3 "api": "sm2tsservice --clear" 4 } 5}
实现 ajax 类【如果使用的 axios,且后端返回数据结构遵循 { code?:number;message?:string;result: any }
】
自 @3.1.* 版本起,支持增量更新
import CHANGELOG from './CHANGELOG.md';
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/1 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More