How to validate incoming request schema in karate mock server mode?

I'm trying to write a mock API server in Karate and I want to make sure that the incoming request matches a given schema (or Karate fuzzy expression as given in this example)

Here's what I'm trying, but it's resulting in the following error:

Error

11:42:13.342 [armeria-common-worker-nio-2-9]  WARN  com.intuit.karate - scenario match evaluation failed at line 14: pathMatches('/manufacturers') && methodIs('post') && match request != schema - com.intuit.karate.KarateException: >>>> js failed:
01: pathMatches('/manufacturers') && methodIs('post') && match request != schema
<<<<
org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:1:59 Expected ; but found request
pathMatches('/manufacturers') && methodIs('post') && match request != schema

Feature file

Feature: Manufacturer Mock API Server

Background:
  * configure cors = true
  * def schema = 
    """
      {
        id: "#number",
        name: "#string",
        status: "#string"
      }
    """
  * url 'http://localhost:8080/manufacturers'

Scenario: pathMatches('/manufacturers') && methodIs('post') && match request != schema
  * def responseStatus 400

Scenario: pathMatches('/manufacturers') && methodIs('post') && match request == schema
  * def response = request

Question

Is there any way to validate the schema of an incoming request body?



Read more here: https://stackoverflow.com/questions/67379667/how-to-validate-incoming-request-schema-in-karate-mock-server-mode

Content Attribution

This content was originally published by Saurabh Nanda at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: