thephpleague / openapi-psr7-validator

It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications
MIT License
526 stars 94 forks source link

Improverbosity by InvalidBody showing the root cause and the reason. #184

Closed DEVizzent closed 1 year ago

DEVizzent commented 1 year ago

Most of times we I use this lib for testing, validating request and responses according documentation y got InvalidBody message. So I have to debug when this exception is thrown to see the previous one and come across the root cause of the error. I used a try catch on my side to add more context to this error, but I think it can be usefull for all.

Body does not match schema for content-type "application/json" for Response [put /post/1]

Don't provide any context about why it failed. With this change you will see:

Body does not match schema for content-type "application/json" for Response [put /post/1]. [Value expected to be 'integer', 'string' given in User -> id]

Whith this message we can identify the root cause "User -> id" and the reason.

DEVizzent commented 1 year ago

Nice. I will do it :)

El sáb., 28 ene. 2023 9:21, Pavel Batanov @.***> escribió:

@.**** commented on this pull request.

In src/PSR7/Exception/Validation/InvalidBody.php https://github.com/thephpleague/openapi-psr7-validator/pull/184#discussion_r1089681398 :

@@ -17,7 +19,13 @@ public static function becauseBodyDoesNotMatchSchema( SchemaMismatch $prev ): self { $exception = static::fromAddrAndPrev($addr, $prev);

  • $exception->message = sprintf('Body does not match schema for content-type "%s" for %s', $contentType, $addr);
  • $exception->message = sprintf(
  • 'Body does not match schema for content-type "%s" for %s. [%s in %s]',
  • $contentType,
  • $addr,
  • substr($prev->getMessage(), 0, -1),
  • implode('->', $prev->dataBreadCrumb()->buildChain())

I've got it. Testing doesn't have that much tooling indeed. What do you think about introducing some kind of global toggle like Validator/Debug::enable() (or maybe Verbose::enable() ) in order to make it configurable ? I really want to keep generic flow simple since these messages are not machine readable in any case and format (as I specified for oneOf and allOf) can be very debatable

— Reply to this email directly, view it on GitHub https://github.com/thephpleague/openapi-psr7-validator/pull/184#discussion_r1089681398, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJW2WAUJCHXHDRUAYEQ2FITWUTJHPANCNFSM6AAAAAAUH7XCTA . You are receiving this because you authored the thread.Message ID: @.*** com>

scaytrase commented 1 year ago

Can you please use something meaningful in commit author? I'd like to preserve original authorship of commits in general, but have to squash and fix commits of previous PR because they have no name neither linked to github account via email of commit being linked to any GH account

DEVizzent commented 1 year ago

Can you please use something meaningful in commit author? I'd like to preserve original authorship of commits in general, but have to squash and fix commits of previous PR because they have no name neither linked to github account via email of commit being linked to any GH account

Sure, I'll do it tomorrow morning. I will check the commit history to find some examples

DEVizzent commented 1 year ago

Can you please use something meaningful in commit author? I'd like to preserve original authorship of commits in general, but have to squash and fix commits of previous PR because they have no name neither linked to github account via email of commit being linked to any GH account

Sure, I'll do it tomorrow morning. I will check the commit history to find some examples

@scaytrase Yesterday I didn't understand what you were saying, because I have properly configured my global user.name and user.email, but I don't know why I wasn't configured in this concret project :exploding_head: I configured and reset the commit author.

DEVizzent commented 1 year ago

@scaytrase Can you confirm commit autor is now correct and merge? Thank you :+1: .

scaytrase commented 1 year ago

Looks good! Thanks. I'll merge it a bit later, sorry, a bit busy last days

scaytrase commented 1 year ago

thanks @DEVizzent !