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
headers
property exists in the request object. - Ensure that if
body
is set, an entry for theContent-Type
header exists in theheaders
key value pairs. - Ensure that the
Content-Type
header name defined in theheaders
section has no typos. - If the
body
is expected to take in raw data, define a Content-Type header value accordingly e.g.text/plain
for strings and numbers,application/json
for JSON data,application/xml
for XML data, etc. - If the
body
is expected to take a file/binary data as input, you may be looking for themultipart/form-data
Content-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-urlencoded
Content-Type header value. - Remove the
body
property 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/