Skip to content

michaelduerrwhiteduck/Flatten_OneOf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAPI oneOf Flattener

This script processes an OpenAPI document in JSON format and flattens any oneOf arrays that contain only a single $ref object.

Example

It transforms structures like:

"oneOf": [
    {
      "$ref": "#/components/schemas/TemplateDto"
    }
]

into:

"$ref": "#/components/schemas/TemplateDto"

Usage

Command Line

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.

As a Module

const { flattenSingleOneOf } = require('./flatten-oneof');

flattenSingleOneOf('input.json', 'output.json');

Test

A test OpenAPI document is included in this repository. To test the function, run:

node flatten-oneof.js test-openapi.json

This will create a new file called test-openapi-flattened.json with the processed content.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors