Skip to content

Commit

Permalink
adds openapi-format dep to filter operations (#28)
Browse files Browse the repository at this point in the history
* adds openapi-format dep to filter operations

* update changelog
  • Loading branch information
nicklloyd authored May 31, 2021
1 parent bb881aa commit a050a8d
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANEGLOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.1.0 - (2021-05-31)

### OpenApi-Format / CLI options

- Added CLI Option filterFile to pass path to filter options for ignoring requests in spec before passing to Postman conversion

## v0.0.9 - (2021-05-28)

### CLI options
Expand Down
122 changes: 118 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"newman": "^5.2.3",
"node-emoji": "^1.10.0",
"node-fetch": "^2.6.1",
"openapi-format": "^1.2.3",
"openapi-to-postmanv2": "git://github.com/thim81/openapi-to-postman.git#latest.2.7.0",
"ora": "^5.4.0",
"pluralize": "^8.0.0",
Expand Down
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PostmanService } from './application/PostmanService'
import {
cleanupTestSchemaDefs,
clearTmpDirectory,
execShellCommand,
getConfig,
injectEnvVariables,
injectPreRequest,
Expand Down Expand Up @@ -91,6 +92,10 @@ require('dotenv').config()
describe: 'Path to postman-testsuite.json',
type: 'string'
})
.option('filterFile', {
describe: 'Path to openapi-format-filter.json',
type: 'string'
})
.option('envFile', {
describe: 'Path to .env file to use for variable injection',
type: 'string'
Expand Down Expand Up @@ -134,6 +139,7 @@ require('dotenv').config()
? undefined
: options.testSuiteConfigFile || 'postman-testsuite.json'
const envFile = options.envFile || '.env'
const filterFile = options.filterFile

const { variableOverwrites, preRequestScripts, globalReplacements, orderOfOperations } =
await getConfig(portmanConfigFile)
Expand Down Expand Up @@ -185,12 +191,20 @@ require('dotenv').config()
}
}

const openApiSpec = oaLocal ? './tmp/converted/spec.yml' : await new DownloadService().get(oaUrl)
let openApiSpec = oaLocal ? './tmp/converted/spec.yml' : await new DownloadService().get(oaUrl)
const specExists = await fs.pathExists(openApiSpec)
if (!specExists) {
throw new Error(`Download failed. ${openApiSpec} doesn't exist. `)
}

if (filterFile && (await fs.pathExists(filterFile))) {
const openApiSpecPath = './tmp/converted/filtered.yml'

await execShellCommand(
`npx openapi-format ${openApiSpec} -o ${openApiSpecPath} --yaml --filterFile ${filterFile}`
)
openApiSpec = openApiSpecPath
}
// --- openapi-to-postman - Transform OpenApi to Postman collection, with optional test suite generation
const tmpCollectionFile = `${process.cwd()}/tmp/working/tmpCollection.json`

Expand Down
13 changes: 13 additions & 0 deletions src/lib/execShellCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { exec } from 'child_process'
export const execShellCommand = (cmd: string): Promise<boolean> => {
return new Promise((resolve, _reject) => {
exec(cmd, { maxBuffer: 1024 * 500 }, (error, stdout, stderr) => {
if (error) {
console.warn(error)
} else if (stderr) {
console.log(stderr)
}
resolve(stdout ? true : false)
})
})
}
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './clearTmpDirectory'
export * from './execShellCommand'
export * from './getConfig'
export * from './runNewmanWith'
export * from './transforms/cleanupTestSchemaDefs'
Expand Down
1 change: 1 addition & 0 deletions src/types/PortmanOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface PortmanOptions {
portmanConfigFile?: string
postmanConfigFile?: string
testSuiteConfigFile?: string
filterFile?: string
envFile?: string
cliOptionsFile?: string
}

0 comments on commit a050a8d

Please sign in to comment.