@dhaneshpurohit/mockstar 0.1.3 → 0.2.2
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
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## [0.2.2](https://github.com/dhanesh/mockstar/compare/v0.2.1...v0.2.2) (2026-07-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **pkg:** add repository/homepage/bugs so provenance validation passes ([c07a6e0](https://github.com/dhanesh/mockstar/commit/c07a6e0c8682c170ce75b5eb84fa0cfb3f1ae32f))
|
|
7
|
+
|
|
8
|
+
## [0.2.1](https://github.com/dhanesh/mockstar/compare/v0.2.0...v0.2.1) (2026-07-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **ci:** sudo the global npm upgrade in publish-npm (EACCES on runner) ([3b96c45](https://github.com/dhanesh/mockstar/commit/3b96c45244ba1670df38af5f0ce637905bf3f450))
|
|
14
|
+
|
|
15
|
+
# [0.2.0](https://github.com/dhanesh/mockstar/compare/v0.1.3...v0.2.0) (2026-07-06)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **release:** publish via workflow_call (decouple from tag-push trigger) ([#23](https://github.com/dhanesh/mockstar/issues/23)) ([c8dda75](https://github.com/dhanesh/mockstar/commit/c8dda755ae3fbba1e90d51044471777de47ab72c))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* **openapi:** synthesise schema-derived response bodies on import ([768560f](https://github.com/dhanesh/mockstar/commit/768560f8c0673a59a47327371a32b1626b990fc4))
|
|
26
|
+
|
|
1
27
|
## [0.1.3](https://github.com/dhanesh/mockstar/compare/v0.1.2...v0.1.3) (2026-06-23)
|
|
2
28
|
|
|
3
29
|
|
package/dist/cli.js
CHANGED
|
@@ -13742,7 +13742,7 @@ function convertOpenApi(doc, opts = {}) {
|
|
|
13742
13742
|
if (!/^(get|post|put|patch|delete|head|options)$/i.test(method))
|
|
13743
13743
|
continue;
|
|
13744
13744
|
const operation = op;
|
|
13745
|
-
const { status, example, contentType } = pickExemplar(operation);
|
|
13745
|
+
const { status, example, contentType } = pickExemplar(operation, doc);
|
|
13746
13746
|
const entry = {
|
|
13747
13747
|
id: operation.operationId ?? `${method.toUpperCase()}-${safePath}`,
|
|
13748
13748
|
match: {
|
|
@@ -13777,7 +13777,7 @@ function findRefs(value, acc = []) {
|
|
|
13777
13777
|
}
|
|
13778
13778
|
return acc;
|
|
13779
13779
|
}
|
|
13780
|
-
function pickExemplar(op) {
|
|
13780
|
+
function pickExemplar(op, doc) {
|
|
13781
13781
|
const responses = op.responses ?? {};
|
|
13782
13782
|
const preferred = ["200", "201", "202", "204", "default"];
|
|
13783
13783
|
for (const code of preferred) {
|
|
@@ -13795,7 +13795,7 @@ function pickExemplar(op) {
|
|
|
13795
13795
|
const media = content[ct];
|
|
13796
13796
|
if (!media)
|
|
13797
13797
|
continue;
|
|
13798
|
-
const example = media.example ?? firstExample(media.examples);
|
|
13798
|
+
const example = media.example ?? firstExample(media.examples) ?? (media.schema !== undefined ? synthesizeFromSchema(media.schema, doc) : undefined);
|
|
13799
13799
|
return { status, example, contentType: ct };
|
|
13800
13800
|
}
|
|
13801
13801
|
}
|
|
@@ -13809,13 +13809,99 @@ function firstExample(examples) {
|
|
|
13809
13809
|
return v3.value;
|
|
13810
13810
|
return;
|
|
13811
13811
|
}
|
|
13812
|
+
function synthesizeFromSchema(schema2, doc, seen = new Set, depth = 0) {
|
|
13813
|
+
if (depth > 8 || schema2 === null || typeof schema2 !== "object")
|
|
13814
|
+
return null;
|
|
13815
|
+
const s2 = schema2;
|
|
13816
|
+
if (typeof s2.$ref === "string") {
|
|
13817
|
+
if (seen.has(s2.$ref))
|
|
13818
|
+
return null;
|
|
13819
|
+
const resolved = resolveRef(s2.$ref, doc);
|
|
13820
|
+
if (resolved === undefined)
|
|
13821
|
+
return null;
|
|
13822
|
+
return synthesizeFromSchema(resolved, doc, new Set(seen).add(s2.$ref), depth + 1);
|
|
13823
|
+
}
|
|
13824
|
+
if (s2.example !== undefined)
|
|
13825
|
+
return s2.example;
|
|
13826
|
+
if (s2.default !== undefined)
|
|
13827
|
+
return s2.default;
|
|
13828
|
+
if (Array.isArray(s2.enum) && s2.enum.length > 0)
|
|
13829
|
+
return s2.enum[0];
|
|
13830
|
+
if (Array.isArray(s2.allOf)) {
|
|
13831
|
+
const merged = {};
|
|
13832
|
+
for (const sub of s2.allOf) {
|
|
13833
|
+
const part = synthesizeFromSchema(sub, doc, seen, depth + 1);
|
|
13834
|
+
if (part && typeof part === "object" && !Array.isArray(part))
|
|
13835
|
+
Object.assign(merged, part);
|
|
13836
|
+
}
|
|
13837
|
+
return merged;
|
|
13838
|
+
}
|
|
13839
|
+
const oneOf = s2.oneOf ?? s2.anyOf;
|
|
13840
|
+
if (Array.isArray(oneOf) && oneOf.length > 0) {
|
|
13841
|
+
return synthesizeFromSchema(oneOf[0], doc, seen, depth + 1);
|
|
13842
|
+
}
|
|
13843
|
+
const type = Array.isArray(s2.type) ? s2.type[0] : s2.type;
|
|
13844
|
+
if (type === "object" || s2.properties) {
|
|
13845
|
+
const out = {};
|
|
13846
|
+
const props = s2.properties ?? {};
|
|
13847
|
+
for (const [key, propSchema] of Object.entries(props)) {
|
|
13848
|
+
out[key] = synthesizeFromSchema(propSchema, doc, seen, depth + 1);
|
|
13849
|
+
}
|
|
13850
|
+
return out;
|
|
13851
|
+
}
|
|
13852
|
+
if (type === "array") {
|
|
13853
|
+
const item = s2.items !== undefined ? synthesizeFromSchema(s2.items, doc, seen, depth + 1) : null;
|
|
13854
|
+
return item === null ? [] : [item];
|
|
13855
|
+
}
|
|
13856
|
+
if (type === "string")
|
|
13857
|
+
return placeholderForString(typeof s2.format === "string" ? s2.format : "");
|
|
13858
|
+
if (type === "integer" || type === "number")
|
|
13859
|
+
return 0;
|
|
13860
|
+
if (type === "boolean")
|
|
13861
|
+
return true;
|
|
13862
|
+
if (type === "null")
|
|
13863
|
+
return null;
|
|
13864
|
+
return null;
|
|
13865
|
+
}
|
|
13866
|
+
function placeholderForString(format) {
|
|
13867
|
+
switch (format) {
|
|
13868
|
+
case "date-time":
|
|
13869
|
+
return "1970-01-01T00:00:00Z";
|
|
13870
|
+
case "date":
|
|
13871
|
+
return "1970-01-01";
|
|
13872
|
+
case "uuid":
|
|
13873
|
+
return "00000000-0000-0000-0000-000000000000";
|
|
13874
|
+
case "email":
|
|
13875
|
+
return "user@example.com";
|
|
13876
|
+
case "uri":
|
|
13877
|
+
case "url":
|
|
13878
|
+
return "https://example.com";
|
|
13879
|
+
case "byte":
|
|
13880
|
+
case "binary":
|
|
13881
|
+
return "";
|
|
13882
|
+
default:
|
|
13883
|
+
return "string";
|
|
13884
|
+
}
|
|
13885
|
+
}
|
|
13886
|
+
function resolveRef(ref, doc) {
|
|
13887
|
+
if (!ref.startsWith("#/"))
|
|
13888
|
+
return;
|
|
13889
|
+
let node = doc;
|
|
13890
|
+
for (const raw2 of ref.slice(2).split("/")) {
|
|
13891
|
+
const key = raw2.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
13892
|
+
if (node === null || typeof node !== "object")
|
|
13893
|
+
return;
|
|
13894
|
+
node = node[key];
|
|
13895
|
+
}
|
|
13896
|
+
return node;
|
|
13897
|
+
}
|
|
13812
13898
|
function encodePathTemplate(openapiPath) {
|
|
13813
13899
|
const parts = openapiPath.split("/").map((seg) => {
|
|
13814
13900
|
if (seg === "")
|
|
13815
13901
|
return seg;
|
|
13816
|
-
const
|
|
13817
|
-
if (
|
|
13818
|
-
const name =
|
|
13902
|
+
const firstParam = seg.match(/\{([^}]+)\}/);
|
|
13903
|
+
if (firstParam?.[1]) {
|
|
13904
|
+
const name = firstParam[1].replace(/[^a-zA-Z0-9_]/g, "_");
|
|
13819
13905
|
return `:${name}`;
|
|
13820
13906
|
}
|
|
13821
13907
|
return encodeURIComponent(seg);
|
|
@@ -14828,7 +14914,7 @@ function proxyHelp() {
|
|
|
14828
14914
|
}
|
|
14829
14915
|
|
|
14830
14916
|
// src/version.ts
|
|
14831
|
-
var MOCKSTAR_VERSION = "0.
|
|
14917
|
+
var MOCKSTAR_VERSION = "0.2.2";
|
|
14832
14918
|
|
|
14833
14919
|
// src/cli.ts
|
|
14834
14920
|
function parseArgs(argv) {
|
|
@@ -45,6 +45,14 @@ export interface ConvertOptions {
|
|
|
45
45
|
* anything else is a security error — CVE-2026-39885 class).
|
|
46
46
|
*/
|
|
47
47
|
export declare function convertOpenApi(doc: unknown, opts?: ConvertOptions): Array<Record<string, unknown>>;
|
|
48
|
+
/**
|
|
49
|
+
* Best-effort synthesis of a representative body from a JSON Schema so imported mocks
|
|
50
|
+
* are shaped like the real API. Bounded (depth + a per-branch $ref-visited set) so
|
|
51
|
+
* self-referential schemas terminate. Emits literal placeholders; `mockstar enhance`
|
|
52
|
+
* upgrades them to Tier 2 tokens. Only in-document `#/…` $refs are followed (external
|
|
53
|
+
* refs are already rejected upstream — RT-8.3).
|
|
54
|
+
*/
|
|
55
|
+
export declare function synthesizeFromSchema(schema: unknown, doc: OpenApiDoc, seen?: ReadonlySet<string>, depth?: number): unknown;
|
|
48
56
|
/**
|
|
49
57
|
* OpenAPI uses `{name}` path params; we rewrite to `:name` for Hono-style
|
|
50
58
|
* matching. Path segments are URL-encoded to prevent traversal attacks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../../src/features/openapi/converter.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE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AO,YAAA;CAKnC;AAED,MAAM,WAAW,cAAc;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,GAAE,cAAmB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAiEtG;AAqDD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,UAAU,EACf,IAAI,GAAE,WAAW,CAAC,MAAM,CAAa,EACrC,KAAK,SAAI,GACR,OAAO,CAkDT;AAmCD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAmB9D"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MOCKSTAR_VERSION = "0.
|
|
1
|
+
export declare const MOCKSTAR_VERSION = "0.2.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhaneshpurohit/mockstar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Bun-based mock server with static + dynamic mocking, JSON config, named JS handlers, pass-through, multi-tenancy, and test-data utilities.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/dhanesh/mockstar.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/dhanesh/mockstar#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/dhanesh/mockstar/issues"
|
|
13
|
+
},
|
|
6
14
|
"type": "module",
|
|
7
15
|
"types": "./dist/index.d.ts",
|
|
8
16
|
"bin": {
|