@scalar/mock-server 0.2.73 → 0.2.75
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/CHANGELOG.md +22 -0
- package/README.md +107 -10
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @scalar/mock-server
|
|
2
2
|
|
|
3
|
+
## 0.2.75
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a40999d]
|
|
8
|
+
- Updated dependencies [b89da58]
|
|
9
|
+
- Updated dependencies [3300d5b]
|
|
10
|
+
- @scalar/oas-utils@0.2.71
|
|
11
|
+
- @scalar/openapi-parser@0.8.9
|
|
12
|
+
- @scalar/openapi-types@0.1.5
|
|
13
|
+
|
|
14
|
+
## 0.2.74
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [c3e76d9]
|
|
19
|
+
- Updated dependencies [757fade]
|
|
20
|
+
- Updated dependencies [a607115]
|
|
21
|
+
- @scalar/oas-utils@0.2.70
|
|
22
|
+
- @scalar/openapi-parser@0.8.9
|
|
23
|
+
- @scalar/openapi-types@0.1.5
|
|
24
|
+
|
|
3
25
|
## 0.2.73
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -5,21 +5,23 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@scalar/mock-server)
|
|
6
6
|
[](https://discord.gg/scalar)
|
|
7
7
|
|
|
8
|
-
A powerful Node.js server that generates
|
|
8
|
+
A powerful Node.js mock server that automatically generates realistic API responses from your OpenAPI/Swagger documents. It creates fully-functional endpoints with mock data, handles authentication, and respects content types - making it perfect for frontend development, API prototyping, and integration testing.
|
|
9
9
|
|
|
10
10
|

|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
14
|
+
- Perfect for frontend development and testing
|
|
15
|
+
- Creates endpoints automatically from OpenAPI documents
|
|
16
|
+
- Generates realistic mock data based on your schemas
|
|
17
|
+
- Handles authentication and responds with defined HTTP headers
|
|
18
|
+
- Supports Swagger 2.0 and OpenAPI 3.x documents
|
|
19
|
+
- Customizable response handling
|
|
19
20
|
|
|
20
21
|
## Quickstart
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
The easiest way to get started is through [our Scalar CLI](https://github.com/scalar/scalar/tree/main/packages/cli).
|
|
24
|
+
You can have a mock server up and running in seconds:
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
27
|
npx @scalar/cli mock openapi.json --watch
|
|
@@ -27,7 +29,7 @@ npx @scalar/cli mock openapi.json --watch
|
|
|
27
29
|
|
|
28
30
|
## Installation
|
|
29
31
|
|
|
30
|
-
For
|
|
32
|
+
For advanced use cases, you can integrate the mock server directly into your Node.js application for full control:
|
|
31
33
|
|
|
32
34
|
```bash
|
|
33
35
|
npm install @scalar/mock-server
|
|
@@ -39,9 +41,9 @@ npm install @scalar/mock-server
|
|
|
39
41
|
import { serve } from '@hono/node-server'
|
|
40
42
|
import { createMockServer } from '@scalar/mock-server'
|
|
41
43
|
|
|
42
|
-
// Your OpenAPI
|
|
44
|
+
// Your OpenAPI document
|
|
43
45
|
const specification = {
|
|
44
|
-
openapi: '3.1.
|
|
46
|
+
openapi: '3.1.1',
|
|
45
47
|
info: {
|
|
46
48
|
title: 'Hello World',
|
|
47
49
|
version: '1.0.0',
|
|
@@ -69,6 +71,7 @@ const specification = {
|
|
|
69
71
|
// Create the mocked routes
|
|
70
72
|
const app = await createMockServer({
|
|
71
73
|
specification,
|
|
74
|
+
// Custom logging
|
|
72
75
|
onRequest({ context, operation }) {
|
|
73
76
|
console.log(context.req.method, context.req.path)
|
|
74
77
|
},
|
|
@@ -86,6 +89,100 @@ serve(
|
|
|
86
89
|
)
|
|
87
90
|
```
|
|
88
91
|
|
|
92
|
+
### Authentication
|
|
93
|
+
|
|
94
|
+
You can define security schemes in your OpenAPI document and the mock server will validate the authentication:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { serve } from '@hono/node-server'
|
|
98
|
+
import { createMockServer } from '@scalar/mock-server'
|
|
99
|
+
|
|
100
|
+
// Your OpenAPI document
|
|
101
|
+
const specification = {
|
|
102
|
+
openapi: '3.1.1',
|
|
103
|
+
info: {
|
|
104
|
+
title: 'Hello World',
|
|
105
|
+
version: '1.0.0',
|
|
106
|
+
},
|
|
107
|
+
paths: {
|
|
108
|
+
'/secret': {
|
|
109
|
+
get: {
|
|
110
|
+
security: [
|
|
111
|
+
{
|
|
112
|
+
bearerAuth: [],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
apiKey: [],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
responses: {
|
|
119
|
+
'200': {
|
|
120
|
+
description: 'OK',
|
|
121
|
+
content: {
|
|
122
|
+
'application/json': {
|
|
123
|
+
example: {
|
|
124
|
+
foo: 'bar',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
'401': {
|
|
130
|
+
description: 'Unauthorized',
|
|
131
|
+
content: {
|
|
132
|
+
'application/json': {
|
|
133
|
+
example: {
|
|
134
|
+
error: 'Unauthorized',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
components: {
|
|
144
|
+
securitySchemes: {
|
|
145
|
+
bearerAuth: {
|
|
146
|
+
type: 'http',
|
|
147
|
+
scheme: 'bearer',
|
|
148
|
+
bearerFormat: 'JWT',
|
|
149
|
+
},
|
|
150
|
+
apiKey: {
|
|
151
|
+
type: 'apiKey',
|
|
152
|
+
in: 'header',
|
|
153
|
+
name: 'X-API-Key',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Create the mocked routes
|
|
160
|
+
const app = await createMockServer({
|
|
161
|
+
specification,
|
|
162
|
+
// Custom logging
|
|
163
|
+
onRequest({ context, operation }) {
|
|
164
|
+
console.log(context.req.method, context.req.path)
|
|
165
|
+
},
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
// Start the server
|
|
169
|
+
serve(
|
|
170
|
+
{
|
|
171
|
+
fetch: app.fetch,
|
|
172
|
+
port: 3000,
|
|
173
|
+
},
|
|
174
|
+
(info) => {
|
|
175
|
+
console.log(`Listening on http://localhost:${info.port}`)
|
|
176
|
+
},
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### OpenAPI endpoints
|
|
181
|
+
|
|
182
|
+
The given OpenAPI document is automatically exposed:
|
|
183
|
+
|
|
184
|
+
- `/openapi.json` and `/openapi.yaml`
|
|
185
|
+
|
|
89
186
|
## Community
|
|
90
187
|
|
|
91
188
|
We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"swagger",
|
|
17
17
|
"cli"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.75",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "^4.6.5",
|
|
40
40
|
"object-to-xml": "^2.0.0",
|
|
41
|
-
"@scalar/
|
|
42
|
-
"@scalar/openapi-
|
|
43
|
-
"@scalar/
|
|
41
|
+
"@scalar/oas-utils": "0.2.71",
|
|
42
|
+
"@scalar/openapi-parser": "0.8.9",
|
|
43
|
+
"@scalar/openapi-types": "0.1.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@hono/node-server": "^1.11.0",
|
|
47
47
|
"@types/node": "^20.14.10",
|
|
48
|
-
"@scalar/build-tooling": "0.1.
|
|
49
|
-
"@scalar/hono-api-reference": "0.5.
|
|
48
|
+
"@scalar/build-tooling": "0.1.12",
|
|
49
|
+
"@scalar/hono-api-reference": "0.5.159"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "scalar-build-rollup",
|