This script processes an OpenAPI document in JSON format and flattens any oneOf arrays that contain only a single $ref object.
It transforms structures like:
"oneOf": [
{
"$ref": "#/components/schemas/TemplateDto"
}
]into:
"$ref": "#/components/schemas/TemplateDto"node flatten-oneof.js <input-file-path> [output-file-path]If no output file path is provided, the result will be saved as <input-filename>-flattened.json in the same directory.
const { flattenSingleOneOf } = require('./flatten-oneof');
flattenSingleOneOf('input.json', 'output.json');A test OpenAPI document is included in this repository. To test the function, run:
node flatten-oneof.js test-openapi.jsonThis will create a new file called test-openapi-flattened.json with the processed content.