JSON Payload Inspection

I am trying to do basic json payload inspection, I added below configuration as per the https://tyk.io/docs/advanced-configuration/transform-traffic/validate-json/:

“use_extended_paths”: true,
“extended_paths”: {
“validate_json”: [{
“method”: “any”,
“path”: “me”,
“schema”: “{…schema…}”,
“error_response_code”: 422
}]
},

But I tried to put wrong json request payload using postman but still I am getting 200 error code.

Below is my API definition:

[root@ip-10-10-31-38 apps]# cat cloudgatewayhttpbasicauth.json
{
“name”: “cloudgatewayhttpbasicauth”,
“slug”: “cloudgatewayhttpbasicauth”,
“listen_port”: 0,
“protocol”: “”,
“enable_proxy_protocol”: false,
“api_id”: “cloudgatewayhttpbasicauth”,
“org_id”: “5”,
“use_keyless”: false,
“use_oauth2”: false,
“use_openid”: false,
“openid_options”: {
“providers”: null,
“segregate_by_client”: false
},
“oauth_meta”: {
“allowed_access_types”: null,
“allowed_authorize_types”: null,
“auth_login_redirect”: “”
},
“auth”: {
“use_param”: false,
“param_name”: “”,
“use_cookie”: false,
“cookie_name”: “”,
“auth_header_name”: “”,
“use_certificate”: false,
“validate_signature”: false,
“signature”: {
“algorithm”: “”,
“header”: “”,
“secret”: “”,
“allowed_clock_skew”: 0,
“error_code”: 0,
“error_message”: “”
}
},
“auth_configs”: null,
“use_basic_auth”: true,
“basic_auth”: {
“disable_caching”: false,
“cache_ttl”: 0,
“extract_from_body”: false,
“body_user_regexp”: “”,
“body_password_regexp”: “”
},
“use_mutual_tls_auth”: false,
“client_certificates”: null,
“upstream_certificates”: null,
“pinned_public_keys”: null,
“enable_jwt”: false,
“use_standard_auth”: false,
“use_go_plugin_auth”: false,
“enable_coprocess_auth”: false,
“jwt_signing_method”: “”,
“jwt_source”: “”,
“jwt_identity_base_field”: “”,
“jwt_client_base_field”: “”,
“jwt_policy_field_name”: “”,
“jwt_default_policies”: null,
“jwt_issued_at_validation_skew”: 0,
“jwt_expires_at_validation_skew”: 0,
“jwt_not_before_validation_skew”: 0,
“jwt_skip_kid”: false,
“jwt_scope_to_policy_mapping”: null,
“jwt_scope_claim_name”: “”,
“notifications”: {
“shared_secret”: “”,
“oauth_on_keychange_url”: “”
},
“enable_signature_checking”: false,
“hmac_allowed_clock_skew”: 0,
“hmac_allowed_algorithms”: null,
“request_signing”: {
“is_enabled”: false,
“secret”: “”,
“key_id”: “”,
“algorithm”: “”,
“header_list”: null,
“certificate_id”: “”,
“signature_header”: “”
},
“base_identity_provided_by”: “”,
“definition”: {
“location”: “header”,
“key”: “x-api-version”,
“strip_path”: false
},
“version_data”: {
“not_versioned”: true,
“default_version”: “”,
“versions”: {
“Default”: {
“name”: “Default”,
“expires”: “”,
“paths”: {
“ignored”: null,
“white_list”: null,
“black_list”: null
},
“use_extended_paths”: true,
“extended_paths”: {
“validate_json”: [{
“method”: “any”,
“path”: “me”,
“schema”: “{…schema…}”,
“error_response_code”: 422
}]
},

    "global_headers": null,
    "global_headers_remove": null,
    "global_response_headers": null,
    "global_response_headers_remove": null,
    "ignore_endpoint_case": false,
    "global_size_limit": 0,
    "override_target": ""
  }
}

},
“uptime_tests”: {
“check_list”: null,
“config”: {
“expire_utime_after”: 0,
“service_discovery”: {
“use_discovery_service”: false,
“query_endpoint”: “”,
“use_nested_query”: false,
“parent_data_path”: “”,
“data_path”: “”,
“port_data_path”: “”,
“target_path”: “”,
“use_target_list”: false,
“cache_timeout”: 0,
“endpoint_returns_list”: false
},
“recheck_wait”: 0
}
},
“proxy”: {
“preserve_host_header”: false,
“listen_path”: “/CloudGateway/rest/”,
“target_url”: “https://ip-10-10-31-38.ap-southeast-1.compute.internal:8443”,
“disable_strip_slash”: false,
“strip_listen_path”: false,
“enable_load_balancing”: false,
“target_list”: null,
“check_host_against_uptime_tests”: false,
“service_discovery”: {
“use_discovery_service”: false,
“query_endpoint”: “”,
“use_nested_query”: false,
“parent_data_path”: “”,
“data_path”: “”,
“port_data_path”: “”,
“target_path”: “”,
“use_target_list”: false,
“cache_timeout”: 0,
“endpoint_returns_list”: false
},
“transport”: {
“ssl_insecure_skip_verify”: false,
“ssl_ciphers”: null,
“ssl_min_version”: 0,
“ssl_max_version”: 0,
“ssl_force_common_name_check”: false,
“proxy_url”: “”
}
},
“disable_rate_limit”: false,
“disable_quota”: false,
“custom_middleware”: {
“pre”: null,
“post”: null,
“post_key_auth”: null,
“auth_check”: {
“name”: “”,
“path”: “”,
“require_session”: false,
“raw_body_only”: false
},
“response”: null,
“driver”: “”,
“id_extractor”: {
“extract_from”: “”,
“extract_with”: “”,
“extractor_config”: null
}
},
“custom_middleware_bundle”: “”,
“cache_options”: {
“cache_timeout”: 0,
“enable_cache”: false,
“cache_all_safe_requests”: false,
“cache_response_codes”: null,
“enable_upstream_cache_control”: false,
“cache_control_ttl_header”: “”,
“cache_by_headers”: null
},
“session_lifetime”: 0,
“active”: true,
“internal”: false,
“auth_provider”: {
“name”: “”,
“storage_engine”: “”,
“meta”: null
},
“session_provider”: {
“name”: “”,
“storage_engine”: “”,
“meta”: null
},
“event_handlers”: {
“events”: null
},
“enable_batch_request_support”: false,
“enable_ip_whitelisting”: true,
“allowed_ips”: [“18.142.155.240”,“111.65.34.213”],
“enable_ip_blacklisting”: false,
“blacklisted_ips”: null,
“dont_set_quota_on_create”: false,
“expire_analytics_after”: 0,
“response_processors”: null,
“CORS”: {
“enable”: false,
“allowed_origins”: null,
“allowed_methods”: null,
“allowed_headers”: null,
“exposed_headers”: null,
“allow_credentials”: false,
“max_age”: 0,
“options_passthrough”: false,
“debug”: false
},
“domain”: “”,
“certificates”: null,
“do_not_track”: false,
“tags”: null,
“enable_context_vars”: false,
“config_data”: null,
“tag_headers”: null,
“global_rate_limit”: {
“rate”: 0,
“per”: 0
},
“strip_auth_data”: false,
“enable_detailed_recording”: false,
“graphql”: {
“enabled”: false,
“execution_mode”: “”,
“version”: “”,
“schema”: “”,
“type_field_configurations”: null,
“playground”: {
“enabled”: false,
“path”: “”
},
“engine”: {
“field_configs”: null,
“data_sources”: null
}
}
}

