npm package: @pwccnhk/o2p
Description: Toolkit for converting OpenApiSpec 3 to Postman Collection 2 with merge ability
Author: rexlam0630
Latest version: 0.0.8

# O2P - Toolkit for merging OpenAPI to Postman Collection

[![npm Version](https://img.shields.io/npm/v/@pwccnhk/o2p.svg)](https://www.npmjs.com/package/@pwccnhk/o2p)

**Merge OpenAPI 3.0 to existing Postman Collection 2.1**

This project is based on official Postman project [openapi-to-postman](https://github.com/postmanlabs/openapi-to-postman) with ability to merge the converted result to your existing Postman v2.1 collection. 

The existing toolkit do the converting well, but if you're advanced user of Postman, 
you probably found that your pre-flight script, test cases, or even request model, examples get replaced for every convert. 
You can avoiding it by using 

---

### Options

-i / --import: File path to your OpenAPI 3.0 json/yaml

-e / --export: File path to export the converted result

-m / --merge (optional): File path to your existing postman, it will be merged to the converted result

### Examples

- To merge new changes from `openapi.json` with existing collection `my-postman.json` to `postman.json`, type the following command: 
  
  ```bash
  o2p -i openapi.json -m my-postman.json -e postman.json
  ```

- To just convert without merge

  ```bash
  o2p -i openapi.json -e postman.json
  ```
  
### The rules

Add, Update, Delete or Replace? Check below table:

(This is better to have a config file or interactive interface to config the behaviour, welcome to contribute!)

**Terminology:**
- Information: Project name, version
- Variables: Environment variables, Global variable...etc. (ref. [Postman Document](https://learning.getpostman.com/docs/postman/environments_and_globals/variables/))
- Events: Pre-flight script, unit test scrips in Postman
- Item: The actually API request

|                           | Item Only On Left | Item On Both | Item Only On Right |
|---------------------------|-------------------|--------------|--------------------|
| Information               | Add               | Update       | Delete             |
| Variables                 | Add               | No Action    | No Action          |
| Events                    | -                 | No Action    | No Action          |
| ***Item***                |                   |              |                    |
| - Url Host & Path         | -                 | Update       | -                  |
| - Url Query               | Add               | No Action    | Delete             |
| - Method                  | -                 | Update       | -                  |
| - Auth                    | -                 | Update       | -                  |
| - Headers                 | Add               | No Action    | Delete             |
| - Body (Both Raw)         | Add               | Conflict     | No Action          |
| - Body (Both Form)        | Add               | No Action    | Delete             |
| - Body (Other, Same type) | Add               | No Action    | No Action          |
| - Body (Other, Diff type) | Add               | Update       | No Action          |
| - Response (Example)      | Add               | Update       | Delete             |