hapi-openapi
hapi-openapi copied to clipboard
Bug: Paths with "x-" anywhere in a path name do not appear in the Swagger UI
Bug Description
Any Path that has x- anywhere in the path name does not show up in the Swagger UI. The path does still work in the service if you make a request to it.
Example:
{
"paths": {
"/api/example/tax-district": {
...
}
}
}
Cause
The stripVendorExtensions function looks for vendor extensions with the regex /\x-(.*)/ . This regex matches key names with x- positioned anywhere in the text, and removes them.
I presume that this function is run after the routes are configured (since the endpoint still works), but before the reponse content is assembled for the request from the UI to fetch swagger.json.
Solution
The OpenAPI specification says that vendor extensions are properties that start with x-, so this behavior is a bug.
The regex should be changed to this: /^\x-(.*)/
The added caret at the start causes the regex to only match keys that begin with x-, rather than matching them anywhere in the string