required-content-type-header-for-request-body
Overview
This rule belongs to the apimatic-gavel-validation ruleset and states that:
When the request level body is defined, a Content-Type header entry must also be present in the headers section to help us understand how the body information is structured so it can be processed further accordingly.
| Property | Value |
|---|---|
| Enabled | Yes |
| Maximum Severity | Error |
| Message | Request Content-Type header is missing from headers even though body is non-empty. |
| Code | APIMATICGAVEL_V003 |
| Type | Validation |
| Rule System | Semantic |
| Broad Category | Gavel Request |
| Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
| Tags | gavel apimatic semantic validation content type header request body body form request |
Suggested Fixes
- Ensure that a
headersproperty exists in the request object. - Ensure that if
bodyis set, an entry for theContent-Typeheader exists in theheaderskey value pairs. - Ensure that the
Content-Typeheader name defined in theheaderssection has no typos. - If the
bodyis expected to take in raw data, define a Content-Type header value accordingly e.g.text/plainfor strings and numbers,application/jsonfor JSON data,application/xmlfor XML data, etc. - If the
bodyis expected to take a file/binary data as input, you may be looking for themultipart/form-dataContent-Type header value. - If the body is expected to have key-value pairs structured like a query string, you may be looking for the
application/x-www-form-urlencodedContent-Type header value. - Remove the
bodyproperty definition from the request object if no request payload is expected.
For More Information
- https://docs.apimatic.io/specification-extensions/swagger-test-cases-extensions/#http-request
- https://docs.apimatic.io/specification-extensions/swagger-test-cases-extensions/#gavel-specification
- https://docs.apimatic.io/specification-extensions/swagger-test-cases-extensions/#specifying-test-cases-using-gavel-specification
- https://docs.apimatic.io/rulesets/overview/