Skip to content

Commit 5fb8e24

Browse files
committed
chore: add test case
1 parent 50c6ee3 commit 5fb8e24

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

lib/__tests__/pointer.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, it } from "vitest";
2+
import { $RefParser } from "..";
3+
import path from "path";
4+
5+
describe("pointer", () => {
6+
it("inlines internal JSON Pointer refs under #/paths/ for OpenAPI bundling", async () => {
7+
const refParser = new $RefParser();
8+
const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "openapi-paths-ref.json");
9+
const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any;
10+
11+
// The GET endpoint should have its schema defined inline
12+
const getSchema = schema.paths["/foo"].get.responses["200"].content["application/json"].schema;
13+
expect(getSchema.$ref).toBeUndefined();
14+
expect(getSchema.type).toBe("object");
15+
expect(getSchema.properties.bar.type).toBe("string");
16+
17+
// The POST endpoint should have its schema inlined (copied) instead of a $ref
18+
const postSchema = schema.paths["/foo"].post.responses["200"].content["application/json"].schema;
19+
expect(postSchema.$ref).toBeUndefined();
20+
expect(postSchema.type).toBe("object");
21+
expect(postSchema.properties.bar.type).toBe("string");
22+
23+
// Both schemas should be identical objects
24+
expect(postSchema).toEqual(getSchema);
25+
});
26+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "Sample API",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/foo": {
9+
"get": {
10+
"summary": "Get foo",
11+
"responses": {
12+
"200": {
13+
"description": "OK",
14+
"content": {
15+
"application/json": {
16+
"schema": {
17+
"type": "object",
18+
"properties": {
19+
"bar": {
20+
"type": "string"
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"post": {
30+
"summary": "Create foo",
31+
"responses": {
32+
"200": {
33+
"description": "OK",
34+
"content": {
35+
"application/json": {
36+
"schema": {
37+
"$ref": "#/paths/~1foo/get/responses/200/content/application~1json/schema"
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)