Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prestonvanloon/swagger-aggregator
Aggregate several swagger APIs in one
https://github.com/prestonvanloon/swagger-aggregator
Last synced: about 4 hours ago
JSON representation
Aggregate several swagger APIs in one
- Host: GitHub
- URL: https://github.com/prestonvanloon/swagger-aggregator
- Owner: prestonvanloon
- License: mit
- Created: 2016-04-12T21:23:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-17T17:38:23.000Z (over 8 years ago)
- Last Synced: 2024-09-18T18:18:49.033Z (15 days ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 10
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swagger-aggregator
[![Build Status](https://travis-ci.org/prestonvanloon/swagger-aggregator.svg?branch=master)](https://travis-ci.org/prestonvanloon/swagger-aggregator)
[![Coverage Status](https://coveralls.io/repos/github/prestonvanloon/swagger-aggregator/badge.svg?branch=master)](https://coveralls.io/github/prestonvanloon/swagger-aggregator?branch=master)swagger-aggregator is a tool to merge multiple swagger REST API schemas into one schema.
This is helpful if you are using an API Gateway approach to your REST API.
# Example Usage
swagger.yaml
```yaml
swagger: '2.0'
info:
version: "1.0.0"
title: "API Gateway"
description: This swagger file was aggregated using swagger-aggregator!basePath: /v2
x-apis:
pet: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml
uber: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/uber.json
trains: local/file/trains.yaml
```The `x-apis` property is the list of external or local schemas to aggregate.
To use `swagger-aggregator`, simply require it and pass the file name to aggregate. `swagger-aggregator` returns a promise with the JSON object result.
```
npm install --save-dev swagger-aggregator
``````javascript
const aggregator = require('swagger-aggregator');
const fs = require('fs');module.exports = function() {
return aggregator('swagger.yaml')
.then(result => {
fs.writeFileSync('dist/aggregated.json', JSON.stringify(result));
});
};```