华为云命令行工具服务 KooCLI-生成JSON格式API入参骨架

时间:2025-02-12 14:54:22

生成JSON格式API入参骨架

skeleton选项用于生成JSON格式API入参骨架。在命令中添加“--skeleton”选项,则在当前目录生成该API的JSON格式的入参文件,用户可填写文件中的参数值,以“--cli-jsonInput=${JSON文件名}”传入参数,调用API:

hcloud RDS CreateConfiguration --cli-region="cn-north-4" --skeleton已生成JSON格式API入参骨架,文件存放位置:C:\cli\RDS_CreateConfiguration_cn-20231108093800.json

该JSON文件的内容如下:

{"header": {"X-Language": ""},"path": {"project_id": ""},"body": {"datastore": {"type": "","version": ""},"description": "","name": "","values": {"": ""}}}--------------------------------- 骨架填写完成后,请删除此行及下列参数描述信息: ---------------------------------{"header": {"X-Language": {"Required": false,"ParamType": "string","Usage": "语言","EnumValue": ["zh-cn","en-us"]}},"path": {"project_id": {"Required": true,"ParamType": "string","Usage": "项目ID。"}},"body": {"datastore": {"type": {"Required": true,"ParamType": "string","Usage": "数据库引擎,不区分大小写:\n- MySQL\n- PostgreSQL\n- SQLServer\n- MariaDB","EnumValue": ["MySQL","PostgreSQL","SQLServer","MariaDB"]},"version": {"Required": true,"ParamType": "string","Usage": "数据库版本。\n\n- MySQL引擎支持5.6、5.7版本。取值示例:5.7。具有相应权限的用户才可使用8.0,您可联系华为云客服人员申请。\n- PostgreSQL引擎支持9.5、9.6、10、11版本。取值示例:9.6。\n- Microsoft SQL Server:仅支持2017 企业版、2017 标准版、2017 web版、2014 标准版、2014 企业版、2016 标准版、2016 企业版、2012 企业版、2012 标准版、2012 web版、2008 R2 企业版、2008 R2 web版、2014 web版、2016 web版。取值示例2014_SE。 例如:2017标准版可填写2017_SE,2017企业版可填写2017_EE,2017web版可以填写2017_WEB"}},"description": {"Required": false,"ParamType": "string","Usage": "参数模板描述。最长256个字符,不支持\u003e!\u003c\"\u0026'=特殊字符。默认为空。"},"name": {"Required": true,"ParamType": "string","Usage": "参数模板名称。最长64个字符,只允许大写字母、小写字母、数字、和“-_.”特殊字符。"},"values": {"": {"Required": false,"ParamType": "string","Usage": "参数值对象,用户基于默认参数模板自定义的参数值。为空时不修改参数值。\n\n- key:参数名称,\"max_connections\":\"10\"。为空时不修改参数值,key不为空时value也不可为空。\n- value:参数值,\"max_connections\":\"10\"。"}}}}
  • 生成的JSON文件分为上下两部分,上半部分为cli-jsonInput需要的API参数骨架,下半部分为各参数的描述信息及其取值规范。中间以分割线分割。用户可参考参数的描述信息,在上半部分的骨架中填写参数值。
  • JSON文件填写完成后,需删除分割线及下半部分的内容。对于未填写取值的参数,使用时也需要删除该参数。

以上述文件为例,参数填写完成后,JSON文件的内容为:

{"path": {"project_id": "0dd8cb****************19b5a84546"},"body": {"datastore": {"type": "MySQL","version": "5.7"},"description": "test create configuration","name": "test-001","values": {"max_connections": "10"}}}

将该文件传入命令中,以--cli-jsonInput方式调用API:

hcloud RDS CreateConfiguration --cli-region="cn-north-4" --cli-jsonInput="RDS_CreateConfiguration_cn-20231108093800.json" --dryruncli-jsonInput中各位置(如path、query、body、formData、header、cookie)传入的API参数优先于命令传入--------------------------------- dry-run模式跳过实际运行,当前请求为: ---------------------------------POST https://rds.cn-north-4.myhuaweicloud.com/v3/0dd8cb****************19b5a84546/configurationsContent-Type: application/jsonX-Project-Id: 0dd8cb****************19b5a84546X-Sdk-Date: 20220621T103331ZAuthorization: ****{  "datastore": {    "type": "MySQL",    "version": "5.7"  },  "description": "test create configuration",  "name": "test-001",  "values": {    "max_connections": "10"  }}
support.huaweicloud.com/usermanual-hcli/hcli_05_19.html