-
Notifications
You must be signed in to change notification settings - Fork 3
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
Swagger can't handle exceptions on HTTP delete #30
Comments
This is a limitation of swagger/openapi. There is no way that I've seen to define the A CakePHP Middleware can be added like this to force wildcard # src/Application.php
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
$middlewareQueue
// Force wildcard accept header to application/json responses
->add(function(ServerRequestInterface $request, RequestHandlerInterface $handler){
/*if ($request->getMethod() !== 'DELETE') {
return $handler->handle($request);
}*/
$accept = $request->getHeader('accept');
$item = reset($accept);
if ($item === '*/*') {
return $handler->handle($request->withHeader('accept', 'application/json'));
}
return $handler->handle($request);
})
// ... additional middleware
return $middlewareQueue;
} This will handle the default swagger functionality: curl -X DELETE "http://localhost:8080/admin/actors/123123123" -H "accept: */*" |
If desired, this can be isolated specifically to Swagger by adding a custom header. See: swagger-api/swagger-ui#2793 Example: <script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: '<?php echo $url ?>',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region
ui.getConfigs().requestInterceptor = (req) => { req.headers['X-API-CLIENT']= 'SWAGGER'; return req; }
window.ui = ui
}
</script> |
Added to demo application |
What Happened
Tried deleting a record that doesn't exist via swagger interface. An exception is generated which causes swagger to crash.
Expected Behavior
404 response
Steps to Reproduce
Version and Platform (please complete the following information):
The text was updated successfully, but these errors were encountered: