Validate API specification
The Validate API specification policy validates the incoming request and outgoing responses against the API's various specifications.
In the Validate API specification policy, specifications such as schema, query parameters, path parameters, cookie parameters, content-types, and HTTP Headers are referenced in their corresponding formats. The request sent to the API by an application must conform with the structure or format specified. The incoming requests are validated against the API specifications in this policy to conform to the structure or format that the API expects.
In IBM API Studio, the kind
ValidateAPISpecification identifies the policy.
Example of a Validate API Specification policy in code view.
kind: ValidateAPISpecification
apiVersion: api.ibm.com/v2
metadata:
name: validate-api-spec
version: 1.0
namespace: wm_project
spec:
input: request #Required
validate:
request:
schema:
validate: true
query: true
path: true
header: true
cookie: true
contentType: true
extensions:
webm-gateway:
apiVersion: api.ibm.com/v2
spec:
validate:
custom-headers:
condition: (${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
schema:
feature:
- name: TOLERATE_DUPLICATES
value: true
- name: DISALLOW_DOCTYPE
value: false
For the ValidateAPISpecification policy kind, configure these specifications:
| Code view | Form view | Description |
|---|---|---|
| validate | N.A. |
Denotes the API Specifications to validate. Validates the Request or Response against the definitions in the API specification. |
schema |
Schema |
Defines validation features that affect how schema compliance is enforced. Configure the following under the
feature spec in the code view, or use the
Add condition option in the form view: name and
value.
|
query |
Query parameters |
Validates the query parameters in the incoming request against the query parameters that are defined in the API Specification of the request. |
path |
Path parameters |
Validates the path parameters in the incoming request against the query parameters that are defined in the API Specification of the request. |
cookie |
Cookie parameters |
Validates the cookie parameters in the incoming request against the query parameters that are defined in the API Specification of the request. |
header |
Header | Validates the HTTP headers in the incoming request against the query parameters that are defined in the API Specification of the request. |
contentType |
Content types |
Validates the content types in the incoming request against the query parameters that are defined in the API Specification of the request. |
custom-headers |
Custom headers |
Defines the condition for applying custom headers. The condition evaluates an expression that
checks whether the incoming request meets specific criteria. It can include comparison and logical
operators such as You can use the following operators:
|