hyperjump-io / json-schema

JSON Schema Validation, Annotation, and Bundling. Supports Draft 04, 06, 07, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1
https://json-schema.hyperjump.io/
MIT License
216 stars 22 forks source link

Validation for invalid OpenAPI 3.1.0 document returns an empty `errors` array #26

Closed dchicchon closed 1 year ago

dchicchon commented 1 year ago

Issue is as stated above, I passed in my OpenAPI 3.1.0 document to the validate method that was shown in the main README.md.

import { validate } from "@hyperjump/json-schema/openapi-3-1";
import fs from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));

const openapi = JSON.parse(fs.readFileSync(join(__dirname, "openapi3.1.json")));

try {
  // Validate an OpenAPI document
  const output = await validate(
    "https://spec.openapis.org/oas/3.1/schema-base",
    openapi
  );
  console.log(output);
} catch (err) {
  console.log(err);
}

Below is the output

{
  keyword: 'https://json-schema.org/evaluation/validate',
  absoluteKeywordLocation: 'https://spec.openapis.org/oas/3.1/schema-base/2022-10-07#',
  instanceLocation: '#',
  valid: false,
  errors: []
}

Expected output: If my OpenAPI document is not valid, I expected to receive errors that specified what issues I need to resolve.

Actual output: An invalid OpenAPI 3.1.0 document returns an empty errors array

jdesrosiers commented 1 year ago

The default output format is FLAG which doesn't include error details. In order to get more details you need to use one of the other output formats. https://github.com/hyperjump-io/json-schema#output-formats-experimental

import { BASIC } from "@hyperjump/json-schema/experimental";

const output = await validate("https://spec.openapis.org/oas/3.1/schema-base", openapi, BASIC);