go-mokapi 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/bin/mokapi.js +32 -0
- package/dist/mokapi-darwin-arm64/mokapi +0 -0
- package/dist/mokapi-linux-amd64/mokapi +0 -0
- package/dist/mokapi-windows-amd64/mokapi.exe +0 -0
- package/index.d.ts +7 -0
- package/package.json +32 -0
- package/types/faker.d.ts +22 -0
- package/types/globals.d.ts +10 -0
- package/types/http.d.ts +21 -0
- package/types/kafka.d.ts +18 -0
- package/types/mokapi.d.ts +74 -0
- package/types/mustache.d.ts +3 -0
- package/types/yaml.d.ts +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/marle3003/mokapi/raw/v0.5.0/logo.svg" alt="Mokapi" title="Mokapi" width="400" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Mokapi is a tool that allows developers to create and test API designs before actually building them. It works by emulating API responses based on the designs that have been created, which allows developers to test different configurations and edge cases without having to rely on a fully built API.
|
|
8
|
+
|
|
9
|
+
With Mokapi, developers can make changes to their API configurations on the fly, which can help to speed up the testing process and reduce dependencies. This means that developers can quickly and easily test different scenarios, such as delayed or failed responses, without having to rely on a fully functional API.
|
|
10
|
+
|
|
11
|
+
By using Mokapi, developers can reduce the time and effort required for development and testing, since they can test different scenarios and configurations in a more efficient way. This can help to improve the quality of the API and reduce the risk of bugs or errors in production.
|
|
12
|
+
|
|
13
|
+
## Web UI
|
|
14
|
+
|
|
15
|
+
<img src="https://github.com/marle3003/mokapi/raw/v0.5.0/webui.png" alt="Mokapi Web UI" title="Mokapi Web UI" />
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
npx mokapi --Providers.File.Directory=./mokapi
|
|
21
|
+
```
|
package/bin/mokapi.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
let spawn = require('child_process').spawn;
|
|
3
|
+
let path = require('path');
|
|
4
|
+
|
|
5
|
+
const ARCH_MAPPING = {
|
|
6
|
+
"ia32": "386",
|
|
7
|
+
"x64": "amd64",
|
|
8
|
+
"arm": "arm"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Mapping between Node's `process.platform` to Golang's
|
|
12
|
+
const PLATFORM_MAPPING = {
|
|
13
|
+
"darwin": "darwin",
|
|
14
|
+
"linux": "linux",
|
|
15
|
+
"win32": "windows",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let exe = `../dist/mokapi-${PLATFORM_MAPPING[process.platform]}-${ARCH_MAPPING[process.arch]}/mokapi`
|
|
19
|
+
if (process.platform === 'win32') {
|
|
20
|
+
exe += '.exe'
|
|
21
|
+
}
|
|
22
|
+
const exePath = path.resolve(__dirname, exe)
|
|
23
|
+
const mokapi = spawn(exePath, process.argv.slice(2), {cwd: process.cwd()})
|
|
24
|
+
|
|
25
|
+
mokapi.stdout.on('data', function(data) {
|
|
26
|
+
console.log(data.toString())
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
mokapi.stderr.on('data', function(data) {
|
|
30
|
+
console.log(data.toString())
|
|
31
|
+
})
|
|
32
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference path="types/globals.d.ts" />
|
|
2
|
+
/// <reference path="types/faker.d.ts" />
|
|
3
|
+
/// <reference path="types/http.d.ts" />
|
|
4
|
+
/// <reference path="types/kafka.d.ts" />
|
|
5
|
+
/// <reference path="types/mokapi.d.ts" />
|
|
6
|
+
/// <reference path="types/mustache.d.ts" />
|
|
7
|
+
/// <reference path="types/yaml.d.ts" />
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "go-mokapi",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Create and test API designs before actually building them.",
|
|
5
|
+
"homepage": "https://github.com/marle3003/mokapi/tree/v0.5.0/docs",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/marle3003/mokapi.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"mokapi": "bin/mokapi.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"mokapi": "mokapi"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mock",
|
|
18
|
+
"api",
|
|
19
|
+
"kafka",
|
|
20
|
+
"rest",
|
|
21
|
+
"http"
|
|
22
|
+
],
|
|
23
|
+
"author": "Marcel Lehmann",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"bin",
|
|
28
|
+
"dist",
|
|
29
|
+
"types",
|
|
30
|
+
"index.d.ts"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/types/faker.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module 'faker' {
|
|
2
|
+
function fake(schema: Schema): any
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
declare interface Schema {
|
|
6
|
+
type: "object" | "array" | "number" | "integer" | "string" | "boolean"
|
|
7
|
+
format?: string
|
|
8
|
+
pattern?: string
|
|
9
|
+
items?: Schema
|
|
10
|
+
required?: string[]
|
|
11
|
+
enum?: any[]
|
|
12
|
+
minimum?: number
|
|
13
|
+
maximum?: number
|
|
14
|
+
exclusiveMinimum?: boolean
|
|
15
|
+
exclusiveMaximum?: boolean
|
|
16
|
+
anyOf?: Schema[]
|
|
17
|
+
allOf?: Schema[]
|
|
18
|
+
oneOf?: Schema[]
|
|
19
|
+
minItems?: number
|
|
20
|
+
maxItems?: number
|
|
21
|
+
shuffleItems?: boolean
|
|
22
|
+
}
|
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare module 'mustache' {
|
|
2
|
+
function get(url: string, args: Args): Response
|
|
3
|
+
function post(url: string, body: string, args: Args): Response
|
|
4
|
+
function put(url: string, body: string, args: Args): Response
|
|
5
|
+
function head(url: string, args: Args): Response
|
|
6
|
+
function patch(url: string, args: Args): Response
|
|
7
|
+
function del(url: string, body: string, args: Args): Response
|
|
8
|
+
function options(url: string, body: string, args: Args): Response
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type Header = { [name: string]: string };
|
|
12
|
+
|
|
13
|
+
declare interface Args {
|
|
14
|
+
header?: Header;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare interface Response {
|
|
18
|
+
body: string
|
|
19
|
+
statusCode: number
|
|
20
|
+
headers: Header
|
|
21
|
+
}
|
package/types/kafka.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare module 'kafka' {
|
|
2
|
+
function produce(args: ProduceArgs): ProduceResult
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
declare interface ProduceArgs {
|
|
6
|
+
cluster?: string
|
|
7
|
+
topic?: string
|
|
8
|
+
partition?: number
|
|
9
|
+
key?: any
|
|
10
|
+
value?: any
|
|
11
|
+
headers?: {[key: string]: any; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare interface ProduceResult {
|
|
15
|
+
key: any
|
|
16
|
+
value: any
|
|
17
|
+
error?: string
|
|
18
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
declare module 'mokapi' {
|
|
2
|
+
/** Listener for http events. */
|
|
3
|
+
function on(event: 'http', f: HttpEventHandler): void
|
|
4
|
+
/** Schedules a new periodic job with interval.
|
|
5
|
+
* Interval string is a possibly signed sequence of
|
|
6
|
+
* decimal numbers, each with optional fraction and a unit suffix,
|
|
7
|
+
* such as "300ms", "-1.5h" or "2h45m".
|
|
8
|
+
* Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
|
|
9
|
+
*/
|
|
10
|
+
function every(interval: string, f: function(): void): void
|
|
11
|
+
/** Returns the environment variable named by the key. */
|
|
12
|
+
function env(key: string): string
|
|
13
|
+
|
|
14
|
+
/** Opens a file and reading all its content. */
|
|
15
|
+
function open(path: string): string
|
|
16
|
+
|
|
17
|
+
/** Returns a textual representation of the date. See the documentation to see
|
|
18
|
+
* how to represent the layout format.
|
|
19
|
+
* Default layout is RFC3339.
|
|
20
|
+
* Default timestamp is current UTC */
|
|
21
|
+
function date(args?: DateArgs): string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type HttpEventHandler = (request: HttpRequest, response: HttpResponse) => boolean
|
|
25
|
+
|
|
26
|
+
declare interface HttpRequest {
|
|
27
|
+
/** Request method. */
|
|
28
|
+
method: string
|
|
29
|
+
/** Request url. */
|
|
30
|
+
url: Url
|
|
31
|
+
/** Request body. */
|
|
32
|
+
body: any
|
|
33
|
+
/** Path parameters. */
|
|
34
|
+
path: { [key: string]: any; }
|
|
35
|
+
/** Query parameters. */
|
|
36
|
+
query: { [key: string]: any; }
|
|
37
|
+
/** Header parameters. */
|
|
38
|
+
header: { [key: string]: any; }
|
|
39
|
+
/** Cookie parameters. */
|
|
40
|
+
cookie: { [key: string]: any; }
|
|
41
|
+
/** Path defined in OpenAPI. */
|
|
42
|
+
key: string
|
|
43
|
+
/** OperationId definied in OpenAPI. */
|
|
44
|
+
operationId: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare interface HttpResponse {
|
|
48
|
+
/** Response headers. */
|
|
49
|
+
headers: { [key: string]: string; }
|
|
50
|
+
/** HTTP status code. */
|
|
51
|
+
statusCode: number
|
|
52
|
+
/** Response body. It has a higher precedence than data. */
|
|
53
|
+
body: string
|
|
54
|
+
/** Response data. It has a lower precedence than body. */
|
|
55
|
+
data: any
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare interface Url {
|
|
59
|
+
/** URL scheme. */
|
|
60
|
+
scheme: string
|
|
61
|
+
/** URL host. */
|
|
62
|
+
host: string
|
|
63
|
+
/** URL path. */
|
|
64
|
+
path: string
|
|
65
|
+
/** URL query string. */
|
|
66
|
+
query: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare interface DateArgs {
|
|
70
|
+
layout?: string
|
|
71
|
+
timestamp?: number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const RFC3339 = "RFC3339"
|
package/types/yaml.d.ts
ADDED