Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions test/specs/asyncapi/canHandle.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";

const $RefParser = require("../../..");

const { expect } = require("chai");
const { readFileSync } = require("fs");
const { join } = require("path");
const AJV = require("ajv");

describe("can process ayncapi schema so that AJV does not choke", () => {

it("through dereferencing, ignoring circular references", async () => {
const [schema, doc] = buildFixtures();

const derefNoCircular = await $RefParser.dereference(
schema,
{ dereference: { circular: "ignore" }},
);

validate(derefNoCircular, doc);
});

it("through bundling", async () => {
const [schema, doc] = buildFixtures();

const bundled = await $RefParser.bundle(
schema,
);

validate(bundled, doc);
});

function validate (schema, doc) {
const ajv = new AJV({
allErrors: true,
schemaId: "id",
logger: false,
});

const validateFn = ajv.compile(schema);
const isValid = validateFn(doc);

expect(isValid).to.be.true;
expect(validateFn.errors).to.be.null;
}

function buildFixtures () {
const docPath = join(__dirname, "streetlights.json");
const doc = JSON.parse(readFileSync(docPath, "utf8"));

const schemaPath = join(__dirname, "schema.aas2.json");
const schema = JSON.parse(readFileSync(schemaPath, "utf8"));

return [schema, doc];
}
});
Loading