Validate

Validates incoming payloads against JSON or XML schemas.

Use the Validate policy to ensure that incoming data matches an expected JSON or XML schema before the request proceeds.

For more information on the policy parameter descriptions, see DataPower Nano Gateway documentation.

Example of a Validate policy in code view.

kind: ValidateAPISpecification
apiVersion: api.ibm.com/v1
metadata:
  name: validate_api_specification_request
  version: 1
  namespace: sample
spec:
  input: request #Not Optional
  validate:
    request:
      schema:
        validate: true # provided to add xml feature in future
      query: true
      path: true
      header: true # provided to add xml feature in future
      cookie: true
      contentType: true 
---
kind: ValidateAPISpecification
apiVersion: api.ibm.com/v1
metadata:
  name: validate_api_specification_response
  version: 1
  namespace: sample
spec:
  input: response #Not Optional
  validate:
    response:
      schema:
        validate: true # provided to add xml feature in future
      header: true # provided to add xml feature in future
      contentType: true
---
kind: ValidateAPISpecification
apiVersion: api.ibm.com/v1
metadata:
  name: validate_api_specification_schema_subset
  version: 1
  namespace: sample
spec:
  input: message #Not Optional
  validate:
    openApiSchemaRef:
      schemaReference: "#/components/schemas/pet"
      failureStatusCode: "400" # Enum BadRequest(400)/InternalServerError(500)
---
kind: ValidateAPISpecification
apiVersion: api.ibm.com/v1
metadata:
  name: validate_api_specification_schema_external
  version: 1
  namespace: sample
spec:
  input: message #Not optional
  validate:
    file: 
      $path: "./schema.json"  # relative path of the scehma file inside the project.
      failureStatusCode: "400" # Enum BadRequest(400)/InternalServerError(500)