常见赠款 CLI
普通Grants CLI (英语:cg)是一个与"通用Grants"协议合作的工具. 它简化了界定、实施和验证通用赠款API的程序.
说明: 此软件包目前为α. 下文所描述的命令被嘲弄了执行,将在今后的发布中被全部功能所取代.
安装
# Install globally
npm install -g @common-grants/cli
# Or use with npx
npx @common-grants/cli <command>
使用量
查看可用的命令和选项 :
cg --help
输出 :
CommonGrants CLI tools
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
init [options] Initialize a new CommonGrants project
preview <specPath> Preview an OpenAPI specification
check Validate APIs and specifications
compile <typespecPath> Compile a TypeSpec file to OpenAPI
help [command] display help for command
初始化项目
从模板创建新的 CommonGrants 项目 :
# Initialize interactively
cg init
# List available templates
cg init --list
# Use a specific template
cg init --template custom-api
将类型编译为 OpenAPI
将 TypeSpec 文件编译为 OpenAPI 规格 :
cg compile spec.tsp
这是薄薄的包裹 tsp compile 命令并使用您的工程 tspconfig.yaml 用于确定输出格式的文件.
预览 OpenAPI 规格
使用 Swagger 界面预览 API 规格 :
# Preview a YAML file
cg preview openapi.yaml
# Preview a JSON file
cg preview openapi.json
验证 API 规格
对照 CommunityGrants 基础协议验证 API 规格 。 您可以选择指定特定协议版本来检查,或者提供一个路径来获取自己的基谱. 默认, check spec 使用与 CLI 捆绑的基协议的最新版本.
# Using the base protocol spec bundled with @common-grants/cli, uses the latest version by default
cg check spec openapi.yaml
# Using a specific protocol version
cg check spec openapi.yaml --protocol-version 0.4.0
# Using the path to a locally compiled base spec
cg check spec openapi.yaml --base <path-to-base-spec>
调查结果报告为错误或警告。 错误以退出码 1 失败命令 。 打印、标记警告 (warning),而且命令仍然以退出代码 0 成功,因为一个路由 : optional 可能因履约而省略.
发展状况
此 CLI 正在积极开发中, 只支持以下命令 :
cg init带有一组有限的模板cg compilecg previewcg check spec
预期特点
以下例子说明了国家综合倡议的预期特点,但这些特点尚未执行,可能会有变化.
验证 API 执行
检查一个 API 执行是否符合其规格 :
# Basic validation
cg check api https://api.example.com spec.yaml
# Generate validation report
cg check api https://api.example.com spec.yaml --report json
# Validate with authentication
cg check api https://api.example.com spec.yaml --auth bearer:token