commons-excel2swagger
v2.0.0
Published
Make sure to have 1 sheet named **"meta"** for swagger metadata and at least 1 sheet that contains **swagger definitions**
Downloads
99
Readme
EXCEL to SWAGGER Generator
Step 1: Prepare Excel File
Required Sheets:
Make sure to have 1 sheet named "meta" for swagger metadata and at least 1 sheet that contains swagger definitions
Note:
You can find the example sheets and generated swagger with the code
find the sample excel and swagger
1. meta sheet:
This sheet must contain the following properties:
Note: the key and value are headers in this sheet
| key | value | |--------------|-------------------------------------------------| | version | 1.0.0 | | title | Node Template | | description | Terms of service | | serviceTerms | http://swagger.io/terms/ | | email | [email protected] | | licenseName | Apache License Version 2.0 | | licenseUrl | http://www.apache.org/licenses/LICENSE-2.0.html | | host | localhost:8000 | | basePath | / |
2. swagger definitions:
At least 1 sheet is needed with the following format. Note that the first row is header in our case.
All the sheets containing this header will be counted as valid swagger definition sheet.
| controller | endpoint | method | param.name | param.type | param.dataType | param.minlen | param.maxlen | param.description | param.required | param.example | response.name | response.dataType | summary | description |
|------------|----------|--------|------------|------------|----------------|--------------|--------------|-------------------|----------------|---------------|---------------|-------------------|---------|-------------|
An example of sample sheet will look like this:
| controller | endpoint | method | param.name | param.type | param.dataType | param.minlen | param.maxlen | param.description | param.required | param.example | response.name | response.dataType | summary | description | |------------|----------------------------|--------|---------------|------------|----------------|--------------|--------------|-----------------------|----------------|----------------------|---------------|-------------------|--------------------------------------|------------------------------| | | | | | | | | | | | | | | | | | books | /books/v1/getBook/{bookId} | get | bookId | path | string | 4 | 10 | | | 24 | success | boolean | API to get single book by id summary | API to get single book by id | | | | | token | header | string | 50 | 100 | A token used for auth | | | | | | | | books | /books/v1/books | get | sort | query | string | | | | | date | success | boolean | API to get data of books | API to get data of books | | | | | order | query | string | | | | | A | message | string | | | | | | | page | query | string | | | | TRUE | 1 | data | object | | | | | | | limit | query | string | | | | TRUE | 10 | | | | | | | | | token | header | string | | | | | | | | | | | books | /books/v1/books | post | contents | body | string | | | | | | success | boolean | API to add books | API to add books | | | | | id | query | string | | | | | | | | | | | | | | token | header | string | | | | | | | | | | | books | /books/v1/addbooks | post | name | body | string | | | | TRUE | A tale of two cities | success | boolean | API to add data from pbooks | API to add data from pbooks | | | | | pages | body | number | | | | TRUE | 450 | | | | | | | | | author | body | string | | | | | Charles Dickens | | | | | | | | | example1 | query | string | | | example 2 description | TRUE | | | | | | | | | | example2 | query | string | | | | | | | | | | | | | | token | header | string | | | | | | | | | | | employees | /employees/v1/getEmployees | post | contents | body | string | 3 | 100 | contents description | | | success | boolean | API to get Employees | API to get Employees | | | | | id | query | string | 16 | 32 | | | | | | | | | | | | token | header | string | | | | TRUE | | | | | | | | | | emp | body | object | | | | TRUE | | | | | | | | | | qualification | body | array | | | | | | | | | | | employees | /employees/v1/uploadData | post | excelFile | formData | file | | | | | | | | | | | | | | data | formData | string | | | | | | | | | |
Step 2: Generate swagger file
Once you are done with your excel file as instructed above you now have to follow the steps:
1. Install the package as a dev dependency
npm i -D commons-excel2swagger
2. Running commands
Open terminal/console from the root of your project directory where this package is installed.
npx exSwag
npx exSwag C:\downloads\project\project_swagger.xlsx
3. Output
Running the above command will generate a swagger file where your excel file is present
In the above example it will be generated as:
C:\downloads\project\project_swagger.json
4. Verify the output (Optional)
Visit swagger editor and paste the generated swagger json in this editor.
This will show the error(s) if present on the right side of the screen.