Hi @saloni512, I can observe that the sample code from the documentation is still intact in your API definition.

You would need to replace

{…schema…}

with your JSON object/body. Hope this helps.

For basic JSON format validation what I am supposed to add here? Is there any standard Schema I need to add?

Yes, the schema must be a draft v4 JSON Schema spec, see Specification Links | JSON Schema for details.

Whatever your JSON object is, the schema needs to be in v4. We have a sample in our docs

Example you can use our sample Person object in the docs as a test case.

You would need to pass in the valid body below:

{
    "firstName": "John",
    "lastName": "Doe",
    "age": 30
}

Does this means api will always expect below in the request pay load, if its not as it is then it will throw 422 error:

{
“firstName”: “John”,
“lastName”: “Doe”,
“age”: 30
}

I tried adding below in the schema, in the postman given wrong json still getting 200:

“extended_paths”: {
“validate_json”: [{
“method”: “any”,
“path”: “me”,
“schema”: {“firstName”: “John”, “lastName”: “Doe”, “age”: 30 },
“error_response_code”: 422
}]
},

No. In our doc, there is a sample schema. I will link it below

"validate_json": [
              {
                "path": "response-headers",
                "method": "POST",
                "schema": {
                  "properties": {
                    "age": {
                      "description": "Age in years",
                      "minimum": 0,
                      "type": "integer"
                    },
                    "firstName": {
                      "type": "string"
                    },
                    "lastName": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "firstName",
                    "lastName"
                  ],
                  "title": "Person",
                  "type": "object"
                },
                "error_response_code": 422
              }
            ]

