Skip to content

Commit

Permalink
make random() work with in the OpenAPI document
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Sep 9, 2022
1 parent 612ebf9 commit 8e1586e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"fs-extra": "^10.1.0",
"js-yaml": "^4.1.0",
"json-schema-faker": "^0.5.0-rcv.44",
"json-schema-ref-parser": "^9.0.9",
"jsonwebtoken": "^8.5.1",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
Expand Down
5 changes: 4 additions & 1 deletion src/counterfact.js
@@ -1,6 +1,7 @@
import fs from "node:fs/promises";
import nodePath from "node:path";

import $RefParser from "json-schema-ref-parser";
import yaml from "js-yaml";

import { Registry } from "./registry.js";
Expand All @@ -10,7 +11,9 @@ import { ModuleLoader } from "./module-loader.js";

async function loadOpenApiDocument(source) {
try {
return yaml.load(await fs.readFile(source, "utf8"));
return $RefParser.dereference(
await yaml.load(await fs.readFile(source, "utf8"))
);
} catch {
return undefined;
}
Expand Down
10 changes: 7 additions & 3 deletions test/counterfact.test.js
Expand Up @@ -88,9 +88,13 @@ describe("integration test", () => {
content:
text/plain:
schema:
type: string
examples:
- "hello"
$ref: "#/components/schemas/Hello"
components:
schemas:
Hello:
type: string
examples:
- "hello"
`,

"paths/hello.mjs": `
Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Expand Up @@ -10,6 +10,16 @@
"@jridgewell/gen-mapping" "^0.1.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@apidevtools/json-schema-ref-parser@9.0.9":
version "9.0.9"
resolved "https://registry.yarnpkg.com/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-9.0.9.tgz#d720f9256e3609621280584f2b47ae165359268b"
integrity sha512-GBD2Le9w2+lVFoc4vswGI/TjkNIZSVp7+9xPf+X3uidBfWnAeUWmquteSyt0+VCrhNMWj/FTABISQrD3Z/YA+w==
dependencies:
"@jsdevtools/ono" "^7.1.3"
"@types/json-schema" "^7.0.6"
call-me-maybe "^1.0.1"
js-yaml "^4.1.0"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a"
Expand Down Expand Up @@ -945,6 +955,11 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@jsdevtools/ono@^7.1.3":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@jsdevtools/ono/-/ono-7.1.3.tgz#9df03bbd7c696a5c58885c34aa06da41c8543796"
integrity sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==

"@manypkg/find-root@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@manypkg/find-root/-/find-root-1.1.0.tgz#a62d8ed1cd7e7d4c11d9d52a8397460b5d4ad29f"
Expand Down Expand Up @@ -2093,7 +2108,7 @@
dependencies:
"@types/istanbul-lib-report" "*"

"@types/json-schema@^7.0.11", "@types/json-schema@^7.0.3", "@types/json-schema@^7.0.9":
"@types/json-schema@^7.0.11", "@types/json-schema@^7.0.3", "@types/json-schema@^7.0.6", "@types/json-schema@^7.0.9":
version "7.0.11"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
Expand Down Expand Up @@ -5848,6 +5863,13 @@ json-schema-ref-parser@^6.1.0:
js-yaml "^3.12.1"
ono "^4.0.11"

json-schema-ref-parser@^9.0.9:
version "9.0.9"
resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-9.0.9.tgz#66ea538e7450b12af342fa3d5b8458bc1e1e013f"
integrity sha512-qcP2lmGy+JUoQJ4DOQeLaZDqH9qSkeGCK3suKWxJXS82dg728Mn3j97azDMaOUmJAN4uCq91LdPx4K7E8F1a7Q==
dependencies:
"@apidevtools/json-schema-ref-parser" "9.0.9"

json-schema-traverse@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
Expand Down

0 comments on commit 8e1586e

Please sign in to comment.