Comments (12)
Can you provide a sample schema and sample data?
from njsonschema.
You want me to include the models? I don't have the actual Schema, I use var schema = JsonSchema4.FromType<ReportItem>();
and var schemaData = schema.ToJson();
to build the schema from my models and then var errors = schema.Validate(JSend.JsonString);
to get the errors.
from njsonschema.
Can you post the schemaData and JSend.JsonString content here (or is it confidential)?
from njsonschema.
here ya go:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"typeName": "ReportItem",
"additionalProperties": false,
"required": [
"ReportID",
"RequiresFilter",
"MimeType",
"ExternalID",
"CreatedBy",
"ExecutionScript",
"ExecutionParameter",
"Columns"
],
"properties": {
"ReportID": {
"type": "string",
"format": "guid"
},
"RequiresFilter": {
"type": "boolean"
},
"MimeType": {
"type": "string"
},
"ExternalID": {
"type": "string"
},
"CreatedBy": {
"type": "string",
"format": "date-time"
},
"ExecutionScript": {
"type": "string"
},
"ExecutionParameter": {
"type": "string"
},
"ExecutionOrderBy": {
"type": [
"null",
"string"
]
},
"DynamicFilters": {
"type": [
"array",
"null"
],
"items": {
"type": "object",
"typeName": "DynamicFilter",
"additionalProperties": false,
"required": [
"ID",
"Script",
"ScriptOrderBy",
"Fields",
"ScriptParams"
],
"properties": {
"ID": {
"type": "string"
},
"Script": {
"type": "string"
},
"ScriptOrderBy": {
"type": "string"
},
"Fields": {
"type": "string"
},
"ScriptParams": {
"type": "object",
"additionalProperties": {
"type": [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string"
]
}
}
}
}
},
"RequiresOrgID": {
"type": "boolean"
},
"ReportFilter": {
"oneOf": [
{
"$ref": "#/definitions/QueryFilter"
},
{
"type": "null"
}
]
},
"ReportRules": {
"oneOf": [
{
"$ref": "#/definitions/QueryRule"
},
{
"type": "null"
}
]
},
"Columns": {
"type": "array",
"items": {
"type": "object",
"typeName": "QueryColumn",
"additionalProperties": false,
"required": [
"isrequired",
"column_name"
],
"properties": {
"isrequired": {
"type": "boolean"
},
"column_name": {
"type": "string"
}
}
}
}
},
"definitions": {
"QueryFilter": {
"type": "object",
"typeName": "QueryFilter",
"additionalProperties": false,
"required": [
"display_errors",
"allow_empty",
"plugins",
"filters"
],
"properties": {
"display_errors": {
"type": "boolean"
},
"allow_empty": {
"type": "boolean"
},
"plugins": {
"type": "array",
"items": {
"type": "string"
}
},
"filters": {
"type": "array",
"items": {
"type": "object",
"typeName": "Filter",
"additionalProperties": false,
"required": [
"id",
"label",
"type",
"operators"
],
"properties": {
"id": {
"type": "string"
},
"label": {
"type": "string"
},
"type": {
"type": "string"
},
"operators": {
"type": "array",
"items": {
"type": "string"
}
},
"input": {
"type": [
"null",
"string"
]
},
"values": {
"type": [
"null",
"object"
],
"additionalProperties": {
"type": [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string"
]
}
},
"validation": {
"oneOf": [
{
"$ref": "#/definitions/Validation"
},
{
"type": "null"
}
]
},
"unique": {
"type": "boolean"
},
"description": {
"type": [
"null",
"string"
]
}
}
}
}
}
},
"QueryRule": {
"type": "object",
"typeName": "QueryRule",
"additionalProperties": false,
"properties": {
"condition": {
"type": [
"null",
"string"
]
},
"rules": {
"type": [
"array",
"null"
],
"items": {
"type": "object",
"typeName": "Rule",
"additionalProperties": false,
"properties": {
"id": {
"type": [
"null",
"string"
]
},
"operator": {
"type": [
"null",
"string"
]
},
"value": {
"type": [
"null",
"object"
]
},
"readonly": {
"type": "boolean"
},
"condition": {
"type": [
"null",
"string"
]
}
}
}
}
}
},
"Validation": {
"type": "object",
"typeName": "Validation",
"additionalProperties": false,
"properties": {
"min": {
"type": "integer"
},
"step": {
"type": "number",
"format": "double"
}
}
}
}
}
from njsonschema.
If I use something simple like {"Key": "Value"} as the json to compare this schema against, that's when I get the error. I'm doing a workaround, but would rather have this work properly if possible.
from njsonschema.
Ok, ill check this asap
from njsonschema.
Sweet. Thanks again!
from njsonschema.
The validation is correct, the error is not a property but an object error and the path is null because it applies to the root object. I added a unit test for your case and appended #
to the error Path
. This way all paths start with #
(= root) and this error on the root object has #
in the Path
property...
from njsonschema.
Do you expect something else?
from njsonschema.
Wasn't thinking about the fact that it's an object and therefore has no path. What I am doing actually works just fine. Thanks for the help.
from njsonschema.
In the next version, each path will start with # (same as in a JSON ref) it will never be null.. Is this a problem for you?
from njsonschema.
This shouldn't be a problem. I'm iterating through the errors and adding them to an array using an Results.Add(new JsonReportErrors { ErrorKind = error.Kind.ToString(), ErrorPath = error.Path.ToString() });
statement and that was erroring out because of the null. Now that it will have a # and not be null, I'll be good.
from njsonschema.
Related Issues (20)
- Using the generic type 'JsonInheritanceConverter<TBase>' requires 1 type argument HOT 2
- NJsonSchema generated code throwing The JSON value could not be converted HOT 1
- Improve base package readme
- AllowAdditionalProperties - not working
- Format "guid" vs "uuid"
- Validation Failures On All JSON Schema Draft Versions
- Private expression-bodied read-only properties should be ignored HOT 1
- Unable to generate document when XmlElement[] is a property of the class
- JsonProperty not working on version 11.0.0 (working on 10.9.0) HOT 1
- Referenced schema could not be loaded when defined in external schema file
- Fixed the bug. "System.InvalidOperationException: Could not resolve the path '#/paths/~1audienceCategories~1%7Ba "
- Annotations on separate lines?
- Polymorphic Schema Generation
- .Net6 to .Net8 upgrade - System.InvalidOperationException: This operation is only valid on generic types. HOT 1
- C# TimeSpan not resolved and generated as a DayJs duration HOT 1
- Property named '-1' generates wrong C# Property name
- Duplicated members
- IEquatable<T> interface
- Method Resolution Conflict in `SystemTextJsonReflectionService`
- INPC: Skip change check (to support partial patch) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from njsonschema.