This sample schema is what is expected as the value of the schema property and how the JSON body is validated. You would notice that the properties are given a valid instance or data type as well as some extra info. Some are also required by specification.

You would need to construct something similar for your own JSON object/body. More information on how to construct a valid schema can be found here. Tyk gateway utilizes draft 4 of the JSON schema spec, so you would need to ensure your schema follows that pattern.

The JSON body below is how to validate that your schema is working properly. If you remove any of the required properties (firstName or lastName), you would get an error result back detailing what went wrong. Same thing would happen is you pass in a negative age value.

{
    "firstName": "John",
    "lastName": "Doe",
    "age": 30
}

If you are new to JSON schema, then this step by step guide could be of help

As per the suggestion I added below but still getting 200 response even I passing wrong data or blank or negative value of age:

“schema”: {
“properties”: {
“age”: {
“description”: “Age in years”,
“minimum”: 0,
“type”: “integer”
},
“firstName”: {
“type”: “string”
},
“lastName”: {
“type”: “string”
}
},
“required”: [
“firstName”,
“lastName”
],
“title”: “Person”,
“type”: “object”

},

Can you crosscheck that the full path is correct? For example, the path where the JSON validation takes place in my API definition below is at the response-headers sub path

Path should look like: “…/http-bin-site/response-headers”

