验证 API 或产品的 YAML 或 JSON 定义

您可以使用 IBM® API Connect 开发者工具箱来验证 YAML 或 JSON 定义。

在开始之前

要完成本主题中描述的步骤,必须已安装 开发者工具箱。 更多信息,请参阅安装工具包

过程

要使用 开发者工具箱执行验证,请输入以下命令:
apic validate filename

其中 filename 是您想要验证的 API 定义文件的文件名。

  • 包含 --product-only 以仅验证产品定义,而不验证产品引用的任何 API。
  • 包含 --no-extensions 以仅验证 API 的缺省 OpenAPI 部分及其任何扩展。
注:
  • 如果定义 API 的 OpenAPI 文件使用 $ref 字段来引用在单独文件中定义的 OpenAPI 代码片段, 在使用 apic drafts:validate 命令创建草稿 API 之前, $ref 字段将替换为目标文件的内容。 有关更多信息,请参阅 使用 $ref 在 OpenAPI 文件中复用代码片段
  • 无法验证或发布包含具有 Swagger 属性 (使用 regex ) 的 API 的产品,其中包含诸如 "(?" 之类的前瞻断言。 系统会返回错误消息。 例如:
    Product has not been published!
    The multipart 'openapi' field contains an OpenAPI definition with validation errors.
        definitions.properties.pattern Does not match format 'regex' (context: (root).definitions.properties.pattern, line: 0, col: 0)
    400