Open jonsinfinity1 opened 2 months ago
I get a TypeError saying it expected an integer but got boolean.
That's exactly what's supposed to happen with the example. The line triggering it is commented "Will throw a ValidationException" (TypeError is a ValidationException).
My bad, I'm getting the same error when trying to load my schema from file and figured the error was happening at the same place. When I use my schema file it doesn't get past the loadSchema(). The schema validates using your validator here: https://tryjsonschematypes.appspot.com/#validate as well as generating data using the schema. I thought maybe it had something to do with the way the string was created but I've taken the string directly from debug to your validator and it works fine.
One thing to note is that it sets the meta-schema to draft-04 even though the schema is using draft-07. I believe the schema I'm using still conforms to draft-04 so not sure it'a a factor.
Any thoughts would be appreciated.
package org.example;
//import net.jimblackler.jsongenerator.Configuration;
//import net.jimblackler.jsongenerator.DefaultConfig;
//import net.jimblackler.jsongenerator.Generator;
import net.jimblackler.jsonschemafriend.Schema;
import net.jimblackler.jsonschemafriend.SchemaStore;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Random;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
try {
// Load the JSON schema from a file or string
String schemaFilePath = "/../../../../src/schemas/address.json";
String schemaContent = new String(Files.readAllBytes(Paths.get(schemaFilePath)));
// Parse the schema using the SchemaLoader
SchemaStore schemaStore = new SchemaStore();
Schema schema = schemaStore.loadSchema(schemaContent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here's the schema I'm testing with:
{
"$id": "https://example.com/address.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Address",
"type": "object",
"properties": {
"streetAddress": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"postalCode": {
"type": "string",
"pattern": "^\\d{5}$"
}
},
"required": ["streetAddress", "city", "state", "postalCode"]
}
And here's the stacktrace:
net.jimblackler.jsonschemafriend.StandardGenerationException: {valid=false, keywordLocation=http://json-schema.org/draft-04/schema, absoluteKeywordLocation=http://json-schema.org/draft-04/schema#, instanceLocation=, errors=[{valid=false, error=Expected: [object] Found: [string], keywordLocation=http://json-schema.org/draft-04/schema, absoluteKeywordLocation=http://json-schema.org/draft-04/schema#, instanceLocation=#}]}
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:233)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:138)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:94)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:86)
at org.example.Main.main(Main.java:26)
1:15:12 PM: Execution finished ':org.example.Main.main()'.
I cannot get a schema string to load. I consistently get a TypeError expecting an object but found string with my implementation and then when I try to run the basic example with json string from your documentation I get a TypeError saying it expected an integer but got boolean. I'm using the 0.12.4 version using Java 11 (corretto), I first started with Java 22. I tried previous versions of your build but the result has been the same. Clean intellij project using gradle and you're the only dependency.