You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[How can I adapt request paths that don't match my schema?](#how-can-i-adapt-request-paths-that-dont-match-my-schema)
22
24
-[Development](#development)
23
25
-[Benchmarks](#benchmarks)
24
26
-[Contributing](#contributing)
@@ -327,6 +329,82 @@ That aside, closer integration with specific frameworks like Sinatra, Hanami, Ro
327
329
This gem was inspired by [committee](https://github.com/interagent/committee) (Ruby) and [Connexion](https://github.com/spec-first/connexion) (Python).
328
330
Here is a [feature comparison between openapi_first and committee](https://gist.github.com/ahx/1538c31f0652f459861713b5259e366a).
329
331
332
+
## Frequently Asked Questions
333
+
334
+
### How can I adapt request paths that don't match my schema?
335
+
336
+
If your API is deployed at a different path than what's defined in your OpenAPI schema, you can use `env[OpenapiFirst::PATH]` to override the path used for schema matching.
337
+
338
+
Let's say you have `openapi.yaml` like this:
339
+
340
+
```yaml
341
+
servers:
342
+
- url: https://yourhost/api
343
+
paths:
344
+
# The actual endpoint URL is https://yourhost/api/resource
345
+
/resource:
346
+
```
347
+
348
+
Here your OpenAPI schema defines endpoints starting with `/resource` but your actual application is mounted at `/api/resource`. You can bridge the gap by creating a custom middleware:
349
+
350
+
```ruby
351
+
class CustomOpenAPIValidation < OpenapiFirst::Middlewares::RequestValidation
# You can add ResponseValidation without any customization.
366
+
use OpenapiFirst::Middlewares::ResponseValidation, 'openapi.yaml'
367
+
```
368
+
369
+
In this case, you might want to serve APIs on `/api` while serving rendered pages on other paths which are not managed by OpenAPI schema in a single application.
370
+
371
+
You can add some lines to selectively validate only paths under `/api` while bypassing others:
0 commit comments