In Apidog, after sending a request within an endpoint, Apidog automatically validates whether the response conforms to the schema based on the endpoint's specification.
If the above points are consistent, it will display "Response Data Sructure validated!". This means that the actual API return values are consistent with the API documentation specification, eliminating the need for manual verification and improving the efficiency.When you encounter the corresponding prompts on the right, you can follow the prompts to solve the issue.There are generally two types of problems: the first is when the server's response is incorrect, in which case the backend needs to be modified to align with the specification; the second is when the API specification is incorrect, requiring modification of the endpoint spec.By utilizing the automatic validation feature, you can eliminate the need to manually write scripts to validate responses. Furthermore, when there are changes to the API specification, the validation will also automatically adjust accordingly.
By default, Apidog validates the first response in the endpoint, typically a 200 response. However, an endpoint may return multiple different responses with different schemas. In such cases, you can choose which response to validate in the validation area's top right corner.You also have the option to toggle the "validate" feature off by clicking the switch in front of the response. This change only applies to the current endpoint.
As the actual business upgrades, additional properties may be added to the response. In such cases, Apidog allows users to determine whether to allow additional fields.For example, there is an API for querying user information, and the previous return fields were name and phone. Therefore, the data structure was specified like:With the business upgrade, a new city field was added to this API, but the API spec was not updated. According to default validation mechanism, no error will be reported, meaning that adding additional fields is allowed by default.However, for more strict development scenarios, if the return value contains additional fields that do not match the definition, the response validation should also report an error. In this case, you can achieve the desired behavior by following these steps:
1.
Modify the response in the API spec. In the advanced settings of the object, configure "additionalProperties" to "Deny", which will only take effect for the current API.
2.
If you want to disallow additional fields for all API in the project, you can go to "Settings" → "Response Validate Settings" and turn off "Allow Objects to Have additionalProperties".
3.
After completing the configuration, when sending the request again, the response validation mechanism will report an error, indicating that additionalProperties are not allowed.
The "Validate Response" switch is turned on by default, and you can adjust it in the "Verification Response Settings" in the project settings interface. This setting only takes effect for all APIs in the current project and does not affect the saved Endpoint Cases.If you only requires manual assertions or post-scripts and do not need Apidog to validate response consistency with the API specification, you can disable the validation function for specific modules.
The validate response contains "HTTP Status", "Header", "Body", you can adjust it in the "Validate Reponse Content" in the project settings. This setting only takes effect for all API in the current project and does not affect the saved Endpoint Cases.