Skip to content

Schema fails validation #77

@martinellison

Description

@martinellison

I get the following error from trying to validate the schema datasworn.schema.json:

Error: unknown field `$id`, expected one of `metadata`, `definitions`, `nullable`, `ref`, `type`, `enum`, `elements`, `properties`, `optionalProperties`, `additionalProperties`, `values`, `discriminator`, `mapping`

What version of the JTD are you using?

edit: I have now tried out the official JTD validator jtd-validate` on your schema and it is giving me the same error.

My validation code is as follows, for information:

use color_eyre::{Result, eyre::WrapErr, eyre::eyre};
use jtd::{Schema, SerdeSchema, ValidationErrorIndicator};
use serde_json::json;
use std::{fs::File, io::BufReader};

fn main() -> Result<()> {
    let base_path = home::home_dir()
        .ok_or(eyre!("must be valid home path"))?
        .join("extgit")
        .join("datasworn"); // path to where I checked out the repo
    let data_path = base_path
        .join("datasworn")
        .join("datasworn.schema.json");
    let file =
        File::open(data_path.clone()).wrap_err_with(|| format!("cannot read: {data_path:?}"))?;
    let reader: BufReader<File> = BufReader::new(file);
    let data: serde_json::Value =
        serde_json::from_reader(reader).map_err(|err| eyre!("bad read: {err:?}"))?;
    let schema_value: SerdeSchema = serde_json::from_value(data)?;
    let schema = Schema::from_serde_schema(schema_value)?;
    schema.validate()?;

    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions