feat(openAPI): allow hiding routes
๐ Linked issue
#2889
โ Type of change
- [ ] ๐ Documentation (updates to the documentation, readme, or JSdoc annotations)
- [ ] ๐ Bug fix (a non-breaking change that fixes an issue)
- [ ] ๐ Enhancement (improving an existing functionality like performance)
- [x] โจ New feature (a non-breaking change that adds functionality)
- [ ] ๐งน Chore (updates to the build process or auxiliary tools and libraries)
- [ ] โ ๏ธ Breaking change (fix or feature that would cause existing functionality to change)
๐ Description
This PR adds a new property openAPIEnabled to the NitroRouteMeta and NitroRouteConfig types. Using this property one can include/exclude specific routes in the generated _openapi.json.
To only include a part of the backend one can do for example:
export default defineNitroConfig({
experimental: {
openAPI: true,
},
routeRules: {
"**": {
openAPIEnabled: false,
},
"/api/public/**": {
openAPIEnabled: true,
},
},
});
It is also possible to override this rule using the routes meta, like:
// /api/public/exceptionRoute.ts
defineRouteMeta({
openAPIEnabled: false
})
๐ Checklist
- [x] I have linked an issue or discussion.
- [x] I have updated the documentation accordingly.
hey, @horvbalint what's the progress on this? I looked at the checks and the error don't seem to have anything to do with the additon of the property.
hey, @horvbalint what's the progress on this? I looked at the checks and the error don't seem to have anything to do with the additon of the property.
Hi, the PR is ready for review I think. The error in the checks dont seem to come from my changes, but I had no time to investigate it :/
hey, @horvbalint what's the progress on this? I looked at the checks and the error don't seem to have anything to do with the additon of the property.
Hi, the PR is ready for review I think. The error in the checks dont seem to come from my changes, but I had no time to investigate it :/
Hello @pi0, could we get this merged please?
Expecting to be able to merge secondary PRs, a lot of the OpenAPI generated by the current code is not needed
I was also looking for this feature. In the mean time I achieved the same using a nitro plugin:
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook("beforeResponse", (event, { body }) => {
if (event.path === "/openapi.json") {
const entriesToDelete = [
"/openapi.json",
"/_docs/scalar",
"/",
];
entriesToDelete.forEach((entry) => {
delete body.paths[entry];
});
}
});
});