stoplightio / prism

Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
https://stoplight.io/open-source/prism
Apache License 2.0
4.3k stars 346 forks source link

Request body validation is not working #2591

Open lopenchi opened 2 months ago

lopenchi commented 2 months ago

Context

When using the Stoplight mock server, I encountered an issue where the validation does not work as expected when there is incorrect data. This issue affects users who rely on accurate validation responses for API testing and mocking.

Current Behavior

Instead of throwing an error for invalid data, the mock server returns a 200 OK status, incorrectly indicating that the validation passed.

Expected Behavior

When an invalid data is sent, throw a 400 error

Possible Workaround/Solution

No ideas

Steps to Reproduce

  1. Define a new path with request body (object) in the Stoplight project
    "/v1/Conversations": {
      "description": "A Participant resource represents a member of the conversation.",
      "post": {
        "description": "Add a new participant to the conversation",
        "parameters": [],
        "responses": {
          "201": ...
        },
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "title": "CreateConversationParticipantRequest",
                "properties": {
                  "MessagingBinding.Address": {
                    "type": "string",
                    "description": "The address of the participant's device"
                  }
                }
              },
            }
          }
        }
      }
    },
  2. Send a request with data that does not meet the validation criteria (e.g., missing required fields or invalid field lengths).
    curl -X POST "http://127.0.0.1:4010/v1/Conversations" \
    --data-urlencode "MessagingBindingAddress=+15558675310" \
  3. Observe that the server incorrectly returns a 200 OK status. MessagingBindingAddress must be MessagingBinding.Address

Environment

rtritean commented 2 months ago

Having the same problem, all of our pipelines broke.