diff --git a/test/specs/bundle/bundle.spec.ts b/test/specs/bundle/bundle.spec.ts new file mode 100644 index 00000000..ba478f0a --- /dev/null +++ b/test/specs/bundle/bundle.spec.ts @@ -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); + }); +}); diff --git a/test/specs/bundle/bundled.ts b/test/specs/bundle/bundled.ts new file mode 100644 index 00000000..90b6727f --- /dev/null +++ b/test/specs/bundle/bundled.ts @@ -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", + }, + }, + }, + ], + }, + }, + }, + ], + }, + }, + }, + }, + ], +}; diff --git a/test/specs/bundle/schemaA.json b/test/specs/bundle/schemaA.json new file mode 100644 index 00000000..877c8661 --- /dev/null +++ b/test/specs/bundle/schemaA.json @@ -0,0 +1,6 @@ +{ + "$id": "schemaA/1.0", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "$ref": "schemaB.json#/definitions/ReservationPurchaseOrderForBookResponse" +} diff --git a/test/specs/bundle/schemaB.json b/test/specs/bundle/schemaB.json new file mode 100644 index 00000000..d26ee9f6 --- /dev/null +++ b/test/specs/bundle/schemaB.json @@ -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" + } + } + } + ] + } + } +} diff --git a/test/specs/bundle/schemaC.json b/test/specs/bundle/schemaC.json new file mode 100644 index 00000000..3fcee17f --- /dev/null +++ b/test/specs/bundle/schemaC.json @@ -0,0 +1,235 @@ +{ + "$id": "schemaC/1.0", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "AbstractResponseReservationActionMetaData": { + "allOf": [ + { + "$ref": "#/definitions/AbstractReservationActionMetaData" + }, + { + "type": "object", + "required": [ + "test" + ], + "properties": { + "test": { + "type": "string" + } + } + } + ], + "properties": { + "type": { + "type": "string" + } + } + }, + "AbstractReservationActionMetaData": { + "type": "object", + "required": [ + "supplierPriceElements" + ], + "properties": { + "supplierPriceElements": { + "$ref": "#/definitions/SupplierPriceElement" + }, + "type": { + "type": "string" + } + } + }, + "SupplierPriceElement": { + "allOf": [ + { + "$ref": "#/definitions/AbstractSupplierPriceElement" + }, + { + "type": "object", + "required": [ + "purchaseRate" + ], + "properties": { + "purchaseRate": { + "$ref": "#/definitions/InDetailParent" + }, + "fee": { + "$ref": "#/definitions/AllFees" + } + } + } + ] + }, + "AllFees": { + "type": "object", + "properties": { + "modificationFee": { + "$ref": "#/definitions/MonetaryAmount" + }, + "cancellationFee": { + "$ref": "#/definitions/MonetaryAmount" + } + } + }, + "MonetaryAmount": { + "type": "object", + "required": [ + "amount", + "currency" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Amount" + }, + "currency": { + "$ref": "#/definitions/Currency" + } + } + }, + "Amount": { + "type": "number", + "format": "float" + }, + "Currency": { + "type": "string", + "minLength": 1 + }, + "InDetailParent": { + "allOf": [ + { + "$ref": "#/definitions/MonetaryAmount" + }, + { + "type": "object", + "properties": { + "inDetail": { + "$ref": "#/definitions/InDetailChild" + } + } + } + ] + }, + "InDetailChild": { + "type": "object", + "properties": { + "perDate": { + "type": "array", + "items": { + "$ref": "#/definitions/InDetailPerDate" + } + }, + "perPax": { + "type": "array", + "items": { + "$ref": "#/definitions/InDetailPerPax" + } + } + } + }, + "InDetailPerDate": { + "type": "object", + "properties": { + "date": { + "type": "string", + "format": "date" + }, + "amount": { + "$ref": "#/definitions/Amount" + }, + "detailedPriceInformation": { + "type": "array", + "items": { + "$ref": "#/definitions/DetailedPriceInformation" + } + } + } + }, + "DetailedPriceInformation": { + "type": "object", + "properties": { + "amount": { + "$ref": "#/definitions/Amount" + }, + "paxId": { + "type": "string" + }, + "inDetail": { + "$ref": "#/definitions/InDetailPriceInformation" + } + } + }, + "InDetailPriceInformation": { + "type": "object", + "properties": { + "rate": { + "$ref": "#/definitions/Amount" + }, + "board": { + "$ref": "#/definitions/Amount" + }, + "taxes": { + "type": "array", + "items": { + "$ref": "#/definitions/InDetailField" + } + }, + "fees": { + "type": "array", + "items": { + "$ref": "#/definitions/InDetailField" + } + }, + "supplements": { + "type": "array", + "items": { + "$ref": "#/definitions/InDetailField" + } + }, + "salesOfferIds": { + "type": "array", + "items": { + "$ref": "#/definitions/InDetailField" + } + } + } + }, + "InDetailField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "amount": { + "$ref": "#/definitions/Amount" + } + } + }, + "InDetailPerPax": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "amount": { + "$ref": "#/definitions/Amount" + }, + "salesOfferIds": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "AbstractSupplierPriceElement": { + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string" + } + } + } + } +} diff --git a/test/specs/working-directory/nested/working-dir.spec.ts b/test/specs/working-directory/nested/working-dir.spec.ts index b51d203a..e696e785 100644 --- a/test/specs/working-directory/nested/working-dir.spec.ts +++ b/test/specs/working-directory/nested/working-dir.spec.ts @@ -23,7 +23,7 @@ describe("Working directory", () => { } catch (err) { expect(err).to.be.an.instanceOf(JSONParserError); // @ts-expect-error TS(2571): Object is of type 'unknown'. - expect(err.message).to.contain("Error opening file"); + expect(err.message).to.contain("Error"); } }); });