Skip to content

Commit

Permalink
Merge pull request #107 from joolfe/develop
Browse files Browse the repository at this point in the history
Add CLI implementation
  • Loading branch information
joolfe authored Apr 30, 2021
2 parents b7a80d5 + bb995f5 commit b735275
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ node_modules/*
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.cache

.idea
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"execa"
]
}
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
## [1.8.0](https://github.com/joolfe/postman-to-openapi/compare/1.7.1...1.8.0) (2021-04-30)


### Features

* addd testa dn support for node 14 Close [#104](https://github.com/joolfe/postman-to-openapi/issues/104) ([4fe0284](https://github.com/joolfe/postman-to-openapi/commit/4fe02849a55f01bfa563174c5c47bf07c2370817))
* change cli parser (wip) ([2009923](https://github.com/joolfe/postman-to-openapi/commit/20099237ac1a85d4945a3e19e1c147c4b8206c8e))
* cli added to library ([5df5d9b](https://github.com/joolfe/postman-to-openapi/commit/5df5d9b5cc985b6418f2bb1ab44411dd7624b8d3))
* files configured in package.json Close [#103](https://github.com/joolfe/postman-to-openapi/issues/103) ([0ac1cd2](https://github.com/joolfe/postman-to-openapi/commit/0ac1cd2901d63b59d9bd21f4983e86f6f79cb961))
* husky version 6 ([1f39c49](https://github.com/joolfe/postman-to-openapi/commit/1f39c4968d2b23e17c935b90df85795b7493716c))
* keep old husky config ([1d85167](https://github.com/joolfe/postman-to-openapi/commit/1d851677c39bd4b977cd4f9ddeea79bbd649e37a))
* simple cli called p2o ([a4cea3f](https://github.com/joolfe/postman-to-openapi/commit/a4cea3f9a4e99b14978039d46333a303e7e6919c))
* using aslant instead standard.js Close [#94](https://github.com/joolfe/postman-to-openapi/issues/94) ([4ab6aef](https://github.com/joolfe/postman-to-openapi/commit/4ab6aef7fb51328573b387fed920ff5d90abee5c))
* **wip:** first version of cli ([a259287](https://github.com/joolfe/postman-to-openapi/commit/a259287745556fad13e5e6d0399f47d0e4719abb))


### Bug Fixes

* avoid fail `body.raw` is empty string Close [#101](https://github.com/joolfe/postman-to-openapi/issues/101) ([1c376cf](https://github.com/joolfe/postman-to-openapi/commit/1c376cff2bc77420ae96fb188d27bac94f0c349b))
* some adaptions to use husky ([39d1a35](https://github.com/joolfe/postman-to-openapi/commit/39d1a35da9eae56a560d61102229249f31daaefe))


### Build System

* update some deps ([22c0086](https://github.com/joolfe/postman-to-openapi/commit/22c0086ec58c38e2763374bb93533e0650a1834a))


### Code Refactoring

* only one file and ass more test ([1c440da](https://github.com/joolfe/postman-to-openapi/commit/1c440da2b3f93ce2085026a7bbc0bb905a94efc3))


### Documentation

* add cli references ([739ea64](https://github.com/joolfe/postman-to-openapi/commit/739ea64f289d61706f7ddb644a619fe6bfc65eaf))
* update changelog ([7813e7c](https://github.com/joolfe/postman-to-openapi/commit/7813e7c1ffd58bbe9b2325b8de69f288deca8ace))

### [1.7.3](https://github.com/joolfe/postman-to-openapi/compare/1.7.1...1.7.3) (2021-04-24)


Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Or in other words, transform [this specification](https://schema.getpostman.com/
[![docs](https://img.shields.io/badge/docs-here-yellow)](https://joolfe.github.io/postman-to-openapi/)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)


## Installation

Using `npm`:
Expand All @@ -28,8 +27,16 @@ Using `yarn`:
yarn add postman-to-openapi
```

To install as a `cli` just

```bash
npm i postman-to-openapi -g
```

## Quick Usage

As a library

```js
// Require Package
const postmanToOpenApi = require('postman-to-openapi')
Expand Down Expand Up @@ -59,6 +66,12 @@ postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'General' })
})
```

As a cli

```bash
p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json
```

## Documentation

All features, usage instructions and help can be found in the [Documentation page](https://joolfe.github.io/postman-to-openapi/)
Expand Down
50 changes: 50 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

const { program } = require('commander')
const { version } = require('../package.json')
const postmanToOpenApi = require('../lib')
const { promises: { readFile } } = require('fs')

const additionalHelp = `
Example calls:
$ p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json
For more info about how to use it visit our documentation in <https://joolfe.github.io/postman-to-openapi/>
`

program
.version(version, '-v, --vers', 'Output the current version of the library.')
.name('p2o')
.usage('<collection> [options]')
.addHelpText('after', additionalHelp)
.arguments('<collection>')
.description('Transform a postman collection to OpenAPI specification yml.', {
collection: 'Relative path to the Postman collection json file'
})
.option('-f, --file <file>', 'Relative path to the file where result will be saved. If empty result will be returned by cli.')
.option('-o, --options <options>', 'Relative path to json file that contain the optional parameters for the transformation.')
.action(async (collection, { file, options }, command) => {
try {
const parsedOptions = await parseOptions(options)
const result = await postmanToOpenApi(collection, file, parsedOptions)
console.info(result)
} catch (err) {
throw new Error(err)
}
})

program
.parseAsync()
.catch(err => {
process.exitCode = 1
console.error(err.message)
})

async function parseOptions (optionsPath) {
try {
return optionsPath ? JSON.parse(await readFile(optionsPath)) : {}
} catch (err) {
throw new Error(`invalid "options" parameter -> ${err.message}`)
}
}
53 changes: 38 additions & 15 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@

## Features at a glance

- Postman Collection v2.1 and v2.0.
- OpenApi 3.0
- Basic info API from Postman info or customizable.
- Basic method conversion (GET, POST, PUT...).
- Support Postman folders as tags.
- Transform query, headers and path parameters (description, required...).
- Postman variables as Path parameters.
- Automatic infer types from query and headers parameters.
- Support Json and Text body formats.
- Global Authorization parse or by configuration (Basic and Bearer).
- Contact and License from variables or by configuration.
- Provide meta-information as a markdown table.
- Path depth configuration.
- Response status code parse from test.
* Postman Collection v2.1 and v2.0.
* OpenApi 3.0
* 🆕 Cli available
* Basic info API from Postman info or customizable.
* Basic method conversion (GET, POST, PUT...).
* Support Postman folders as tags.
* Transform query, headers and path parameters (description, required...).
* Postman variables as Path parameters.
* Automatic infer types from query and headers parameters.
* Support Json and Text body formats.
* Global Authorization parse or by configuration (Basic and Bearer).
* Contact and License from variables or by configuration.
* Provide meta-information as a markdown table.
* Path depth configuration.
* Response status code parse from test.

See [Features](#features) section for more details about how to use each of this features.

Expand All @@ -37,17 +38,25 @@ See [Features](#features) section for more details about how to use each of this

# Install

To use local in your Node.js project as a library

```bash
npm i postman-to-openapi --save
```

To use as a cli coming soon...
To use as a cli

```bash
npm i postman-to-openapi -g
```

</div></div>
<div class="tilted-section"><div markdown="1">

# Usage

## As library

Use the library is as easy as use a single method `async postmanToOpenApi(inputPath, outputPath, options)`, the parameters are:

| Param | Description |
Expand Down Expand Up @@ -86,6 +95,20 @@ postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'General' })
})
```

## As cli

After install just need to

```bash
p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json
```

All the field described in [options](#options) can be provided and used in the cli, for more info an all the available options just check the cli help

```bash
p2o -h
```

## Options

The third parameter used in the library method is an `options` object containing the optional parameters for the transformation, the allowed parameters are:
Expand Down
Loading

0 comments on commit b735275

Please sign in to comment.