{
	"api_id": "c51461aaac8d498a4f5074ca4ef65d4e",
	"jwt_issued_at_validation_skew": 0,
	"upstream_certificates": {},
	"use_keyless": true,
	"enable_coprocess_auth": false,
	"base_identity_provided_by": "",
	"custom_middleware": {
		"pre": [],
		"post": [],
		"post_key_auth": [],
		"auth_check": {
			"name": "",
			"path": "",
			"require_session": false,
			"raw_body_only": false
		},
		"response": [],
		"driver": "",
		"id_extractor": {
			"extract_from": "",
			"extract_with": "",
			"extractor_config": {}
		}
	},
	"disable_quota": false,
	"custom_middleware_bundle": "",
	"cache_options": {
		"cache_timeout": 60,
		"enable_cache": false,
		"cache_all_safe_requests": false,
		"cache_response_codes": [],
		"enable_upstream_cache_control": false,
		"cache_control_ttl_header": "",
		"cache_by_headers": []
	},
	"enable_ip_blacklisting": false,
	"tag_headers": [
		"edge"
	],
	"jwt_scope_to_policy_mapping": {},
	"pinned_public_keys": {},
	"expire_analytics_after": 0,
	"domain": "",
	"openid_options": {
		"providers": [],
		"segregate_by_client": false
	},
	"jwt_policy_field_name": "",
	"enable_proxy_protocol": false,
	"jwt_default_policies": [],
	"active": true,
	"jwt_expires_at_validation_skew": 0,
	"config_data": {},
	"notifications": {
		"shared_secret": "",
		"oauth_on_keychange_url": ""
	},
	"jwt_client_base_field": "",
	"auth": {
		"use_param": false,
		"param_name": "",
		"use_cookie": false,
		"cookie_name": "",
		"auth_header_name": "Authorization",
		"use_certificate": false,
		"validate_signature": false,
		"signature": {
			"algorithm": "",
			"header": "",
			"secret": "",
			"allowed_clock_skew": 0,
			"error_code": 0,
			"error_message": ""
		}
	},
	"check_host_against_uptime_tests": false,
	"auth_provider": {
		"name": "",
		"storage_engine": "",
		"meta": {}
	},
	"blacklisted_ips": [],
	"graphql": {
		"enabled": false,
		"execution_mode": "proxyOnly",
		"schema": "",
		"type_field_configurations": [],
		"playground": {
			"enabled": false,
			"path": ""
		}
	},
	"hmac_allowed_clock_skew": -1,
	"dont_set_quota_on_create": false,
	"uptime_tests": {
		"check_list": [],
		"config": {
			"expire_utime_after": 0,
			"service_discovery": {
				"use_discovery_service": false,
				"query_endpoint": "",
				"use_nested_query": false,
				"parent_data_path": "",
				"data_path": "",
				"cache_timeout": 60
			},
			"recheck_wait": 0
		}
	},
	"enable_jwt": false,
	"do_not_track": false,
	"name": "Http Bin Site",
	"slug": "http-bin-site",
	"oauth_meta": {
		"allowed_access_types": [],
		"allowed_authorize_types": [],
		"auth_login_redirect": ""
	},
	"CORS": {
		"enable": false,
		"max_age": 24,
		"allow_credentials": false,
		"exposed_headers": [],
		"allowed_headers": [
			"Origin",
			"Accept",
			"Content-Type",
			"X-Requested-With",
			"Authorization"
		],
		"options_passthrough": false,
		"debug": false,
		"allowed_origins": [
			"*"
		],
		"allowed_methods": [
			"GET",
			"POST",
			"HEAD"
		]
	},
	"event_handlers": {
		"events": {}
	},
	"proxy": {
		"target_url": "http://httpbin.org",
		"service_discovery": {
			"endpoint_returns_list": false,
			"cache_timeout": 0,
			"parent_data_path": "",
			"query_endpoint": "",
			"use_discovery_service": false,
			"_sd_show_port_path": false,
			"target_path": "",
			"use_target_list": false,
			"use_nested_query": false,
			"data_path": "",
			"port_data_path": ""
		},
		"check_host_against_uptime_tests": false,
		"transport": {
			"ssl_insecure_skip_verify": false,
			"ssl_min_version": 0,
			"proxy_url": "",
			"ssl_ciphers": []
		},
		"target_list": [],
		"preserve_host_header": false,
		"strip_listen_path": true,
		"enable_load_balancing": false,
		"listen_path": "/http-bin-site/",
		"disable_strip_slash": false
	},
	"client_certificates": [],
	"use_basic_auth": false,
	"version_data": {
		"not_versioned": true,
		"default_version": "",
		"versions": {
			"Default": {
				"name": "Default",
				"expires": "",
				"paths": {
					"ignored": [],
					"white_list": [],
					"black_list": []
				},
				"use_extended_paths": true,
				"global_headers": {},
				"global_headers_remove": [],
				"global_response_headers": {},
				"global_response_headers_remove": [],
				"ignore_endpoint_case": false,
				"global_size_limit": 0,
				"override_target": "",
				"extended_paths": {
					"validate_json": [
						{
							"path": "response-headers",
							"method": "POST",
							"schema": {
								"properties": {
									"age": {
										"description": "Age in years",
										"minimum": 0,
										"type": "integer"
									},
									"firstName": {
										"type": "string"
									},
									"lastName": {
										"type": "string"
									}
								},
								"required": [
									"firstName",
									"lastName"
								],
								"title": "Person",
								"type": "object"
							},
							"error_response_code": 422
						}
					]
				}
			}
		}
	},
	"jwt_scope_claim_name": "",
	"use_standard_auth": false,
	"session_lifetime": 0,
	"hmac_allowed_algorithms": [],
	"disable_rate_limit": false,
	"definition": {
		"location": "header",
		"key": "x-api-version",
		"strip_path": false
	},
	"use_oauth2": false,
	"jwt_source": "",
	"jwt_signing_method": "",
	"jwt_not_before_validation_skew": 0,
	"use_go_plugin_auth": false,
	"jwt_identity_base_field": "",
	"allowed_ips": [],
	"request_signing": {
		"is_enabled": false,
		"secret": "",
		"key_id": "",
		"algorithm": "",
		"header_list": [],
		"certificate_id": "",
		"signature_header": ""
	},
	"org_id": "5",
	"enable_ip_whitelisting": false,
	"global_rate_limit": {
		"rate": 0,
		"per": 0
	},
	"protocol": "",
	"enable_context_vars": false,
	"tags": [

	],
	"basic_auth": {
		"disable_caching": false,
		"cache_ttl": 0,
		"extract_from_body": false,
		"body_user_regexp": "",
		"body_password_regexp": ""
	},
	"listen_port": 0,
	"session_provider": {
		"name": "",
		"storage_engine": "",
		"meta": {}
	},
	"auth_configs": {
		"authToken": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		},
		"basic": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		},
		"coprocess": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		},
		"hmac": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		},
		"jwt": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		},
		"oauth": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		},
		"oidc": {
			"use_param": false,
			"param_name": "",
			"use_cookie": false,
			"cookie_name": "",
			"auth_header_name": "Authorization",
			"use_certificate": false,
			"validate_signature": false,
			"signature": {
				"algorithm": "",
				"header": "",
				"secret": "",
				"allowed_clock_skew": 0,
				"error_code": 0,
				"error_message": ""
			}
		}
	},
	"strip_auth_data": false,
	"certificates": [],
	"enable_signature_checking": false,
	"use_openid": false,
	"internal": false,
	"jwt_skip_kid": false,
	"enable_batch_request_support": false,
	"enable_detailed_recording": true,
	"response_processors": [],
	"use_mutual_tls_auth": false
}

