Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-mock-server

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-mock-server - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

openapi.yaml

50

index.js

@@ -1,28 +0,46 @@

const Port = require("get-port")
const App = require("express")()
const OpenApiMock = require("openapi-mockk")
const Opts = require('mri');
const Port = require('get-port')
const App = require('express')()
const OpenApiMock = require('openapi-mockk')
const args = require('args')
const debug = require('debug')('openapi-mock-server')
const chalk = require('chalk')
const args = Opts(process.argv.slice(2))
args.option(['a', 'api'], 'Path to OpenAPI specification file. JSON or YAML.')
args.example('openapi-mock-server --api=petstore.yaml', 'To run a server serving examples from specification, simply point to a file')
const opts = args.parse(process.argv)
if (args.api) {
App.all("*", (req, res, next) => {
const content = req.headers["content-type"] || "application/json"
debug(`Reading OpenAPI in ${opts.api}`)
const mock = OpenApiMock(opts.api)
mock.openapi.then(api => {
debug(`OpenAPI specification for ${api.info.title} loaded successfuly`)
})
if (opts.api) {
App.all('*', (req, res, next) => {
const content = req.headers['content-type'] || 'application/json'
const path = req.path
const operation = req.method.toLowerCase()
const mock = OpenApiMock(args.api).responses({
debug(`HTTP ${req.method} ${req.path}; content-type=${content}`)
mock.responses({
path,
operation,
response: '200',
content,
content
}).then(mock => {
res.send(mock[path][operation].responses)
if (path in mock) {
const response = mock[path][operation].responses
debug(`200: ${response}`)
res.send(response)
} else {
debug(`404: path not found`)
res.sendStatus(404)
}
})
})
Port({port: 3000}).then(port => {
App.listen(port, () => console.log(`OpenApiMock server listening on port ${port}`))
});
App.listen(port, () => console.log(chalk`{cyan openapi-mock-server: listening @ {underline http://localhost:${port}}}`))
})
} else {
console.log("OpenAPI file required, --api=api.yaml. Supports json and yaml.")
}
args.showHelp()
}
{
"name": "openapi-mock-server",
"version": "0.1.1",
"version": "0.1.2",
"description": "Create mock server based on Open API 3.0 specification file ",
"main": "index.js",
"repository": "unjello/openapi-mock-server",
"repository": "unjello/openapi-mock-server",
"scripts": {

@@ -19,5 +19,7 @@ "test": "standard"

"dependencies": {
"args": "^3.0.8",
"chalk": "^2.3.2",
"debug": "^3.1.0",
"express": "^4.16.3",
"get-port": "^3.2.0",
"mri": "^1.1.0",
"openapi-mockk": "^0.1.0"

@@ -24,0 +26,0 @@ },

@@ -9,2 +9,4 @@ [![npm version][npm_badge]][npm_link] [![Build Status][travis_badge]][travis_link] [![downloads][npm_dl_badge]][npm_dl_link] [![js-standard-style][js_standard_badge]][js_standard_link]

Requires Node 8 or newer.
```bash

@@ -11,0 +13,0 @@ $ pnpm i -g openapi-mock-server

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc