Skip to content

Commit e4ecbc5

Browse files
committed
bundle spec
1 parent 734a4be commit e4ecbc5

File tree

6 files changed

+568
-1
lines changed

6 files changed

+568
-1
lines changed

test/specs/bundle/bundle.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, it } from "vitest";
2+
import { expect } from "vitest";
3+
import $RefParser from "../../../lib/index.js";
4+
import path from "../../utils/path";
5+
import dereferencedSchema from "./bundled";
6+
import Ajv from "ajv";
7+
import addFormats from "ajv-formats";
8+
9+
describe("Bundles", () => {
10+
it("should bundle correctly", async () => {
11+
const parser = new $RefParser();
12+
const schema = path.rel("test/specs/bundle/schemaA.json");
13+
const bundled = await parser.bundle(schema);
14+
const derefed = await parser.dereference(bundled);
15+
const ajv = new Ajv();
16+
addFormats(ajv);
17+
18+
const compiled = ajv.compile(derefed);
19+
const compiledDerefed = ajv.compile(bundled);
20+
expect(bundled).to.deep.equal(dereferencedSchema);
21+
});
22+
});

test/specs/bundle/bundled.ts

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
export default {
2+
$id: "schemaA/1.0",
3+
$schema: "http://json-schema.org/draft-07/schema#",
4+
type: "object",
5+
allOf: [
6+
{
7+
type: "object",
8+
required: ["eventId", "payload"],
9+
properties: {
10+
eventId: {
11+
type: "string",
12+
},
13+
},
14+
},
15+
{
16+
type: "object",
17+
properties: {
18+
payload: {
19+
type: "array",
20+
items: {
21+
allOf: [
22+
{
23+
type: "object",
24+
},
25+
{
26+
type: "object",
27+
properties: {
28+
reservationActionMetaData: {
29+
allOf: [
30+
{
31+
allOf: [
32+
{
33+
type: "object",
34+
required: ["supplierPriceElements"],
35+
properties: {
36+
supplierPriceElements: {
37+
allOf: [
38+
{
39+
required: ["type"],
40+
properties: {
41+
type: {
42+
type: "string",
43+
},
44+
},
45+
},
46+
{
47+
type: "object",
48+
required: ["purchaseRate"],
49+
properties: {
50+
purchaseRate: {
51+
allOf: [
52+
{
53+
type: "object",
54+
required: ["amount", "currency"],
55+
properties: {
56+
amount: {
57+
type: "number",
58+
format: "float",
59+
},
60+
currency: {
61+
type: "string",
62+
minLength: 1,
63+
},
64+
},
65+
},
66+
{
67+
type: "object",
68+
properties: {
69+
inDetail: {
70+
type: "object",
71+
properties: {
72+
perDate: {
73+
type: "array",
74+
items: {
75+
type: "object",
76+
properties: {
77+
date: {
78+
type: "string",
79+
format: "date",
80+
},
81+
amount: {
82+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
83+
},
84+
detailedPriceInformation: {
85+
type: "array",
86+
items: {
87+
type: "object",
88+
properties: {
89+
amount: {
90+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
91+
},
92+
paxId: {
93+
type: "string",
94+
},
95+
inDetail: {
96+
type: "object",
97+
properties: {
98+
rate: {
99+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
100+
},
101+
board: {
102+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
103+
},
104+
taxes: {
105+
type: "array",
106+
items: {
107+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/1/properties/inDetail/properties/perDate/items/properties/detailedPriceInformation/items/properties/inDetail/properties/fees/items",
108+
},
109+
},
110+
fees: {
111+
type: "array",
112+
items: {
113+
type: "object",
114+
properties: {
115+
id: {
116+
type: "string",
117+
},
118+
amount: {
119+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
120+
},
121+
},
122+
},
123+
},
124+
supplements: {
125+
type: "array",
126+
items: {
127+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/1/properties/inDetail/properties/perDate/items/properties/detailedPriceInformation/items/properties/inDetail/properties/fees/items",
128+
},
129+
},
130+
salesOfferIds: {
131+
type: "array",
132+
items: {
133+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/1/properties/inDetail/properties/perDate/items/properties/detailedPriceInformation/items/properties/inDetail/properties/fees/items",
134+
},
135+
},
136+
},
137+
},
138+
},
139+
},
140+
},
141+
},
142+
},
143+
},
144+
perPax: {
145+
type: "array",
146+
items: {
147+
type: "object",
148+
properties: {
149+
id: {
150+
type: "string",
151+
},
152+
amount: {
153+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
154+
},
155+
salesOfferIds: {
156+
type: "array",
157+
items: {
158+
type: "string",
159+
},
160+
},
161+
},
162+
},
163+
},
164+
},
165+
},
166+
},
167+
},
168+
],
169+
},
170+
fee: {
171+
type: "object",
172+
properties: {
173+
modificationFee: {
174+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0",
175+
},
176+
cancellationFee: {
177+
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0",
178+
},
179+
},
180+
},
181+
},
182+
},
183+
],
184+
},
185+
type: {
186+
type: "string",
187+
},
188+
},
189+
},
190+
{
191+
type: "object",
192+
required: ["test"],
193+
properties: {
194+
test: {
195+
type: "string",
196+
},
197+
},
198+
},
199+
],
200+
properties: {
201+
type: {
202+
type: "string",
203+
},
204+
},
205+
},
206+
{
207+
type: "object",
208+
required: ["test"],
209+
properties: {
210+
test: {
211+
type: "string",
212+
},
213+
},
214+
},
215+
],
216+
},
217+
},
218+
},
219+
],
220+
},
221+
},
222+
},
223+
},
224+
],
225+
};

test/specs/bundle/schemaA.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$id": "schemaA/1.0",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"type": "object",
5+
"$ref": "schemaB.json#/definitions/ReservationPurchaseOrderForBookResponse"
6+
}

test/specs/bundle/schemaB.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"$id": "schemaB/1.0",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"AbstractPurchaseOrderResponse": {
6+
"type": "object",
7+
"required": [
8+
"eventId",
9+
"payload"
10+
],
11+
"properties": {
12+
"eventId": {
13+
"type": "string"
14+
}
15+
}
16+
},
17+
"AbstractReservationDomainAnnotation": {
18+
"required": [
19+
"type"
20+
],
21+
"properties": {
22+
"type": {
23+
"type": "string"
24+
}
25+
}
26+
},
27+
"ReservationPurchaseOrderForBookResponse": {
28+
"allOf": [
29+
{
30+
"$ref": "#/definitions/AbstractPurchaseOrderResponse"
31+
},
32+
{
33+
"type": "object",
34+
"properties": {
35+
"payload": {
36+
"type": "array",
37+
"items": {
38+
"$ref": "#/definitions/BookResponseReservationAction"
39+
}
40+
}
41+
}
42+
}
43+
]
44+
},
45+
"BookResponseReservationActionMetaData": {
46+
"allOf": [
47+
{
48+
"$ref": "schemaC.json#/definitions/AbstractResponseReservationActionMetaData"
49+
},
50+
{
51+
"type": "object",
52+
"required": [
53+
"test"
54+
],
55+
"properties": {
56+
"test": {
57+
"type": "string"
58+
}
59+
}
60+
}
61+
]
62+
},
63+
"BookResponseReservationAction": {
64+
"allOf": [
65+
{
66+
"type": "object"
67+
},
68+
{
69+
"type": "object",
70+
"properties": {
71+
"reservationActionMetaData": {
72+
"$ref": "#/definitions/BookResponseReservationActionMetaData"
73+
}
74+
}
75+
}
76+
]
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)