If you are still having challenges then can you share

  1. Debug Log of the request
  2. Current API definition
  3. Curl code snippet

curl -v http://ec2-18-142-155-240.ap-southeast-1.compute.amazonaws.com:8080/CloudGateway/rest/Ping -u “cibadmin:admin”

GET /CloudGateway/rest/Ping HTTP/1.1
Authorization: Basic Y2liYWRtaW46YWRtaW4=
User-Agent: curl/7.29.0
Host: ec2-18-142-155-240.ap-southeast-1.compute.amazonaws.com:8080
Accept: /

< HTTP/1.1 200 OK
< Content-Length: 0
< Content-Type: text/plain;charset=UTF-8
< Date: Wed, 10 Nov 2021 14:34:58 GMT
< Server: Apache
< X-Ratelimit-Limit: -1
< X-Ratelimit-Remaining: -1
< X-Ratelimit-Reset: 1636552740
<

API Definition:

cat cloudgatewayhttpbasicauth.json
{
“name”: “cloudgatewayhttpbasicauth”,
“slug”: “cloudgatewayhttpbasicauth”,
“listen_port”: 0,
“protocol”: “”,
“enable_proxy_protocol”: false,
“api_id”: “cloudgatewayhttpbasicauth”,
“org_id”: “5”,
“use_keyless”: false,
“use_oauth2”: false,
“use_openid”: false,
“openid_options”: {
“providers”: null,
“segregate_by_client”: false
},
“oauth_meta”: {
“allowed_access_types”: null,
“allowed_authorize_types”: null,
“auth_login_redirect”: “”
},
“auth”: {
“use_param”: false,
“param_name”: “”,
“use_cookie”: false,
“cookie_name”: “”,
“auth_header_name”: “”,
“use_certificate”: false,
“validate_signature”: false,
“signature”: {
“algorithm”: “”,
“header”: “”,
“secret”: “”,
“allowed_clock_skew”: 0,
“error_code”: 0,
“error_message”: “”
}
},
“auth_configs”: null,
“use_basic_auth”: true,
“basic_auth”: {
“disable_caching”: false,
“cache_ttl”: 0,
“extract_from_body”: false,
“body_user_regexp”: “”,
“body_password_regexp”: “”
},
“use_mutual_tls_auth”: false,
“client_certificates”: null,
“upstream_certificates”: null,
“pinned_public_keys”: null,
“enable_jwt”: false,
“use_standard_auth”: false,
“use_go_plugin_auth”: false,
“enable_coprocess_auth”: false,
“jwt_signing_method”: “”,
“jwt_source”: “”,
“jwt_identity_base_field”: “”,
“jwt_client_base_field”: “”,
“jwt_policy_field_name”: “”,
“jwt_default_policies”: null,
“jwt_issued_at_validation_skew”: 0,
“jwt_expires_at_validation_skew”: 0,
“jwt_not_before_validation_skew”: 0,
“jwt_skip_kid”: false,
“jwt_scope_to_policy_mapping”: null,
“jwt_scope_claim_name”: “”,
“notifications”: {
“shared_secret”: “”,
“oauth_on_keychange_url”: “”
},
“enable_signature_checking”: false,
“hmac_allowed_clock_skew”: 0,
“hmac_allowed_algorithms”: null,
“request_signing”: {
“is_enabled”: false,
“secret”: “”,
“key_id”: “”,
“algorithm”: “”,
“header_list”: null,
“certificate_id”: “”,
“signature_header”: “”
},
“base_identity_provided_by”: “”,
“definition”: {
“location”: “header”,
“key”: “x-api-version”,
“strip_path”: false
},
“version_data”: {
“not_versioned”: true,
“default_version”: “”,
“versions”: {
“Default”: {
“name”: “Default”,
“expires”: “”,
“paths”: {
“ignored”: null,
“white_list”: null,
“black_list”: null
},
“use_extended_paths”: true,
“extended_paths”: {
“validate_json”: [{
“method”: “any”,
“path”: “Ping”,
“schema”: {
“properties”: {
“age”: {
“description”: “Age in years”,
“minimum”: 0,
“type”: “integer”
},
“firstName”: {
“type”: “string”
},
“lastName”: {
“type”: “string”
}
},
“required”: [
“firstName”,
“lastName”
],
“title”: “Person”,
“type”: “object”

},

    "error_response_code": 422

}]
},

    "global_headers": null,
    "global_headers_remove": null,
    "global_response_headers": null,
    "global_response_headers_remove": null,
    "ignore_endpoint_case": false,
    "global_size_limit": 0,
    "override_target": ""
  }
}

},
“uptime_tests”: {
“check_list”: null,
“config”: {
“expire_utime_after”: 0,
“service_discovery”: {
“use_discovery_service”: false,
“query_endpoint”: “”,
“use_nested_query”: false,
“parent_data_path”: “”,
“data_path”: “”,
“port_data_path”: “”,
“target_path”: “”,
“use_target_list”: false,
“cache_timeout”: 0,
“endpoint_returns_list”: false
},
“recheck_wait”: 0
}
},
“proxy”: {
“preserve_host_header”: false,
“listen_path”: “/CloudGateway/rest/”,
“target_url”: “https://ip-10-10-31-38.ap-southeast-1.compute.internal:8443”,
“disable_strip_slash”: false,
“strip_listen_path”: false,
“enable_load_balancing”: false,
“target_list”: null,
“check_host_against_uptime_tests”: false,
“service_discovery”: {
“use_discovery_service”: false,
“query_endpoint”: “”,
“use_nested_query”: false,
“parent_data_path”: “”,
“data_path”: “”,
“port_data_path”: “”,
“target_path”: “”,
“use_target_list”: false,
“cache_timeout”: 0,
“endpoint_returns_list”: false
},
“transport”: {
“ssl_insecure_skip_verify”: false,
“ssl_ciphers”: null,
“ssl_min_version”: 0,
“ssl_max_version”: 0,
“ssl_force_common_name_check”: false,
“proxy_url”: “”
}
},
“disable_rate_limit”: false,
“disable_quota”: false,
“custom_middleware”: {
“pre”: null,
“post”: null,
“post_key_auth”: null,
“auth_check”: {
“name”: “”,
“path”: “”,
“require_session”: false,
“raw_body_only”: false
},
“response”: null,
“driver”: “”,
“id_extractor”: {
“extract_from”: “”,
“extract_with”: “”,
“extractor_config”: null
}
},
“custom_middleware_bundle”: “”,
“cache_options”: {
“cache_timeout”: 0,
“enable_cache”: false,
“cache_all_safe_requests”: false,
“cache_response_codes”: null,
“enable_upstream_cache_control”: false,
“cache_control_ttl_header”: “”,
“cache_by_headers”: null
},
“session_lifetime”: 0,
“active”: true,
“internal”: false,
“auth_provider”: {
“name”: “”,
“storage_engine”: “”,
“meta”: null
},
“session_provider”: {
“name”: “”,
“storage_engine”: “”,
“meta”: null
},
“event_handlers”: {
“events”: null
},
“enable_batch_request_support”: false,
“enable_ip_whitelisting”: true,
“allowed_ips”: [“18.142.155.240”,“111.65.34.213”,“42.60.242.130”],
“enable_ip_blacklisting”: false,
“blacklisted_ips”: null,
“dont_set_quota_on_create”: false,
“expire_analytics_after”: 0,
“response_processors”: null,
“CORS”: {
“enable”: false,
“allowed_origins”: null,
“allowed_methods”: null,
“allowed_headers”: null,
“exposed_headers”: null,
“allow_credentials”: false,
“max_age”: 0,
“options_passthrough”: false,
“debug”: false
},
“domain”: “”,
“certificates”: null,
“do_not_track”: false,
“tags”: null,
“enable_context_vars”: false,
“config_data”: null,
“tag_headers”: null,
“global_rate_limit”: {
“rate”: 0,
“per”: 0
},
“strip_auth_data”: false,
“enable_detailed_recording”: false,
“graphql”: {
“enabled”: false,
“execution_mode”: “”,
“version”: “”,
“schema”: “”,
“type_field_configurations”: null,
“playground”: {
“enabled”: false,
“path”: “”
},
“engine”: {
“field_configs”: null,
“data_sources”: null
}
}
}

