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

Misleading exception message when validating against schema with non-matching servers #206

Open
tobias-trozowski opened this issue Aug 23, 2023 · 0 comments

Comments

@tobias-trozowski
Copy link

not sure if this is a bug or mere inconvenience...

Description

Misleading exception message when having servers defined in OpenAPI schema but validating against a request object which does not match these servers.

Actual Behaviour

Given we have servers with url paths defined in schema and we're trying to validate a request GET /path against this schema an exception with message OpenAPI spec contains no such operation [/path,get] is raised. Even though GET /path is defined in schema.

Expected Behaviour

Exception message should tell that the request path could not be found for the defined servers.

e.g. OpenAPI spec contains no such operation [/path,get] for the defined servers

Exception Stacktrace

League\OpenAPIValidation\PSR15\Exception\InvalidServerRequestMessage raised in file /var/www/vendor/league/openapi-psr7-validator/src/PSR15/Exception/InvalidServerRequestMessage.php line 13:
Message: Server Request message failed validation
Stack Trace:
#0 /var/www/vendor/league/openapi-psr7-validator/src/PSR15/ValidationMiddleware.php(45): League\OpenAPIValidation\PSR15\Exception\InvalidServerRequestMessage::because(Object(League\OpenAPIValidation\PSR7\Exception\NoOperation))
[... snip ...]
#39 {main}
League\OpenAPIValidation\PSR7\Exception\NoOperation raised in file /var/www/vendor/league/openapi-psr7-validator/src/PSR7/Exception/NoOperation.php line 16:
Message: OpenAPI spec contains no such operation [/path,get]
Stack Trace:
#0 /var/www/vendor/league/openapi-psr7-validator/src/PSR7/ServerRequestValidator.php(67): League\OpenAPIValidation\PSR7\Exception\NoOperation::fromPathAndMethod('/path', 'get')
#1 /var/www/vendor/league/openapi-psr7-validator/src/PSR15/ValidationMiddleware.php(43): League\OpenAPIValidation\PSR7\ServerRequestValidator->validate(Object(Laminas\Diactoros\ServerRequest))
[... snip ...]
#40 {main}

Reproduction Steps

  • Given the follwing OpenAPI schema
openapi: 3.0.0
info:
  version: 1.0.0
  title: Misleading Exception Message
servers:
  - description: Example Server
    url: https://example.com/api/v1
paths:
  /path:
    get:
      responses:
        200:
          description: Successful operation.
        default:
          description: Unexpected Error
  • validating a request GET http://localhost/path against this schema
  • exception is thrown...
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