Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from fbenz/2.0
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
fbenz authored Jan 19, 2018
2 parents baee85d + f841d23 commit e56d488
Show file tree
Hide file tree
Showing 22 changed files with 1,633 additions and 67 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ npm install --save restdocs-to-postman
## Command Line Usage

```shell
restdocs-to-postman --folder generated-snippets --export-format postman --output postman-collection.json
restdocs-to-postman --input generated-snippets --export-format postman --determine-folder secondLastFolder --output postman-collection.json
```

From the given folder, all folders are recursively scanned for `curl-request.adoc` and `curl-request.md` files.
Requests can be sorted into folders with `--determine-folder secondLastFolder`.
The function `secondLastFolder` is the only one for now and puts a request from `../items/get/curl-request.adoc` into a folder called `item`.
Host and header replacements can be used with `--replacements replacements.json`.
See [replacement-example.json](https://github.com/fbenz/restdocs-to-postman/blob/master/replacements-example.json)
for an example of a replacement file.
Expand All @@ -48,7 +50,7 @@ for an example of a replacement file.
const converter = require('restdocs-to-postman');

// Convert Spring REST Docs cURL commands to Postman/Insomnia collections
const folder = './target/generated-snippets';
const folderToScan = './target/generated-snippets';
const exportFormat = 'postman';
const replacements = {
host: {
Expand All @@ -62,7 +64,7 @@ const replacements = {
}
]
};
const output = converter.convert(folder, exportFormat, replacements);
const output = converter.convert({folderToScan, exportFormat, replacements});

// Print the result
console.log(output);
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
'use strict';
const converter = require('./src/convert');

module.exports.convert = function (folder, exportFormat, replacements) {
return converter.convert(folder, exportFormat, replacements);
module.exports.convert = function (options) {
return converter.convert(options);
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "restdocs-to-postman",
"version": "1.0.5",
"version": "2.0.0",
"author": "Florian Benz",
"description": "Converts Spring REST Docs cURL snippets to Postman and Insomnia collections",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion replacements-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"headers": [
{
"name": "Authorization",
"newValue": "{{oauth2Token}}"
"newValue": "Bearer {{oauth2Token}}"
}
]
}
71 changes: 64 additions & 7 deletions src/__tests__/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
const fs = require('fs');
const path = require('path');
const converter = require('../../index');
const folderFunctions = require('../folder-functions');

const fixturesPath = path.join(__dirname, './fixtures');
const snippetsPath = path.join(__dirname, './input-snippets');
const fixturesPath = path.join(__dirname, 'fixtures');
const snippetsPath = path.join(__dirname, 'input-snippets');

const exampleReplacements = {
host: {
Expand All @@ -29,7 +30,7 @@ const exampleReplacements = {
headers: [
{
name: 'Authorization',
newValue: '{{oauth2Token}}'
newValue: 'Bearer {{oauth2Token}}'
}
]
};
Expand All @@ -41,25 +42,81 @@ const loadFixture = (fileName) => {
describe('Should convert Spring REST Docs cURL snippets to', () => {
it('an Insomnia collection', () => {
const expectedOutput = loadFixture('insomnia.json');
const actualOutput = JSON.parse(converter.convert(snippetsPath, 'insomnia'));
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'insomnia'
}));
expect(actualOutput.resources).toEqual(expectedOutput.resources);
});

it('a Postman collection', () => {
const expectedOutput = loadFixture('postman.json');
const actualOutput = JSON.parse(converter.convert(snippetsPath, 'postman'));
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'postman'
}));
expect(actualOutput).toEqual(expectedOutput);
});

it('an Insomnia collection with replacements', () => {
const expectedOutput = loadFixture('insomnia-with-replacements.json');
const actualOutput = JSON.parse(converter.convert(snippetsPath, 'insomnia', exampleReplacements));
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'insomnia',
replacements: exampleReplacements
}));
expect(actualOutput.resources).toEqual(expectedOutput.resources);
});

it('a Postman collection with replacements', () => {
const expectedOutput = loadFixture( 'postman-with-replacements.json');
const actualOutput = JSON.parse(converter.convert(snippetsPath, 'postman', exampleReplacements));
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'postman',
replacements: exampleReplacements
}));
expect(actualOutput).toEqual(expectedOutput);
});

it('an Insomnia collection with folders', () => {
const expectedOutput = loadFixture('insomnia-with-folders.json');
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'insomnia',
determineFolder: folderFunctions.secondLastFolder
}));
expect(actualOutput.resources).toEqual(expectedOutput.resources);
});

it('a Postman collection with folders', () => {
const expectedOutput = loadFixture('postman-with-folders.json');
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'postman',
determineFolder: folderFunctions.secondLastFolder
}));
expect(actualOutput).toEqual(expectedOutput);
});

it('an Insomnia collection with folders and replacements', () => {
const expectedOutput = loadFixture('insomnia-with-folders-and-replacements.json');
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'insomnia',
determineFolder: folderFunctions.secondLastFolder,
replacements: exampleReplacements
}));
expect(actualOutput.resources).toEqual(expectedOutput.resources);
});

it('a Postman collection with folders and replacements', () => {
const expectedOutput = loadFixture('postman-with-folders-and-replacements.json');
const actualOutput = JSON.parse(converter.convert({
folderToScan: snippetsPath,
exportFormat: 'postman',
determineFolder: folderFunctions.secondLastFolder,
replacements: exampleReplacements
}));
expect(actualOutput).toEqual(expectedOutput);
});
});
Loading

0 comments on commit e56d488

Please sign in to comment.