Skip to content

compileAsync causes infinite chain of requests when metaschema is specified #1821

Open
@yesennes

Description

What version of Ajv are you using? 8.8
Does the issue happen if you use the latest version? yes

Ajv options object

{
  loadSchema: async (url) => {
    if (url.startsWith("http://")) {
      url = "https://" + url.substring(7)
    }
    const ans = await (await fetch(url)).json()
    console.log(ans)
    return ans;
  }
}

JSON Schema

{ "$ref": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#" }

Sample data

The schema never finishes compiling

Your code

const ajv = new Ajv(options)

async function compile() {
  await ajv.compileAsync(schema)
  console.log("Done compiling")
}

Here's a sandbox replicating the problem: https://runkit.com/yesennes/619429f6e904c40008bcc644

Validation result, data AFTER validation, error messages

The schema never finish compiling.

What results did you expect?
The schema to finish compiling.
Are you going to resolve the issue?
I can take a stab at it.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions