jimblackler / jsongenerator

A JSON data generator from JSON Schemas, provided as a Java library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schema Question

ohadabraham opened this issue · comments

first questions

Riding on your Schema example:
/**

  • Generate random Json with the following schema:
  • {
  • "type": "object",
  • "properties": {
  • "name": { "type": "string" },
    
  • "birthday": { "type": "string","format": "date" },
    
  • "age": { "type": "integer" }
    
  • }
  • }
    */

he fail a lot on : date
Attempt 22:
"0398-45-24" at #/birthday failed against #/properties/birthday with "Not compliant with format: date. Reason: Text '0398-45-24' could not be parsed: Invalid value for MonthOfYear (valid values 1 - 12): 45"

second question

what fields can i put in the Schema ? what i must remove ? ....i.e : this he can not do generator...
Schema example :
{
"$schema": "https://json-schema.org/draft/2019-09/schema#",
"$id": "http://my-paintings-api.com/schemas/painting-schema.json",
"type": "object",
"title": "eor",
"version": 1,
"description": "eor",
"additionalProperties": true,
"required": [
"orgId"
],
"anyOf": [
"projectId"
],
"oneOf": [
"workerID"
],
"properties": {
"orgId": {
"type": "integer",
"minimum": 1,
"description": "orgID"
},
"projectId": {
"type": "integer",
"description": "projectId"
},
"workerID": {
"type": "string",
"description": "workerID"
},
"accountingCodeName": {
"type": "string",
"description": "accountingCodeName"
},
"changedDate": {
"type": "string",
"description": "changedDate"
},
"clientName": {
"type": "string",
"description": "clientName"
},
"projectName": {
"type": "string",
"description": "projectName"
},
"workerName": {
"type": "string",
"description": "workerName"
},
"projectService": {
"type": "string",
"description": "projectService"
},
"source": {
"type": "string",
"description": "source"
},
"userName": {
"type": "string",
"description": "userName"
},
"previousValue": {
"type": "integer",
"description": "previousValue"
},
"newValue": {
"type": "integer",
"description": "newValue"
},
"effectiveDate": {
"type": "string",
"description": "effectiveDate"
}
}
}

and error is 👍
Exception in thread "main" net.jimblackler.jsonschemafriend.StandardGenerationException: {valid=false, keywordLocation=https://json-schema.org/draft/2019-09/schema, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/schema, instanceLocation=, errors=[{valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/core, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/core, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/applicator, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/applicator, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/validation, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/validation, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/meta-data, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/meta-data, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/format, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/format, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/content, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/content, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/schema, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/schema, instanceLocation=#/anyOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/core, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/core, instanceLocation=#/oneOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/applicator, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/applicator, instanceLocation=#/oneOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/validation, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/validation, instanceLocation=#/oneOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/meta-data, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/meta-data, instanceLocation=#/oneOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/format, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/format, instanceLocation=#/oneOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/meta/content, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/meta/content, instanceLocation=#/oneOf/0}, {valid=false, error=Expected: [boolean, object] Found: [string], keywordLocation=https://json-schema.org/draft/2019-09/schema, absoluteKeywordLocation=https://json-schema.org/draft/2019-09/schema, instanceLocation=#/oneOf/0}]}
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:206)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:117)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:97)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchema(SchemaStore.java:73)
at net.jimblackler.jsonschemafriend.SchemaStore.loadSchemaJson(SchemaStore.java:110)
at com.example.demo.DemoApplication.fake(DemoApplication.java:68)
at com.example.demo.DemoApplication.main(DemoApplication.java:39)

I don't recall writing anything to handle date types specifically. Probably wouldn't be too difficult to add. Or you could work around it by removing the date format specifier from your schema.

ok , will bypass it... thank u