Skip to content

Meaningful validation error responses#31

Merged
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
chrusty:validation_error_messages
Jun 27, 2019
Merged

Meaningful validation error responses#31
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
chrusty:validation_error_messages

Conversation

@chrusty
Copy link
Copy Markdown
Contributor

@chrusty chrusty commented Jun 27, 2019

I've found the validation errors returned are not that helpful. Consider the following examples:

  1. Request with a missing path parameter: {"message":"must have a value"}
  2. Request with an invalid enum value for a path parameter: {"message":""}
  3. Request with a missing required attribute in the request body: {"message":"doesn't match the schema"}
  4. Request with an invalid enum value for an attribute in the request body: {"message":"doesn't match the schema"}

This PR makes use of the Error attribute, which comes back as (overly verbose) multi-line text. However, the first line contains a useful amount of detail. The results (for the same scenarios) are as follows:

  1. Request with a missing path parameter: {"message":"Parameter 'someEnumValue' in path has an error: must have a value: must have a value"}
  2. Request with an invalid enum value for a path parameter: {"message":"Parameter 'someEnumValue' in path has an error: JSON value is not one of the allowed values"}
  3. Request with a missing required attribute in the request body: {"message":"Request body has an error: doesn't match the schema: Property 'someProperty' is missing"}
  4. Request with an invalid enum value for an attribute in the request body: {"message":"Request body has an error: doesn't match the schema: Error at \"/somePropery\": JSON value is not one of the allowed values"}

The full error text contains way too much information, including escaped JSON objects to describe the actual schema. I think this is too much info, so the first line seems like an easy way to get a good balance.

@chrusty chrusty changed the title Returning the first line of the error (instead of the 'reason') Meaningful validation error responses Jun 27, 2019
@deepmap-marcinr deepmap-marcinr merged commit 7620434 into oapi-codegen:master Jun 27, 2019
adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
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

Successfully merging this pull request may close these issues.

2 participants