Skip to content

Commit

Permalink
REST: Filter out non-top-level schemas from OAS
Browse files Browse the repository at this point in the history
This adds a redocly decorator that removes any schemas not listed in
`specs/global/schemas.json`.

Bug: T377321
Change-Id: Ib662871d0d3ea1a2088c08ee8e6d1d5dda68aee4
  • Loading branch information
jakobw committed Nov 19, 2024
1 parent fe9cf2f commit 72107c4
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 1,966 deletions.
6 changes: 6 additions & 0 deletions repo/rest-api/redocly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ extends:

rules:
security-defined: off

plugins:
- ./redocly/plugin-filter-schemas.js

decorators:
filterSchemas/filterSchemas: on
7 changes: 7 additions & 0 deletions repo/rest-api/redocly/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "wikimedia/server",
"rules": {
"max-len": [ "error", 120 ],
"no-console": "error"
}
}
31 changes: 31 additions & 0 deletions repo/rest-api/redocly/plugin-filter-schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

module.exports = function () {
return {
id: 'filterSchemas',
decorators: {
oas3: {
filterSchemas: function () {
let originalSchemas;

return {
Components: {
leave( components ) {
for ( const key in components.schemas || {} ) {
if ( originalSchemas[ key ] === undefined ) {
delete components.schemas[ key ];
}
}
},
NamedSchemas: {
enter( schemas ) {
originalSchemas = schemas;
}
}
}
};
}
}
}
};
};
Loading

0 comments on commit 72107c4

Please sign in to comment.