Validating the YAML or JSON definition of an API or Product

You can validate a YAML or JSON definition by using the IBM® API Connect developer toolkit or you can find and use the schemas that describe valid APIs and Products to validate your own API and Product definitions.

Before you begin

To complete the steps that are described in this topic, you must have installed the developer toolkit. For more information, see Installing the toolkit.

About this task

Procedure

Use one of the following methods to validate your API definition:

  • To perform validation using the developer toolkit, enter the following command:
    apic validate filename

    where filename is the file name of the API definition file you want to validate.

    • Include --product-only to validate only a Product definition and not any APIs that it references.
    • Include --no-extensions to validate only the default OpenAPI (Swagger 2.0) section of the API and none of its extensions.
    [V5.0.5 or later]Note: If the OpenAPI (Swagger 2.0) file that defines your API uses a $ref field to reference a fragment of OpenAPI (Swagger 2.0) code that is defined in a separate file, the $ref field is replaced with the contents of the target file before the API definition is validated by the apic validate command. For more information, see [V5.0.5 or later]Using $ref to reuse code fragments in your OpenAPI (Swagger 2.0) files.
  • To locate the JSON schemas that you can use to validate your API or Product, complete the following steps:
    1. Navigate to the npm_install_folder/apiconnect/node_modules/apiconnect-validate/schemas folder,
      where npm_install_folder is your npm global installation folder; for example:
      /usr/local/lib/node_modules
      Note: If you are using a search to find the folder, be aware that there is a different node_modules folder inside npm_install_folder/apim.toolkit.
    2. Select the schema that you want to use.
      • To validate a Product, use the product-schema.json file.
      • To validate the main body of an API, use the swagger-v2.0-schema.json file.
      • To validate the IBM API Connect extension of an API, use the x-ibm-configuration.json file.
    3. Validate your API definition by using your preferred method.