It is a command-line tool to generate an OpenAPI document as output by reading the provided Swagger/OpenAPI based .json or .yaml file. It can also be used to convert .json to .yaml file or vice-versa.
You should have these applications installed at your system.
node.jsnpm(usually it comes along withnode.js)
You can install it at your system via npm
npm install oadg --globalor
npm i oadg -gThe usage can be found in the help content as shown below
% oadg -h
oadg ~ OpenAPI DocGen
It is a command-line tool to generate an OpenAPI document as output by reading the provided Swagger/OpenAPI based '.json' or '.yaml' file.
Usages:
oadg (--help|--version)
oadg <filepath> (<output>) (--integrated)
oadg <filepath> (<output>) (--json|--yaml) --isolated
oadg <filepath> --dev (--host=<hostaddr>) (--port=<portnum>)
Parameters:
filepath Input Swagger or OpenAPI filepath
output Output file/dir name
hostaddr Serving host address for dev server
portnum Serving port number for dev server
Options:
-h --help Show help
-v --version Show version
-j --json Target output as JSON file
-y --yaml Target output as YAML file
-s --isolated Generate isolated files
-n --integrated Generate integrated file [default: true]
-d --dev Start dev server at <filepath> directory
-u --host=<hostaddr> Set host of dev server [default: localhost]
-p --port=<portnum> Set host of dev server [default: 8080]
You can use any combination of above listed Usages patterns.
Below are the various use cases of this app. Just find out the one relevant for you.
To generate doc for any sample.json, run this command
oadg sample.jsonBy default, it would generate a sample.html file with embedded content. Here, the .html name is extracted from the base filename of sample.json, i.e., sample.
If you specify output name, run this command
oadg sample.json petstoreIt would generate a petstore.html file with embedded content. Here, the provided custom filename is used for .html file.
Similarly, to generate isolated content, run this command
oadg sample.json --isolatedIt would generate a wrapper file as sample.html that loads the sample.json file content.
If you specify output name, run this command
oadg sample.json petstore --isolatedIt would generate a petstore.html file with embedded content. Here, the provided custom filename is used for .html & .json files.
Here, alternative file type could be generated as
oadg sample.json --isolated --yamlThat would generates the sample.yaml along with wrapper file sample.html which loads the sample.yaml file content.
Similarly, you could generate the sample.json along with wrapper file sample.html via
oadg sample.yaml --isolated --jsonYou can convert the file type from json to yaml or vice-versa, like this
oadg sample.json --yamlThat would convert sample.json to sample.yaml.
Similarly, you could generate the sample.json via
oadg sample.yaml --jsonJust make sure not to use --isolated flag in case of file conversion otherwise it will generate wrapper file as well.
In dev-mode, isolated wrapper .html is generated automatically and served via development server on browser. So that you can edit the .json or .yaml source file and preview it live at serving URL.
oadg sample.json --devAfter beginning the dev server, it would automatically opens the default browser with serving URL. You just need to refresh it everytime after you make any change in the .json or .yaml source file.
To run the dev server at different host or port, run this command
oadg sample.json --dev --host=localhost --port=8000Here you can specify the custom host address and/or port number where you want the dev server to seve at.