openapi-refactorer
v0.1.0
Published
Break monolithic OpenAPI documents into several files (and put them back together).
Maintainers
Readme
OpenAPI Refactorer
Break monolithic OpenAPI (f.k.a. Swagger) documents into several files (and put them back together). The resulting entrypoint is a valid OpenAPI document and still compatible with common tools.
Currently only the paths object is used for refactoring.
Installation
Install as a CLI
npm install -g openapi-refactorerInstall as a Node.js Module
npm install openapi-refactorerUsage
Basic usage:
openapi-refactorer -i spider.yaml -o baby_spiders.yamlNOTE: existing files will be overwritten
CLI Options
-V, --version output the version number
-i, --input <file> path of the input OpenAPI file.
-o, --output [file] path of the main output OpenAPI file. Required if --join option is not used. When omitted, output is sent to stdout. Missing directories within the file path will be created. Existing file are promptlessly overwritten.
--join whether to join/bundle the an OpenAPI file tree into one document.
-h, --help output usage informationExample
Input file
openapi: 3.0.0
info:
# (...)
paths:
/pets:
get:
summary: List all pets
operationId: listPets
# (...)
responses:
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
# (...)
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
# (...)
responses:
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: stringCommand
openapi-refactorer -i petstore.yaml -o out/main.yamlOutput file structure
out/
├ main.yaml
└ paths/
├ pets.yaml
└ pets/
└ {petId}.yamlOutput files
openapi: 3.0.0
info:
# (...)
paths:
/pets:
$ref: 'paths/pets.yaml#'
'/pets/{petId}':
$ref: 'paths/pets/%7BpetId%7D.yaml#'
components:
schemas:
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: stringget:
summary: List all pets
operationId: listPets
# (...)
responses:
default:
description: unexpected error
content:
application/json:
schema:
$ref: "../main.yaml#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
# (...)get:
summary: Info for a specific pet
operationId: showPetById
# (...)
responses:
default:
description: unexpected error
content:
application/json:
schema:
$ref: '../../main.yaml#/components/schemas/Error'Known Issues
- When joining/bundling: If a reference points to a definition object which itself references directly to another one, the reference is completely resolved. This produces an equivalent document as the original, but not exactly the same document.
Contributing
I'm open for ideas to make OpenAPI Refactorer better. Just send a pull request or open an issue (especially it's more involved).
License
MIT © 2019 Alexis Luengas
