@scalar/mock-server 0.5.39 → 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/CHANGELOG.md +28 -0
- package/dist/createMockServer.d.ts +1 -1
- package/dist/createMockServer.d.ts.map +1 -1
- package/dist/createMockServer.js +3 -3
- package/dist/createMockServer.js.map +2 -2
- package/dist/routes/respondWithOpenApiDocument.d.ts +12 -2
- package/dist/routes/respondWithOpenApiDocument.d.ts.map +1 -1
- package/dist/routes/respondWithOpenApiDocument.js +1 -1
- package/dist/routes/respondWithOpenApiDocument.js.map +2 -2
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @scalar/mock-server
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#7121](https://github.com/scalar/scalar/pull/7121) [`9661e81`](https://github.com/scalar/scalar/commit/9661e81907d1a9b74ba30f270f2d6c8e49834cd5) Thanks [@marcalexiei](https://github.com/marcalexiei)! - feat(oas-utils): make `dereference` synchronous
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#7193](https://github.com/scalar/scalar/pull/7193) [`c277671`](https://github.com/scalar/scalar/commit/c277671e8357adccf1065f90c2194d9a0bd18452) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix(mock-server): restore `async` on `createMockServer`
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`2239843`](https://github.com/scalar/scalar/commit/2239843150ed16d1ca35b0b1f8e90cd3e35be7ce), [`6ec8c29`](https://github.com/scalar/scalar/commit/6ec8c299d912111b029e8058979d00968b70691a), [`9661e81`](https://github.com/scalar/scalar/commit/9661e81907d1a9b74ba30f270f2d6c8e49834cd5), [`134ff5f`](https://github.com/scalar/scalar/commit/134ff5f32aa6842696bf146c7e0817b1662905eb), [`81b0a7a`](https://github.com/scalar/scalar/commit/81b0a7a4245619f03161eae639dc5834b77432b6), [`c84b7c5`](https://github.com/scalar/scalar/commit/c84b7c5e81be83dacbdfcbf9cb1e558dfdc3faa1), [`0319b8a`](https://github.com/scalar/scalar/commit/0319b8a8652a50667776b2e9fd27c3e15b34f765), [`134ff5f`](https://github.com/scalar/scalar/commit/134ff5f32aa6842696bf146c7e0817b1662905eb), [`eba18d0`](https://github.com/scalar/scalar/commit/eba18d06267a163a8f91396a66f817100ee59461), [`a821986`](https://github.com/scalar/scalar/commit/a821986332141e69d26885b2d2b32eb0c49f416c), [`e23229d`](https://github.com/scalar/scalar/commit/e23229dfbd9613b5047b28b57901f2fc5a6e33e6)]:
|
|
14
|
+
- @scalar/openapi-parser@0.23.0
|
|
15
|
+
- @scalar/openapi-types@0.5.1
|
|
16
|
+
- @scalar/helpers@0.0.13
|
|
17
|
+
- @scalar/oas-utils@0.6.0
|
|
18
|
+
|
|
19
|
+
## 0.5.40
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [3f6d0b9]
|
|
24
|
+
- Updated dependencies [f8efecd]
|
|
25
|
+
- Updated dependencies [f69e7cc]
|
|
26
|
+
- @scalar/helpers@0.0.12
|
|
27
|
+
- @scalar/oas-utils@0.5.2
|
|
28
|
+
- @scalar/openapi-types@0.5.0
|
|
29
|
+
- @scalar/openapi-parser@0.22.3
|
|
30
|
+
|
|
3
31
|
## 0.5.39
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -3,5 +3,5 @@ import type { MockServerOptions } from './types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a mock server instance
|
|
5
5
|
*/
|
|
6
|
-
export declare function createMockServer(options: MockServerOptions): Promise<Hono
|
|
6
|
+
export declare function createMockServer(options: MockServerOptions): Promise<Hono>;
|
|
7
7
|
//# sourceMappingURL=createMockServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMockServer.d.ts","sourceRoot":"","sources":["../src/createMockServer.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"createMockServer.d.ts","sourceRoot":"","sources":["../src/createMockServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAW5D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgD1E"}
|
package/dist/createMockServer.js
CHANGED
|
@@ -9,9 +9,9 @@ import { logAuthenticationInstructions } from "./utils/logAuthenticationInstruct
|
|
|
9
9
|
import { setupAuthenticationRoutes } from "./utils/setupAuthenticationRoutes.js";
|
|
10
10
|
import { mockAnyResponse } from "./routes/mockAnyResponse.js";
|
|
11
11
|
import { respondWithOpenApiDocument } from "./routes/respondWithOpenApiDocument.js";
|
|
12
|
-
|
|
12
|
+
function createMockServer(options) {
|
|
13
13
|
const app = new Hono();
|
|
14
|
-
const { schema } =
|
|
14
|
+
const { schema } = dereference(options?.specification ?? {});
|
|
15
15
|
app.use(cors());
|
|
16
16
|
setupAuthenticationRoutes(app, schema);
|
|
17
17
|
logAuthenticationInstructions(
|
|
@@ -31,7 +31,7 @@ async function createMockServer(options) {
|
|
|
31
31
|
});
|
|
32
32
|
app.get("/openapi.json", (c) => respondWithOpenApiDocument(c, options?.specification, "json"));
|
|
33
33
|
app.get("/openapi.yaml", (c) => respondWithOpenApiDocument(c, options?.specification, "yaml"));
|
|
34
|
-
return app;
|
|
34
|
+
return Promise.resolve(app);
|
|
35
35
|
}
|
|
36
36
|
export {
|
|
37
37
|
createMockServer
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createMockServer.ts"],
|
|
4
|
-
"sourcesContent": ["import { dereference } from '@scalar/openapi-parser'\nimport type { OpenAPI, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB;AAE5B,
|
|
4
|
+
"sourcesContent": ["import { dereference } from '@scalar/openapi-parser'\nimport type { OpenAPI, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport { Hono } from 'hono'\nimport { cors } from 'hono/cors'\n\nimport type { HttpMethod, MockServerOptions } from '@/types'\nimport { getOperations } from '@/utils/getOperations'\nimport { handleAuthentication } from '@/utils/handleAuthentication'\nimport { honoRouteFromPath } from '@/utils/honoRouteFromPath'\nimport { isAuthenticationRequired } from '@/utils/isAuthenticationRequired'\nimport { logAuthenticationInstructions } from '@/utils/logAuthenticationInstructions'\nimport { setupAuthenticationRoutes } from '@/utils/setupAuthenticationRoutes'\n\nimport { mockAnyResponse } from './routes/mockAnyResponse'\nimport { respondWithOpenApiDocument } from './routes/respondWithOpenApiDocument'\n\n/**\n * Create a mock server instance\n */\nexport function createMockServer(options: MockServerOptions): Promise<Hono> {\n const app = new Hono()\n\n /** Dereferenced OpenAPI document */\n const { schema } = dereference(options?.specification ?? {})\n\n // CORS headers\n app.use(cors())\n\n /** Authentication methods defined in the OpenAPI document */\n setupAuthenticationRoutes(app, schema)\n\n logAuthenticationInstructions(\n schema?.components?.securitySchemes || ({} as Record<string, OpenAPIV3_1.SecuritySchemeObject>),\n )\n\n /** Paths specified in the OpenAPI document */\n const paths = schema?.paths ?? {}\n\n Object.keys(paths).forEach((path) => {\n const methods = Object.keys(getOperations(paths[path])) as HttpMethod[]\n\n /** Keys for all operations of a specified path */\n methods.forEach((method) => {\n const route = honoRouteFromPath(path)\n const operation = schema?.paths?.[path]?.[method] as OpenAPI.Operation\n\n // Check if authentication is required for this operation\n if (isAuthenticationRequired(operation.security)) {\n app[method](route, handleAuthentication(schema, operation))\n }\n\n // Actual route\n app[method](route, (c) => mockAnyResponse(c, operation, options))\n })\n })\n\n // OpenAPI JSON file\n app.get('/openapi.json', (c) => respondWithOpenApiDocument(c, options?.specification, 'json'))\n\n // OpenAPI YAML file\n app.get('/openapi.yaml', (c) => respondWithOpenApiDocument(c, options?.specification, 'yaml'))\n\n /**\n * No async code, but returning a Promise to allow future async logic to be implemented\n * @see https://github.com/scalar/scalar/pull/7174#discussion_r2470046281\n */\n return Promise.resolve(app)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAE5B,SAAS,YAAY;AACrB,SAAS,YAAY;AAGrB,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,SAAS,qCAAqC;AAC9C,SAAS,iCAAiC;AAE1C,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAKpC,SAAS,iBAAiB,SAA2C;AAC1E,QAAM,MAAM,IAAI,KAAK;AAGrB,QAAM,EAAE,OAAO,IAAI,YAAY,SAAS,iBAAiB,CAAC,CAAC;AAG3D,MAAI,IAAI,KAAK,CAAC;AAGd,4BAA0B,KAAK,MAAM;AAErC;AAAA,IACE,QAAQ,YAAY,mBAAoB,CAAC;AAAA,EAC3C;AAGA,QAAM,QAAQ,QAAQ,SAAS,CAAC;AAEhC,SAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,SAAS;AACnC,UAAM,UAAU,OAAO,KAAK,cAAc,MAAM,IAAI,CAAC,CAAC;AAGtD,YAAQ,QAAQ,CAAC,WAAW;AAC1B,YAAM,QAAQ,kBAAkB,IAAI;AACpC,YAAM,YAAY,QAAQ,QAAQ,IAAI,IAAI,MAAM;AAGhD,UAAI,yBAAyB,UAAU,QAAQ,GAAG;AAChD,YAAI,MAAM,EAAE,OAAO,qBAAqB,QAAQ,SAAS,CAAC;AAAA,MAC5D;AAGA,UAAI,MAAM,EAAE,OAAO,CAAC,MAAM,gBAAgB,GAAG,WAAW,OAAO,CAAC;AAAA,IAClE,CAAC;AAAA,EACH,CAAC;AAGD,MAAI,IAAI,iBAAiB,CAAC,MAAM,2BAA2B,GAAG,SAAS,eAAe,MAAM,CAAC;AAG7F,MAAI,IAAI,iBAAiB,CAAC,MAAM,2BAA2B,GAAG,SAAS,eAAe,MAAM,CAAC;AAM7F,SAAO,QAAQ,QAAQ,GAAG;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,11 +2,21 @@ import type { Context } from 'hono';
|
|
|
2
2
|
/**
|
|
3
3
|
* OpenAPI endpoints
|
|
4
4
|
*/
|
|
5
|
-
export declare function respondWithOpenApiDocument(c: Context, input?: string | Record<string, any>, format?: 'json' | 'yaml'):
|
|
5
|
+
export declare function respondWithOpenApiDocument(c: Context, input?: string | Record<string, any>, format?: 'json' | 'yaml'): (Response & import("hono").TypedResponse<"Not found", 404, "text">) | (Response & import("hono").TypedResponse<{
|
|
6
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
7
|
+
} | {
|
|
8
|
+
dir: string;
|
|
9
|
+
isEntrypoint: boolean;
|
|
10
|
+
references: string[];
|
|
11
|
+
filename: string;
|
|
12
|
+
specification: {
|
|
13
|
+
[x: string]: any;
|
|
14
|
+
};
|
|
15
|
+
}[], import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<string, 200, "text">) | (Response & import("hono").TypedResponse<{
|
|
6
16
|
error: string;
|
|
7
17
|
message: string;
|
|
8
18
|
}, 500, "json">) | (Response & import("hono").TypedResponse<{
|
|
9
19
|
error: string;
|
|
10
20
|
message: string;
|
|
11
|
-
}, 400, "json">)
|
|
21
|
+
}, 400, "json">);
|
|
12
22
|
//# sourceMappingURL=respondWithOpenApiDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"respondWithOpenApiDocument.d.ts","sourceRoot":"","sources":["../../src/routes/respondWithOpenApiDocument.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"respondWithOpenApiDocument.d.ts","sourceRoot":"","sources":["../../src/routes/respondWithOpenApiDocument.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,CAAC,EAAE,OAAO,EACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpC,MAAM,GAAE,MAAM,GAAG,MAAe;;;;;;;;;;;;;;;;iBAwCjC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/routes/respondWithOpenApiDocument.ts"],
|
|
4
|
-
"sourcesContent": ["import { normalize, toYaml } from '@scalar/openapi-parser'\nimport type { Context } from 'hono'\n\n/**\n * OpenAPI endpoints\n */\nexport
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW,cAAc;
|
|
4
|
+
"sourcesContent": ["import { normalize, toYaml } from '@scalar/openapi-parser'\nimport type { Context } from 'hono'\n\n/**\n * OpenAPI endpoints\n */\nexport function respondWithOpenApiDocument(\n c: Context,\n input?: string | Record<string, any>,\n format: 'json' | 'yaml' = 'json',\n) {\n if (!input) {\n return c.text('Not found', 404)\n }\n\n try {\n const document = normalize(input)\n\n // JSON\n if (format === 'json') {\n return c.json(document)\n }\n\n // YAML\n try {\n const yamlDocument = toYaml(normalize(document))\n\n c.header('Content-Type', 'text/yaml')\n return c.text(yamlDocument, 200, {\n 'Content-Type': 'application/yaml; charset=UTF-8',\n })\n } catch (error) {\n return c.json(\n {\n error: 'Failed to convert document to YAML',\n message: error instanceof Error ? error.message : 'Unknown error occurred',\n },\n 500,\n )\n }\n } catch (error) {\n return c.json(\n {\n error: 'Failed to parse OpenAPI document',\n message: error instanceof Error ? error.message : 'Unknown error occurred',\n },\n 400,\n )\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,cAAc;AAM3B,SAAS,2BACd,GACA,OACA,SAA0B,QAC1B;AACA,MAAI,CAAC,OAAO;AACV,WAAO,EAAE,KAAK,aAAa,GAAG;AAAA,EAChC;AAEA,MAAI;AACF,UAAM,WAAW,UAAU,KAAK;AAGhC,QAAI,WAAW,QAAQ;AACrB,aAAO,EAAE,KAAK,QAAQ;AAAA,IACxB;AAGA,QAAI;AACF,YAAM,eAAe,OAAO,UAAU,QAAQ,CAAC;AAE/C,QAAE,OAAO,gBAAgB,WAAW;AACpC,aAAO,EAAE,KAAK,cAAc,KAAK;AAAA,QAC/B,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH,SAAS,OAAO;AACd,aAAO,EAAE;AAAA,QACP;AAAA,UACE,OAAO;AAAA,UACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,QACpD;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,WAAO,EAAE;AAAA,MACP;AAAA,QACE,OAAO;AAAA,QACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MACpD;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"swagger",
|
|
17
17
|
"cli"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.6.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
],
|
|
37
37
|
"module": "dist/index.js",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"hono": "4.
|
|
40
|
-
"@scalar/helpers": "0.0.
|
|
41
|
-
"@scalar/openapi-parser": "0.
|
|
42
|
-
"@scalar/
|
|
43
|
-
"@scalar/
|
|
39
|
+
"hono": "4.10.2",
|
|
40
|
+
"@scalar/helpers": "0.0.13",
|
|
41
|
+
"@scalar/openapi-parser": "0.23.0",
|
|
42
|
+
"@scalar/openapi-types": "0.5.1",
|
|
43
|
+
"@scalar/oas-utils": "0.6.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@hono/node-server": "
|
|
46
|
+
"@hono/node-server": "1.19.5",
|
|
47
47
|
"@types/node": "^22.9.0",
|
|
48
|
-
"vite": "7.1.
|
|
49
|
-
"@scalar/
|
|
50
|
-
"@scalar/
|
|
48
|
+
"vite": "7.1.11",
|
|
49
|
+
"@scalar/build-tooling": "0.2.8",
|
|
50
|
+
"@scalar/hono-api-reference": "0.9.23"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "scalar-build-esbuild",
|