Skip to content

Commit

Permalink
bundle spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Apr 21, 2024
1 parent 734a4be commit e4ecbc5
Show file tree
Hide file tree
Showing 6 changed files with 568 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/specs/bundle/bundle.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, it } from "vitest";
import { expect } from "vitest";
import $RefParser from "../../../lib/index.js";
import path from "../../utils/path";
import dereferencedSchema from "./bundled";
import Ajv from "ajv";
import addFormats from "ajv-formats";

describe("Bundles", () => {
it("should bundle correctly", async () => {
const parser = new $RefParser();
const schema = path.rel("test/specs/bundle/schemaA.json");
const bundled = await parser.bundle(schema);
const derefed = await parser.dereference(bundled);
const ajv = new Ajv();
addFormats(ajv);

const compiled = ajv.compile(derefed);
const compiledDerefed = ajv.compile(bundled);
expect(bundled).to.deep.equal(dereferencedSchema);
});
});
225 changes: 225 additions & 0 deletions test/specs/bundle/bundled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
export default {
$id: "schemaA/1.0",
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
allOf: [
{
type: "object",
required: ["eventId", "payload"],
properties: {
eventId: {
type: "string",
},
},
},
{
type: "object",
properties: {
payload: {
type: "array",
items: {
allOf: [
{
type: "object",
},
{
type: "object",
properties: {
reservationActionMetaData: {
allOf: [
{
allOf: [
{
type: "object",
required: ["supplierPriceElements"],
properties: {
supplierPriceElements: {
allOf: [
{
required: ["type"],
properties: {
type: {
type: "string",
},
},
},
{
type: "object",
required: ["purchaseRate"],
properties: {
purchaseRate: {
allOf: [
{
type: "object",
required: ["amount", "currency"],
properties: {
amount: {
type: "number",
format: "float",
},
currency: {
type: "string",
minLength: 1,
},
},
},
{
type: "object",
properties: {
inDetail: {
type: "object",
properties: {
perDate: {
type: "array",
items: {
type: "object",
properties: {
date: {
type: "string",
format: "date",
},
amount: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
},
detailedPriceInformation: {
type: "array",
items: {
type: "object",
properties: {
amount: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
},
paxId: {
type: "string",
},
inDetail: {
type: "object",
properties: {
rate: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
},
board: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
},
taxes: {
type: "array",
items: {
$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",
},
},
fees: {
type: "array",
items: {
type: "object",
properties: {
id: {
type: "string",
},
amount: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
},
},
},
},
supplements: {
type: "array",
items: {
$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",
},
},
salesOfferIds: {
type: "array",
items: {
$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",
},
},
},
},
},
},
},
},
},
},
perPax: {
type: "array",
items: {
type: "object",
properties: {
id: {
type: "string",
},
amount: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount",
},
salesOfferIds: {
type: "array",
items: {
type: "string",
},
},
},
},
},
},
},
},
},
],
},
fee: {
type: "object",
properties: {
modificationFee: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0",
},
cancellationFee: {
$ref: "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0",
},
},
},
},
},
],
},
type: {
type: "string",
},
},
},
{
type: "object",
required: ["test"],
properties: {
test: {
type: "string",
},
},
},
],
properties: {
type: {
type: "string",
},
},
},
{
type: "object",
required: ["test"],
properties: {
test: {
type: "string",
},
},
},
],
},
},
},
],
},
},
},
},
],
};
6 changes: 6 additions & 0 deletions test/specs/bundle/schemaA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$id": "schemaA/1.0",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"$ref": "schemaB.json#/definitions/ReservationPurchaseOrderForBookResponse"
}
79 changes: 79 additions & 0 deletions test/specs/bundle/schemaB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$id": "schemaB/1.0",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"AbstractPurchaseOrderResponse": {
"type": "object",
"required": [
"eventId",
"payload"
],
"properties": {
"eventId": {
"type": "string"
}
}
},
"AbstractReservationDomainAnnotation": {
"required": [
"type"
],
"properties": {
"type": {
"type": "string"
}
}
},
"ReservationPurchaseOrderForBookResponse": {
"allOf": [
{
"$ref": "#/definitions/AbstractPurchaseOrderResponse"
},
{
"type": "object",
"properties": {
"payload": {
"type": "array",
"items": {
"$ref": "#/definitions/BookResponseReservationAction"
}
}
}
}
]
},
"BookResponseReservationActionMetaData": {
"allOf": [
{
"$ref": "schemaC.json#/definitions/AbstractResponseReservationActionMetaData"
},
{
"type": "object",
"required": [
"test"
],
"properties": {
"test": {
"type": "string"
}
}
}
]
},
"BookResponseReservationAction": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"reservationActionMetaData": {
"$ref": "#/definitions/BookResponseReservationActionMetaData"
}
}
}
]
}
}
}
Loading

0 comments on commit e4ecbc5

Please sign in to comment.