Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specmatic rejects external examples containing invalid requests without body #1498

Open
jhomswk opened this issue Dec 24, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@jhomswk
Copy link

jhomswk commented Dec 24, 2024

Description:

Hi! 👋

Specmatic seems to reject external examples containing invalid requests without body
even though the status code indicates an error.

Please, let me know whether I am missing something.
Thank you in advance.


Minimal Example:

🧾 OpenAPI specification:

openapi: 3.0.0

info:
  title: Users Service
  version: 1.0.0

servers:
  - url: http://localhost:9000

paths:
  /register-user:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: string
                  format: uuid
              required:
                - id
      responses:
        201:
          description: user successfully registered
        400:
          description: validation error

✔️ Example 1 - valid request - works:

{
  "http-request": {
    "path": "/register-user",
    "method": "POST",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "id": "4cee792f-6a93-43ec-80c7-a4f2e4e9ed49"
    }
  },
  "http-response": {
    "status": 201
  }
}

✔️ Example 2 - invalid id - works:

{
  "http-request": {
    "path": "/register-user",
    "method": "POST",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "id": "invalid"
    }
  },
  "http-response": {
    "status": 400
  }
}

✔️ Example 3 - missing id - works:

{
  "http-request": {
    "path": "/register-user",
    "method": "POST",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
    }
  },
  "http-response": {
    "status": 400
  }
}

❌ Example 4 - missing body - fails:

{
  "http-request": {
    "path": "/register-user",
    "method": "POST"
  },
  "http-response": {
    "status": 400
  }
}

💻 Error:

error


Steps To Reproduce:

I have prepared a small repository that can be used to reproduce the issue.


System Information:

  • image: znsio/specmatic:2.0.48
@harikrishnan83 harikrishnan83 self-assigned this Dec 28, 2024
@harikrishnan83 harikrishnan83 added the question Further information is requested label Dec 28, 2024
@harikrishnan83
Copy link
Member

@jhomswk Thanks again for the detailed bug report. Really appreciate the sample repo.

This issue looks quite similar to #1494 (the difference being that here the empty body is not being accepted for 400 response examples) and here is a link to a comment I have added on that issue. Even here even if you do to explicitly set a 400 example with empty body, Specmatic Stub server will already return 400 for such requests. Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants