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
3
votes
0 answers

Extension point or access to OpenApiDocument from Liquid Template

We have Specification Extensions (i.e. x-isPrimaryKey) in our generated OpenApiDocument and need to add them as ClassDecorators to our Angular models. e.g. We communicate if is Pk, Fk and property level permissions. I am successfully overriding the…
ttugates
  • 5,818
  • 3
  • 44
  • 54
3
votes
0 answers

Validate JsonSchema itself. Is it correct JSON Schema?

NB! I don't want to validate JSON against JSON Schema! I have 2 JSON files: 1. JSON Schema file: { "title" : "SomeTitle", "type":"object", "properties":{ "City" : {"type" : "string", "editType" : "textarea"} } } 2. JSON…
kgzdev
  • 2,770
  • 2
  • 18
  • 35
3
votes
0 answers

How do I control the output of NJsonSchema for decimals

I have a C# object like so: public class Foo { public decimal Number {get;set;} } And I create a json schema like so: var schema = await JsonSchema4.FromTypeAsync(typeof(Foo)); var jsonSchema = schema.ToJson(); return jsonSchema; { …
user6047922
3
votes
2 answers

JSON Schema to C#

I am looking for a class or tool to convert JSON schema into a C# class as a prebuild step. I have found several "home-brew" solutions (jsonschema.net, NJsonSchema, ...) , but would prefer to use some mature / official code related to a company /…
Stiefel
  • 2,677
  • 3
  • 31
  • 42
3
votes
2 answers

How can I set the AllowAdditionalProperties to true in generating the schema with NJsonSchema

We are now going to use NJsonSchema to check the Json files for required fields only, and we allow user to add some extra fields for their local use. So, it has to allow additional properties in the Json file. By using the NJsonSchma, there has the…
James MA
  • 323
  • 5
  • 14
2
votes
1 answer

check for duplicate properties in JSON

We are working on a .Net core based web api application and for this we have a requirement to validate incoming request body which is JSON format against the c# based type. We are at this point evaluating NJsonSchema library to see if it throws…
user979189
  • 1,230
  • 2
  • 15
  • 39
2
votes
0 answers

How do i removed SchemaReferenceHandling in NjsonSchema

I am working on Generating JSON Schema from .NET type using NJsonSchema. I am getting references("$ref"...) for complex type in the generated json. "properties": { "resourceType": { "type": "string" }, "id": { "type":…
Anish
  • 121
  • 1
  • 8
2
votes
1 answer

NJsonSchema object validation

I can't validate a json string starting from a very simple schema. This is my object type: public class Person { public string Name { get; set; } } public class MyPerson : Person { public string Surname { get; set; } } And this is my…
Daniele Mereu
  • 115
  • 1
  • 8
2
votes
0 answers

NSwag creating duplicate model

I am using NSwag to generate an OpenApi3 spec from my controllers. I also use a custom implementation of IDocumentProcessor to generate models not included in the controllers. The post processor models share abstract classes with the controller…
Codendaal
  • 514
  • 6
  • 14
2
votes
1 answer

How can I change the type of a property with NJsonSchema

I have a series of generic response objects that are being returned with a property that is an abstract class. The NSwag and NJsonSchema generate the schema with an abstract class, which creates problems. The concrete class is easily determined…
drz
  • 962
  • 7
  • 22
2
votes
1 answer

How to force regex pattern on dictionary values (njsonschema)

Using njsonschema, I want to generate a schema that will ensure that all values written to a dictionary will be validated against a regex pattern. Consider the following class: class File { [RegularExpression("^\\d+\\.\\d+\\.\\d+\\.\\d+$")] …
Eitan H.S.
  • 430
  • 3
  • 15
2
votes
1 answer

Deserialization of Json to NJsonSchema generated object with enums containing spaces

need your help. So, i have json schema and i used NJsonSchema.CodeGeneration tool to generate .cs model. I was able of using it to deserialize json into object successfully until the input json contained enum values with spaces in it. Here is what i…
kikaxa
  • 89
  • 6
2
votes
2 answers

Generate JSON Schema from sample JSON data in C# with NJsonSchema

I am hoping this is me not holding it right, but I am trying to generate a JSON schema from a JSON string that I have in memory. I am using the NJsonSchema off of GitHub. https://github.com/NJsonSchema/NJsonSchema/ string json = @"{ ""a"": 1, …
Jerrod Horton
  • 1,605
  • 1
  • 15
  • 30
1
vote
1 answer

KnownType equivalent for discriminator on Interfaces in NSwag

When we need to tell NSwag and the generated OpenAPI 3.0 document that an abstract class should be converted to some concrete type on the client side, I use [KnownType] with a discriminator and that works really well: using Newtonsoft.Json; using…
DavGarcia
  • 18,540
  • 14
  • 58
  • 96
1
vote
0 answers

NSwag Not generating OpenApi3 Spec JSON file

I am using NSwag for generating openapi 3 spec file. I am stuck at generating the Schema for the response types. Since I am using ServiceStack, I tried different options viz., Option 1 var generatorSettings = new JsonSchemaGeneratorSettings {…
Raajkumar
  • 857
  • 2
  • 13
  • 26
1
2 3 4