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

Duplicate definition of invalid property type #24

Open
wang-qijia opened this issue Dec 19, 2024 · 2 comments
Open

Duplicate definition of invalid property type #24

wang-qijia opened this issue Dec 19, 2024 · 2 comments

Comments

@wang-qijia
Copy link

wang-qijia commented Dec 19, 2024

Hi @frankkilcommins
Is there a duplicate definition of the request types: business-rule-violation, validation-error, and invalid-body-property-value?

Assume there is an API endpoint that requires the value of the type field to be either a or b. If the request contains an invalid value (e.g., c), which of the following would be appropriate for the server to return? It seems any of the above could be used.

curl -X POST https://example.com/api/resource \
-H "Content-Type: application/json" \
-d '{"type": "c"}'
@frankkilcommins
Copy link
Member

Hi @wang-qijia,

Each of the problem types serves a purpose. In the situation you described, it would be best suited to invalid-body-property-value with a problem details response looking something like:

{
   "type":"https://problems-registry.smartbear.com/invalid-body-property-value",
   "title":"Invalid Body Property Value",
   "detail":"The request body contains an invalid body property value.",
   "status":400,
   "errors":[
      {
         "detail":"`c` is an invalid value. Please provide `a` or `b`",
         "pointer":"#/type"
      }
   ]
}

validation-error is also applicable but in this context is not as clear as invalid-body-property-value which is the explicit problem being faced by the client. Think of validation-error as an affordance that gives the ability to return multiple validations errors in one go which may be of slightly mixed type.

business-rule-violation is generally for situations where the client sends a semantically valid request but the server is not able to process the request as it fails to meet business rule expectations.

Hope this helps.

@wang-qijia
Copy link
Author

Thank you for your response.

How is "semantically valid" defined in this context? Can a request with correct syntax but incorrect values also be considered semantically invalid?

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

2 participants