Debug Log:

Nov 10 09:38:09 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:09” level=debug msg=“Started proxy”
Nov 10 09:38:09 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:09” level=debug msg=Started api_id=cloudgatewayhttpbasicauth api_
Nov 10 09:38:09 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:09” level=debug msg="Upstream request URL: /CloudGateway/rest/Pin
Nov 10 09:38:09 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:09” level=debug msg="Outbound request URL: https://ip-10-10-31-38
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg=Finished api_id=cloudgatewayhttpbasicauth api
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg=“Upstream request took (ms): 1255.591016”
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg="Adding Healthcheck to: cloudgatewayhttpbasic
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg=“Val is: 1255”
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg=“Set value to: 1636555090761132093.1255”
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg=“Done proxy”
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg="Incrementing raw key: cloudgatewayhttpbasica
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg="keyName is: cloudgatewayhttpbasicauth.Reques
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg="Now is:2021-11-10 09:38:10.761234958 -0500 E
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg="Then is: 2021-11-10 09:37:10.761234958 -0500
Nov 10 09:38:10 ip-10-10-31-38.ap-southeast-1.compute.internal tyk[390]: time=“Nov 10 09:38:10” level=debug msg=“Returned: 0”
lines 1346-1389/1389 (END)

Please suggest further. I tried to pass wrong JSON using postman but still getting 200 ok.

