Closed webketje closed 1 year ago
There was misconfiguration for OpenAPI 3.0. I just released v1.5.1 to fix the problem. When you update, the error should go away.
However, the next error you'll get is an InvalidSchemaError because you aren't quite using the API correctly. There are two things you can do and what you're doing is somewhere in the middle.
If you're just trying to validate the OpenAPI document, you want something like this,
const openapi = load(readFileSync("doc/openapi_spec.yaml", "utf8"))
const output = await validate("https://spec.openapis.org/oas/3.0/schema", openapi)
console.log(output.valid)
If you want a validator function for a schema in the OpenAPI document, you need to point to the schema you want.
const validateFoo = await validate(pathToFileURL("doc/openapi_spec.yaml") + "#/components/schemas/foo")
const output = validateFoo(42)
console.log(output.valid);
The second example will also validate your whole OpenAPI document and throw an InvalidSchemaError if there's a problem. So, you don't need to validate the OpenAPI document separately if you are using this feature.
Thanks, what I wanted to do was case 2: create a validator for a response in #/components/responses/ResponseType
.
I missed the part of the code snippet in the README where it shows the JSON schema ref being used within the validate
method (but I saw it now). I'll reinstall & close the issue after validating :)
I did as instructed adding a YAML mediaTypePlugin:
But it always fails with
Also, manually navigating to all the default dialects are Github 404's..
When the defaultDialect is hardcoded to
undefined
as in the README example, it always throws. No idea why it even tries querying https://json-schema.org/validation