Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Misc fixes #156

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v7.4.0
v12.13.0
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
language: node_js
node_js: 7.4
cache:
yarn: true
directories:
- node_modules
env:
- TEST_TARGET=lint
- TEST_TARGET=unit
- TEST_TARGET=e2e
- TEST_TARGET=cov
- TEST_CMD=lint
- TEST_CMD=test
- TEST_CMD=test-e2e
- TEST_CMD=coverage
script:
- make test
- yarn run ${TEST_CMD}
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Paw Inc.
Copyright (c) 2015-2018 Paw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,5 @@ transfer: clean importers generators
pack: clean importers generators
sh "$(SCRIPTS)/pack.sh" $(BASE) $(TARGET)

lint:
sh "$(SCRIPTS)/lint.sh" $(BASE)

test:
sh "$(SCRIPTS)/test.sh" $(BASE) $(TEST_TARGET)

validate: lint test

watch:
sh "$(SCRIPTS)/watch.sh" $(BASE) $(COMMAND)
110 changes: 81 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[![Build Status](https://travis-ci.org/luckymarmot/API-Flow.svg?branch=master)](https://travis-ci.org/luckymarmot/API-Flow)

# API-Flow
# API Flow

A flow written in ES6 using Immutable to convert between API description formats (Swagger, etc.) and other programs such as cURL command lines.
A library written in ES6 using [Immutable.js](https://facebook.github.io/immutable-js/docs/) to convert between API description formats (including Swagger and RAML) and applications (including Paw and Postman).

## What formats are supported and what will be in the future

We currently support:
- `Swagger v2.0 (in/out)`
- `RAML v1.0 (in/out)`
- `Postman Collection v2.0 (in/out)`
- `Paw v3.1 (in/out)`

- Swagger v2.0 (in/out)
- RAML v1.0 (in/out)
- Postman Collection v2.0 (in/out)
- Paw v3.1 (in/out)

We intend to support:
- `Swagger v3.0`
- `RAML v0.8`
- `Postman Collection v1.0`
- `Postman Dump v1.0`
- `Insomnia v3.0`
- `Api-Blueprint`

- Swagger v3.0
- RAML v0.8
- Postman Collection v1.0
- Postman Dump v1.0
- Insomnia v3.0
- API Blueprint
- and many more.

## Installation
Expand All @@ -28,32 +31,50 @@ just run
```sh
git clone https://github.com/luckymarmot/API-Flow.git
cd API-Flow
make install
yarn install # or npm install
```

This will install the node module dependencies

## Building the different libraries
### node, web, and webworker

run the following command to build API-Flow for the different environments that you need
### As a Library

Run the following command to build API Flow for the different environments that you need:

```sh
# use TARGET="node" if you only want the node library
make runners TARGET="node web webworker"
# use TARGET=node if you only want the node library
TARGET="node web webworker" make runners
```

### Paw
Possible target environments are:

| Target | Description |
| ----------- | ---------------------------------- |
| `node` | Node library |
| `web` | Web browser library |
| `webworker` | Web library to run in a web worker |

### A a Paw Extension

You can use the following command to add the different extensions to Paw

```sh
# use TARGET="swagger" if you only want the swagger bindings
make transfer TARGET="swagger raml1 postman2"
# use TARGET=swagger if you only want the swagger bindings
TARGET="swagger raml1 postman2" make transfer
```

## Using the npm module
### as a standard library
Possible targets are:

| Target | Description |
| ----------- | ------------------------------------------------ |
| `swagger` | Swagger 2.0 importer and generator |
| `raml1` | RAML 1.0 importer and generator |
| `postman2` | Postman Collection 2.0 importer and generator |

## Using the node module

### As a library

```js
const ApiFlow = require('api-flow'); // if from npm
Expand All @@ -80,27 +101,58 @@ promise.then((data) => {
})
```

### Using as a CLI (coming soon)
### As a CLI
```sh
./node_modules/.bin/babel-node ./bin/api-flow.js some_swagger.json --from swagger --to raml > converted.yml
```

## User Interface

API Flow is one of the main components of [Console.REST](https://github.com/luckymarmot/console-rest). If you're an API user, you can easily use [https://console.rest/](https://console.rest/) to convert API description files. If you're an API provider, you can add a button to your API docs to let your users open and play with your API in client apps including Paw or Postman.

## Formats

| Name | Format | Version |
| ---- | ------ | ------- |
| [Swagger/OAS](https://swagger.io/) | `swagger` | `v2.0` |
| [RAML](https://raml.org/) | `raml` | `v1.0` |
| [Paw](https://paw.cloud) | `paw` | `v3.0` |
| [Postman Collection](https://github.com/postmanlabs/postman-collection) | `postman-collection` | `v2.0` |
| Internal API Flow Data | `internal` | `v1.0` |

## Development

### Testing

```sh
node ./bin/api-flow.js some_swagger.json -f swagger -t raml > converted.yml
yarn run test # unit tests
yarn run test-e2e # integration (end-to-end) tests
```

### User Interface
### Linting

API-Flow is one of the main components of [Console.REST](https://github.com/luckymarmot/console-rest). If you're an API user, you can easily use [https://console.rest/](https://console.rest/) to convert API description files. If you're an API provider, you can add a button to your API docs to let your users open and play with your API in client apps including Paw or Postman.
```sh
yarn run lint
```

### Code coverage

```sh
yarn run coverage
```

## Contributing

PRs are welcomed!
Our sole requirement is that organizations that want to extend API-Flow to support their format write both a parser and a serializer, and not simply a serializer.
Our sole requirement is that organizations that want to extend API Flow to support their format write both a parser and a serializer, and not simply a serializer.

## Documentation
You can find more information about the internal structure of API-Flow in [src](https://github.com/luckymarmot/API-Flow/tree/develop/src). We've also created a set of templates to help speed up the extension process: [loader](https://github.com/luckymarmot/API-Flow/tree/develop/src/loaders/template/v1.0), [parser](https://github.com/luckymarmot/API-Flow/tree/develop/src/parsers/template/v1.0/), and [environment](https://github.com/luckymarmot/API-Flow/tree/develop/src/environments/template)
You can find more information about the internal structure of API Flow in [src](https://github.com/luckymarmot/API-Flow/tree/develop/src). We've also created a set of templates to help speed up the extension process: [loader](https://github.com/luckymarmot/API-Flow/tree/develop/src/loaders/template/v1.0), [parser](https://github.com/luckymarmot/API-Flow/tree/develop/src/parsers/template/v1.0/), and [environment](https://github.com/luckymarmot/API-Flow/tree/develop/src/environments/template)

## License

This repository is released under the [MIT License](LICENSE). Feel free to fork, and modify!
Copyright © 2016 Paw Inc.
Copyright © 2015-2018 Paw.

## Contributors

Expand Down
101 changes: 91 additions & 10 deletions bin/api-flow.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,91 @@
#! /usr/bin/env node
/* eslint-disable */
var FlowCLI = require('../dist/node/api-flow.js').default;

var cli = new FlowCLI(process.argv);
var parser = cli._createParser();
cli.processArguments(parser);
cli.run().then((data) => {
console.log(data)
});
import { resolve } from 'path'
import { existsSync } from 'fs'
import minimist from 'minimist'
import chalk from 'chalk'
import ApiFlow from '../src/api-flow'

// chalk
const success = chalk.bold.green
const error = chalk.bold.red

// formats
const formats = {
swagger: {
format: 'swagger',
version: 'v2.0',
},
raml: {
format: 'raml',
version: 'v1.0',
},
paw: {
format: 'paw',
version: 'v3.0',
},
postman: {
format: 'postman-collection',
version: 'v2.0',
},
internal: {
format: 'internal',
version: 'v1.0',
},
}

// parse CLI
const args = minimist(process.argv.slice(2), {
string: [ 'from', 'to' ],
default: {
to: 'internal'
},
})
const params = args['_']

if (params.length > 1) {
console.log(error('too many parameters'))
process.exit(1)
}
if (params.length === 0) {
console.log(error('missing input parameter'))
process.exit(1)
}
if (!formats[args.from]) {
console.log(error(`unknown format ${args.from}`))
process.exit(1)
}
if (!formats[args.to]) {
console.log(error(`unknown format ${args.to}`))
process.exit(1)
}

const input = resolve(params[0])

if (!existsSync(input)) {
console.log(error(`file does not exist: ${input}`))
process.exit(1)
}

const options = ApiFlow.setup({
options: {
source: {
format: formats[args.from].format,
version: formats[args.from].version,
},
target: {
format: formats[args.to].format,
version: formats[args.to].version,
},
}
})

ApiFlow
.transform({
options,
uri: `file:///${input}`,
})
.then(serialized => {
console.log(serialized)
})
.catch(e => {
console.error('got err:\n', e.stack)
})
2 changes: 1 addition & 1 deletion configs/node/api-flow-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PostmanV2Loader from '../../src/loaders/postman/v2.0/Loader'

import SwaggerV2Parser from '../../src/parsers/swagger/v2.0/Parser'
import RAMLV1Parser from '../../src/parsers/raml/v1.0/Parser'
import PostmanV2Parser from '../../src/loaders/postman/v2.0/Parser'
import PostmanV2Parser from '../../src/parsers/postman/v2.0/Parser'

import SwaggerV2Serializer from '../../src/serializers/swagger/v2.0/Serializer'
import RAMLV1Serializer from '../../src/serializers/raml/v1.0/Serializer'
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
"babel-plugin-transform-flow-strip-types": "6.3.15",
"babel-polyfill": "6.3.14",
"babel-runtime": "6.3.19",
"chalk": "^2.4.1",
"drafter.js": "^2.6.6",
"immutable": "^3.8.1",
"js-yaml": "3.5.5",
"json-schema-faker": "^0.3.7",
"minimist": "^1.2.0",
"raml-1-parser": "^1.1.14",
"raml-parser": "0.8.16",
"request": "^2.72.0",
Expand Down Expand Up @@ -70,13 +72,15 @@
"extends": "./linting/prod.yaml"
},
"scripts": {
"compile": "./node_modules/babel-cli/bin/babel.js --ignore='**/__tests__/' -d lib/ src/",
"flow": "babel-node ./bin/api-flow.js",
"compile": "babel --ignore='**/__tests__/' -d lib/ src/",
"compile-node": "TARGET=node ./node_modules/webpack/bin/webpack.js",
"compile-web": "TARGET=web ./node_modules/webpack/bin/webpack.js",
"compile-worker": "TARGET=webworker ./node_modules/webpack/bin/webpack.js",
"test": "$npm_package_options_mocha \"src/**/__tests__/*.spec.js\"",
"validate": "node validate.js",
"lint": "./node_modules/eslint/bin/eslint.js -c linting/prod.yaml src/"
"test-e2e": "$npm_package_options_mocha --require \"testing/test-require-patch.js\" \"testing/**/*.spec.js\"",
"lint": "eslint -c linting/prod.yaml src/",
"coverage": "NODE_ENV=test node \"./node_modules/.bin/nyc\" \"./node_modules/.bin/mocha\" \"src/**/__tests__/*.spec.js\""
},
"options": {
"mocha": "./node_modules/.bin/mocha --require mocha --compilers js:babel-register --reporter spec"
Expand Down
3 changes: 0 additions & 3 deletions scripts/lint.sh

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/test.sh

This file was deleted.

Loading