{

age: -5

}

I think the issue here is with the method.

"method": "any",

I believe a valid HTTP verb or request method is required here.

Please try modifying the method value and let us know how it goes.

Thanks, It worked after updating method to GET.

I have below queries:

  1. If I want to pass multiple method like GET POST PUT, Is it possible to pass in the same definition or do I need to create separate JSON validation definition.

I tried like method: [“GET”,POST"] but it wasn’t working.

  1. Can we define multiple JSON format definition for different path.

  2. Can we define most generalize format rather than defining specific with attribute, which will just do basic checks on JSON format like all the curly braces are getting closed or commas are in place.

3rd point would be very useful if possible as for my current project I am not sure what data is going to be in the request headers and the requirement is just inspect the JSON basic format not the attribute specific. Your help is much appreciated on this.

Great! Glad to know that the GET method worked.

I have answered your queries below:

If I want to pass multiple method like GET POST PUT, Is it possible to pass in the same definition or do I need to create separate JSON validation definition.

  1. You would need to create a separate JSON validation for each request method.

Can we define multiple JSON format definition for different path.

  1. Yes you can, by simply changing the value of the path. You can also check the root with “/”

Can we define most generalize format rather than defining specific with attribute, which will just do basic checks on JSON format like all the curly braces are getting closed or commas are in place.

  1. Yes you can. That validation check is handled by the schema directly, so if you pass in an object data structure check, it should work. Here is an example below
{
							"method": "PUT",
							"path": "/",
							"schema": {
								"type": "object"
							},
							"error_response_code": 422
						}

One caveat to note is that this only validates the first parameter. For example passing the following:

  1. {}}
  2. {},
  3. {}“This surprisingly works”

in the body will work since the first value is an object.

Hope this helps

HI Team,

Can I do payload validation like either it should be JSON or empty using out of the box feature.

Yes you can. You would need to specify the data structure in the schema

"schema": {
    "type": "string"
}

However, please note that you cannot specify two different types on the same path and method. The first one will take precedence. In simpler terms, the structure below will NOT work, and only check for a valid json since the first definition is an object while the second is a string.

	{
	"method": "GET",
	"path": "/",
	"schema": {
		"type": "object"
	},
	"error_response_code": 422
	},
	{
		"method": "GET",
		"path": "/",
		"schema": {
			"type": "string"
		},
		"error_response_code": 422
	}

If I am passing empty request body:

“error”: “JSON parsing error: EOF”

If I am passing empty request body:

“error”: “(root): Invalid type. Expected: string, given: object”

I updated definition as:

“validate_json”: [{
“method”: “GET”,
“path”: “/”,
“schema”: {
“type”: “string”

},
Please suggest further