Search Results

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 will automatically generate 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 will be validated as you type it, and a message in the lower left will indicate if the sample data is valid.

      After entering valid sample data, click Generate Schema. The schema editor page will appear, 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 will appear, with a blank schema box. Enter your JSON schema in the box.

    • To use an existing schema, click Input Schema. The schema editor page will appear. Enter the name of the existing schema in the schema name box. The schema box will then be 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 will be extracted and replace the schema you just modeled. If you enter an existing name and click Save without choosing the name from the list, the new schema will overwrite 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 will be 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 will overwrite 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, please be note that the generated schema might not be exactly what you want for the request body, since the sample data might not carry all the information to define the appropriate schema. It’s 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 will overwrite the existing schema. You must confirm that you wish to do this.