Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions Api/Weather.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ paths:
required: true
type: string
format: date-time

# Expected responses for this operation:
responses:
# Response code
Expand All @@ -48,16 +48,33 @@ paths:
# A schema describing your response object.
# Use JSON Schema format
schema:
title: Weather
type: object
properties:
degrees:
type: double
weatherState:
type: string
humidity:
type: double
icon:
type: image
$ref: '#/definitions/Weather'
404:
description: Unsuccesful response
description: Unsuccesful response
schema:
$ref: '#/definitions/Error'
definitions:
Weather:
type: object
properties:
degrees:
type: number
format: double
weatherState:
type: string
humidity:
type: number
format: double
icon:
type: string
format: byte
Error:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
fields:
type: string
4 changes: 2 additions & 2 deletions Api/traffic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ definitions:
type: integer
description: Display name of product.
location:
$ref: '#/definitions/Location'
$ref: '#/definitions/LocationCoord'
detour:
type: string
description: Detour information.
Location:
LocationCoord:
type: object
properties:
latitude:
Expand Down
10 changes: 5 additions & 5 deletions Api/translation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ schemes:
- http
consumes:
- application/x-www-form-urlencoded
produces:
produces:
- application/json,
- application/xml
host: localhost
# Describe your paths here
paths:
/:
/translations:
# This is a path endpoint. Change it.
# This is a HTTP operation

get:
# Describe this verb here. Note: you can use markdown
description: |
Gets `Translation` string.
# This is array of GET operation parameters:

parameters:
# An example parameter that is in query and is required
- name: text
Expand Down Expand Up @@ -70,7 +70,7 @@ paths:
schema:
title: You have an error in your application
type: string
/fill:
/translations/fill:
put:
parameters:
- name: translation
Expand Down
1 change: 1 addition & 0 deletions merged/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
27 changes: 27 additions & 0 deletions merged/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Merge apis

## Dependencies
- [node ^4.2.5](https://nodejs.org/en/)
- [npm ^3.5.3](https://www.npmjs.com/)

## Install
`$ npm install`

## Usage
`$ node index.js -d destinationFileName folder/inputfile1.yaml inputfile2.yaml /folder/inputfile3.json [...]`

The above command will merge all the the swagger specifications files into one file.
The file will contain the following information, schemes, host and basePath. These can be changed in the `index.js` file.
```javascript
var info = {
version: "1.0.0",
title: "TUIse",
description: "A bot designed by TUI HackFridays\n"
};
var schemes = ['http', 'https'];
var host = 'api.tuise.eu';
var basePath = '/v1';
```

### Arguments
You can use `-d` or `--destination` to set the destination file name. By default it uses `bundled_result`.
52 changes: 52 additions & 0 deletions merged/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var swaggermerge = require('swagger-merge');
var fs = require('fs');
var path = require('path');
var YAML = require('yaml-js');
var chalk = require('chalk');
var arguments = require('minimist')(process.argv.slice(2));

var _error = chalk.bold.red;
var _warning = chalk.bold.yellow;
var _info = chalk.bold.blue;
var _success = chalk.bold.green;
var swaggerfiles = [];
var destination = (arguments.d || arguments.destination || 'bundled_result') + '.json'
var info = {
version: "1.0.0",
title: "TUIse",
description: "A bot designed by TUI HackFridays\n"
};
var schemes = ['http', 'https'];
var host = 'api.tuise.eu';
var basePath = '/v1';

for(var index in arguments._) {
var file = arguments._[index];
if(fs.existsSync(file)) {
var ext = path.extname(file);
if(ext == '.yaml' || ext == '.yml') {
var obj = YAML.load(fs.readFileSync(file));
swaggerfiles.push(obj);
} else if (ext == '.json') {
swaggerfiles.push(fs.readFileSync(file));
} else {
console.log(_error('[ERROR]'), 'Can\'t parse the file - ', file);
}
}
}

if(swaggerfiles.length > 0) {
swaggermerge.on('warn', function (msg) {
console.log(_warning('[WARNING]'), msg);
});

var merged = swaggermerge.merge(swaggerfiles, info, basePath, host, schemes)

fs.writeFile(destination, JSON.stringify(merged, null, 2), function (err) {
if (err)
return console.error('[ERROR]',err);
console.log(_info('[INFO]'), 'Merged all the files into', _success(destination));
});
} else {
console.log(_info('[INFO]'), 'No files to merge.');
}
24 changes: 24 additions & 0 deletions merged/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "swagger-apis-merge",
"version": "1.0.0",
"description": "swagger apis merge",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/TUIHackfridays/tuise-api.git"
},
"keywords": [
"swagger", "merge"
],
"author": "Délio Amaral",
"license": "MIT",
"dependencies": {
"chalk": "^1.1.3",
"minimist": "^1.2.0",
"swagger-merge": "^0.3.1",
"yaml-js": "^0.1.4"
}
}
Loading