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

Request body is not validated when there are multiple references to the same schema #2574

Open
hansensalim opened this issue Aug 1, 2024 · 0 comments

Comments

@hansensalim
Copy link

Context

An invalid request body is being passed off as valid by validator when a shared schema is being referenced by other endpoint.

Current Behavior

Running mock with --errors flag on OpenAPI that satisfy the condition above returns 2xx even on invalid request body (e.g., missing required property).

Expected Behavior

Invalid request body should return 422.

Possible Workaround/Solution

A workaround is to make sure that no two or more endpoints make reference to a same schema.

Steps to Reproduce

  1. Use the PetStore exampe at https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml
  2. prism mock petstore.yaml --errors
  3. Send an invalid request (i.e., missing name):
    curl --request POST --url http://127.0.0.1:4010/pets --header 'Content-Type: application/json' --data '{"id" : 1}'
  4. This invalid request passes as a success, responding with 201
    image

To see the validation working again:
5. Update the yaml file, remove all other endpoints except the createPets endpoint.
6. Run the same cURL request
curl --request POST --url http://127.0.0.1:4010/pets --header 'Content-Type: application/json' --data '{"id" : 1}'
7. This now works as expected, responding with 422
image

After testing around this validation issue occur whenever the schema #/components/schemas/Pet is being reference by multiple endpoint.

Environment

  • macOS
  • prism v5.8.3
  • node v22.5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant