Adding and Editing Body Parameters

The message body is used to carry the entity body associated with the request. You can define the JSON schema of the request body content. API Modeler provides functionality so that a JSON schema can be generated automatically from a sample data.

Adding a Body Parameter

To add a Body parameter:

  1. In the Request Body Parameter section, click + Body parameter. This opens the Request Body Parameter page with the Provide Sample Data box visible.

  2. In the Description field, enter a description for the added parameter.
  3. Select a request content type from the following options:
    • application/json: the request content must be in JSON format.
    • application/xml: the request content must be in XML format. Selecting this does not affect the functionality of generating a JSON schema for the request body content.
  4. There are three methods to add the request schema:
    • You can model your schema from sample JSON data, and API Modeler automatically generates a corresponding JSON schema object type.

      Enter sample JSON data for your request in the Provide Sample Data box. This can be a JSON object or JSON array. The data is validated as you type it, and a message in the lower left indicates if the sample data is valid.

      After entering valid sample data, click Generate Schema. The schema editor page appears, with your sample data converted into a schema in the schema editor box.

    • To directly enter a complete JSON schema, click Input Schema. The schema editor page appears, with a blank schema box. Enter your JSON schema in the box.
    • To use an existing schema, click Input Schema. The schema editor page appears. Enter the name of the existing schema in the schema name box. The schema box is then filled with the existing schema you selected. The scope of the existing schemas is within the same API specification.

  5. If you modeled your schema or entered a complete schema, enter a unique name in the schema name box.
    Note: If you enter an existing name, and choose this name in the auto-search results in the schema name box, the existing schema is extracted and replaces the schema you just modeled.

    If you enter an existing name and click Save without choosing the name from the list, the new schema overwrites the existing schema under the name.

  6. You can make further changes to the complete schema in the schema box, if required.
  7. Select a request schema from the following options:

    • String: The request content can be any string, rather than a JSON object.
    • Reference: The request content must conform to the referenced JSON schema. This is selected if you have entered or modeled a schema.
  8. Select the array box if the request body is an array of a string, or an array of the JSON object conforming to the schema referenced.
  9. You can click Generate Schema from Sample Data to return to the Request Body Parameter page with the Provide Sample Data box visible. This enables you to start over and enter new sample data. Note that the new generated schema overwrites the existing schema. You must confirm that you wish to do this.
  10. Click Save when you are finished.

When you use sample data to generate the schema, the generated schema might not be exactly what you want for the request body, because the sample data might not carry all the information necessary to define the appropriate schema. It is always a good practice to review the auto-generated schema and make appropriate changes to meet your requirements.

Editing a Body Parameter

To edit an added Body Parameter:

  1. In the right Request Body Parameter section, move the mouse pointer over the Body parameter.
  2. Click Edit to edit the Body parameter or click to delete the Body parameter.
  3. Editing the body parameter is similar to adding a parameter, as described above. You can click Generate Schema from Sample Data to return to the Request Body Parameter page with the Provide Sample Data box visible. This enables you to start over and enter new sample data. Note that the new generated schema overwrites the existing schema. You must confirm that you wish to do this.