All Projects → jormaechea → open-api-mocker

jormaechea / open-api-mocker

Licence: MIT license
A mock server based in OpenAPI Specification

Programming Languages

javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to open-api-mocker

Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+5844.83%)
Mutual labels:  mock, mock-server, openapi, mocking
Prism
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
Stars: ✭ 2,484 (+4182.76%)
Mutual labels:  mock-server, openapi, mocking
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+822.41%)
Mutual labels:  mock, mock-server, mocking
Mockaco
🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
Stars: ✭ 213 (+267.24%)
Mutual labels:  mock, mock-server, mocking
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (-34.48%)
Mutual labels:  mock, mock-server, mocking
Openapi Sampler
🔠 Tool for generation samples based on OpenAPI(fka Swagger) payload/response schema
Stars: ✭ 83 (+43.1%)
Mutual labels:  mock, schema, openapi
Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+8229.31%)
Mutual labels:  mock, mock-server, mocking
Openapi Mock
OpenAPI mock server with random data generation
Stars: ✭ 202 (+248.28%)
Mutual labels:  mock, mock-server, openapi
main
Mocks Server monorepo
Stars: ✭ 109 (+87.93%)
Mutual labels:  mock, mock-server, openapi
json-fake-server
Simple way to create http server (node js) https://www.npmjs.com/package/test-fake-server
Stars: ✭ 15 (-74.14%)
Mutual labels:  mock, mock-server
ruby-dns-mock
DNS mock server written on 💎 Ruby. Mimic any DNS records for your test environment with fake DNS server.
Stars: ✭ 50 (-13.79%)
Mutual labels:  mock, mock-server
mocat
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.
Stars: ✭ 27 (-53.45%)
Mutual labels:  mock, mock-server
springmock
alternative spring mocking infrastructure
Stars: ✭ 22 (-62.07%)
Mutual labels:  mock, mocking
platypus
Very simple and customizable mock/echo server
Stars: ✭ 15 (-74.14%)
Mutual labels:  mock, mock-server
mockingbird
🐦 Decorator Powered TypeScript Library for Creating Mocks
Stars: ✭ 70 (+20.69%)
Mutual labels:  mock, mocking
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (+27.59%)
Mutual labels:  mock-server, mocking
arrest
Swagger REST framework for Node.js, with support for MongoDB and JSON-Schema
Stars: ✭ 17 (-70.69%)
Mutual labels:  schema, openapi
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+58.62%)
Mutual labels:  schema, openapi
aem-stubs
Tool for providing sample data for AEM applications in a simple and flexible way. Stubbing server on AEM, no separate needed.
Stars: ✭ 40 (-31.03%)
Mutual labels:  mock, mocking
dexopener
An Android library that provides the ability to mock your final classes on Android devices.
Stars: ✭ 112 (+93.1%)
Mutual labels:  mock, mocking

OpenAPI Mocker

Build Status npm version Maintainability Test Coverage Docker compatible

An API mocker based in the OpenAPI 3.0 specification.

Installation and usage

Using npm

npm i -g open-api-mocker

open-api-mocker -s my-schema.json -w

open-api-mocker --help # To prompt every available setting.

Using docker

docker run -v "$PWD/myschema.json:/app/schema.json" -p "5000:5000" jormaechea/open-api-mocker

Or to run an specific version

docker run -v "$PWD/myschema.json:/app/schema.json" -p "5000:5000" jormaechea/open-api-mocker:X.Y.Z`

You can set any parameter when running inside a docker container

docker run -v "$PWD/myschema.json:/app/schema.json" -p "3000:3000" jormaechea/open-api-mocker:X.Y.Z -s /app/schema.json -p 3000`

Capabilities

  • Read yaml and json OpenAPI v3 schemas.
  • Port binding selection
  • Request parameters validation
  • Request body validation
  • Response body and headers generation based on examples or schemas
  • Response selection using request header: Prefer: statusCode=XXX or Prefer: example=name
  • Request and response logging
  • Servers basepath support
  • Support x-faker and x-count extension methods to customise generated responses
  • API Authentication

Customizing Generated Responses

The OpenAPI specification allows custom properties to be added to an API definition in the form of x-*. OpenAPI Mocker supports the use of two custom extensions to allow data to be randomised which should allow for more realistic looking data when developing a UI against a mock API for instance.

x-faker

The x-faker extension is valid for use on properties that have a primitive type (e.g. string/integer, etc.) and can be used within an API definition to use one or more methods from the excellent faker library for generating random data.

Given the following API definition:

openapi: '3.0.2'
info:
  title: Cats
  version: '1.0'
servers:
  - url: https://api.cats.test/v1
paths:
  /cat:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  firstName:
                    type: string
                    x-faker: name.firstName
                  lastName:
                    type: string
                    x-faker: name.lastName
                  fullName:
                    type: string
                    x-faker: '{{name.firstName}} {{name.lastName}}'
                  age:
                    type: string
                    x-faker: 'random.number({ "min": 1, "max": 20 })'

A JSON response similar to the following would be produced:

{
    "firstName": "Ted",
    "lastName": "Kozey",
    "fullName": "Herbert Lowe",
    "age": 12
}

The x-faker extension accepts values in 3 forms:

  1. fakerNamespace.method. e.g. random.uuid
  2. fakerNamespace.method({ "methodArgs": "in", "json": "format" }). e.g. random.number({ "max": 100 })
  3. A mustache template string making use of the 2 forms above. e.g. My name is {{name.firstName}} {{name.lastName}}

NOTE: To avoid new fake data from being generated on every call, up to 10 responses per endpoint are cached based on the incoming query string, request body and headers.

x-count

The x-count extension has effect only when used on an array type property. If encountered, OpenAPI Mocker will return an array with the given number of elements instead of the default of an array with a single item.

For example, the following API definition:

openapi: '3.0.2'
info:
  title: Cats
  version: '1.0'
servers:
  - url: https://api.cats.test/v1
paths:
  /cat:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                x-count: 5
                items:
                  type: string

Will produce the following response:

[
    "string",
    "string",
    "string",
    "string",
    "string"
]

Advanced usage

See the advanced usage docs to extend or build your own app upon OpenAPI Mocker.

Tests

Simply run npm t

Contributing

Issues and PRs are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].