Add remove internal schema properties decorator
We adjust the `demo-plugin.js` file, add the new decorator, and adjust the `.redocly.yaml` configuration file to use the decorator.
```js plugins/demo-plugin.js
const RemoveInternalOperations = require('./decorators/remove-internal-operations');
const RemoveInternalSchemaProperties = require('./decorators/remove-internal-schema-properties');
const id = 'demo';
/** @type {import('@redocly/openapi-cli').CustomRulesConfig} */
const decorators = {
oas3: {
'remove-internal-operations': RemoveInternalOperations,
'remove-internal-schema-properties': RemoveInternalSchemaProperties,
},
};
module.exports = {
id,
decorators,
};
```
```js plugins/decorators/remove-internal-schema-properties.js
module.exports = RemoveInternalSchemaProperties;
/** @type {import('@redocly/openapi-cli').OasDecorator} */
function RemoveInternalSchemaProperties() {
return {
SchemaProperties: {
leave(properties) {
for (const propertyName of Object.keys(properties)) {
if (properties[propertyName]['x-internal']) {
delete properties[propertyName];
}
}
}
}
}
};
```
```yaml .redocly.yaml
# See https://redoc.ly/docs/cli/configuration/ for more information.
apiDefinitions:
internal: openapi/internal.yaml
main: openapi/external.yaml
lint:
extends:
- recommended
plugins:
- './plugins/demo-plugin.js'
decorators:
demo/remove-internal-operations: error
demo/remove-internal-schema-properties: error
referenceDocs:
htmlTemplate: ./docs/index.html
theme:
colors:
primary:
main: "#32329f"
```
Create a bundle for internal use (including all of the internal paths, operations and schema properties):
```shell
openapi bundle --skip-decorator=demo/remove-internal-operations --skip-decorator=demo/remove-internal-schema-properties -o dist/internal.json
```
In Redocly's API registry set a special environment variable `OPENAPI_CLI_BUNDLE_ARGS` with the value of `--skip-decorator=demo/remove-internal-schema-properties`.
SchemaProperties is an object, so we use the Object.keys() method to iterate since we cannot iterate on an object directly.
You may also want to create a custom rule to make sure no `x-internal` properties are marked as required.