Questions tagged [njsonschema]

A .Net library for validating JSON against a schema or generating a schema from an existing .Net class.

The library can read a schema from a file or string and validate JSON data against it. A schema can also be generated from an existing .NET class. With the code generation APIs you can generate C# and TypeScript classes or interfaces from a schema.

http://NJsonSchema.org

59 questions
0
votes
1 answer

JSON Schema relative references resolution

I am trying to define a valid JSON Schema and I am not sure how to structure the reference ("$ref") values when referenced components are in sub-directories. I have read (at length) the info at the official JSON Schema site as well as examined test…
0
votes
1 answer

how to validate Jarray response data schema

I have a json schema validate function something like following private void ValidateJsonSchema(string jsonData) { var schema = JsonSchema.FromType(); var errors = schema.Validate(jsonData); } the param jsonData is the…
cz.g
  • 1
  • 1
0
votes
1 answer

Generate swagger v2 schema by NJsonSchema for .NET or Newtonsoft.Json.Schema

I need to use a tool, preferably NJsonSchema for .NET to generate schemas from c# classes. The requirement is to create schemas based on swagger version 2. For example I cannot have oneOf, anyOf, etc, which are new keywords in OAS3 in the…
CageE
  • 419
  • 4
  • 13
0
votes
1 answer

Add a root object to NJsonSchema schema generator

I'm using NJsonSchema to generate JasonSchema from c# classes. I can create this schema: { "title": "SchemaModel", "type": "object", "additionalProperties": false, "properties": { "caseId": { "title": "Case Id", …
CageE
  • 419
  • 4
  • 13
0
votes
0 answers

Is there alternative for JSchemaPreloadedResolver?

I am trying to resolve a JSON schema from a URL. I can use JSchemaPreloadedResolver from the Newtonsoft.Json.Schema library to do this but I must not use this library. Is there any other alternative for this? Perhaps in NJsonSchema or any other…
Piyush Sardana
  • 1,748
  • 4
  • 19
  • 33
0
votes
0 answers

Validate json to determine under-post in NJsonSchema C#

Given a json schema built by swagger I'd like to validate a json requests and responses of my endpoints. If my json data has not all non-required fields, that are described in the schema, then no errors are returned. How can I modify/extend behavior…
ASout
  • 21
  • 1
0
votes
0 answers

How to generate JSON schema from type constructor using NJsonSchema?

I'm using NJsonSchema for schema generation from C# types. public sealed class Config { [JsonConstructor] public Config([RegularExpression("Name.*123")] string name) { Name = name; } public string Name { get; } } And…
Hopeless
  • 579
  • 1
  • 8
  • 25
0
votes
0 answers

How do I allow null properties on my generated POCO classes?

Using NJsonSchema.CodeGeneration, I'm able to output the properties as-defined in JSON schema. However, I noticed that in the generated, code, a couple of things are going on: all of the properties have the Required = Newtonsoft...DisallowNull…
theMayer
  • 15,456
  • 7
  • 58
  • 90
0
votes
3 answers

Setting a property within a class that has an internal setter for use in testing (C#)

I'm using NJsonSchema to validate JSON input. I have a small class that takes a collection of ValidationError objects and creates more user friendly error messages using the contents of each validation error. I want to be able to write unit tests…
Jake12342134
  • 1,539
  • 1
  • 18
  • 45
0
votes
0 answers

Why is this simple Json schema invalid in NJsonchema?

I am testing NJsonschema and found following simple Json schema is invalid. The original schema is a big schema contains a lot of definitions, one of the definitions (ResourceList) is a list contains a lot of other definitions, but to simplify the…
Bochen Lin
  • 413
  • 4
  • 12
0
votes
2 answers

NJsonSchema: If I know a field in my schema can only have a few finite values at runtime, can I add this to my validation logic?

Taking an example from their GitHub, if I knew at runtime the First name could ONLY be "Bob" OR "Bill" could I validate against this? public class Person { [Required] public string FirstName { get; set; } public string MiddleName { get;…
0
votes
1 answer

generating C# class names for objects in collections according to collection property name

I'm trying to use NJsonSchema to generate C# classes, but it's naming the classes for objects in an array "anonymous_". For example, this json schema snippet "Identifiers": { "type": "array", "items": { "type":…
chennen
  • 1
  • 1
0
votes
1 answer

Directing NJsonSchema to treat custom dictionary like regular Dictionary

Let's say I have these configuration classes: public class Config { [Required] public ConfigDictionary Files { get; set; } } public class ConfigDictionary : Dictionary { public ConfigDictionary() :…
Jeremy Cook
  • 20,840
  • 9
  • 71
  • 77
-1
votes
1 answer

Parse Json into a schema-generated set of classes

I have a Json schema and can use NJsonSchema.CodeGeneration.CSharp to create classes corresponding to it. So if I have json which conforms to the schema, I should be able to easily parse it into a collection of objects whose classes are the classes…
Richard Hunt
  • 303
  • 2
  • 10
1 2 3
4