Skip to content

Commit ed14ae4

Browse files
committed
Remove section about skipping non API route from README
Looking for a closer integrated solution in #350
1 parent bec37f6 commit ed14ae4

1 file changed

Lines changed: 0 additions & 43 deletions

File tree

README.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -350,50 +350,7 @@ Here your OpenAPI schema defines endpoints starting with `/resource` but your ac
350350
oad = OpenapiFirst.load('openapi.yaml') do |config|
351351
config.path = ->(req) { request.path.delete_prefix('/api') }
352352
end
353-
# Add your custom middleware
354353
use OpenapiFirst::Middlewares::RequestValidation, oad
355-
356-
# You can add ResponseValidation without any customization.
357-
use OpenapiFirst::Middlewares::ResponseValidation, 'openapi.yaml'
358-
```
359-
360-
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.
361-
362-
You can add some lines to selectively validate only paths under `/api` while bypassing others:
363-
364-
```diff
365-
env[OpenapiFirst::PATH] = request.path.to_s.sub(%r"^/api", "")
366-
367-
+ # Only validate paths under /api/
368-
+ if request.path.start_with?('/api/')
369-
super
370-
+ else
371-
+ @app.call(env)
372-
+ end
373-
end
374-
```
375-
376-
And the final code is:
377-
378-
```ruby
379-
class CustomOpenAPIValidation < OpenapiFirst::Middlewares::RequestValidation
380-
def call(env)
381-
request = Rack::Request.new(env)
382-
383-
# Strip the "/api" prefix for schema matching
384-
env[OpenapiFirst::PATH] = request.path.to_s.sub(%r"^/api", "")
385-
386-
# Only validate paths under /api/
387-
if request.path.start_with?('/api/')
388-
super
389-
else
390-
@app.call(env)
391-
end
392-
end
393-
end
394-
395-
use CustomOpenAPIValidation, 'openapi.yaml'
396-
use OpenapiFirst::Middlewares::ResponseValidation, 'openapi.yaml'
397354
```
398355

399356
## Development

0 commit comments

Comments
 (0)