RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.4k stars 535 forks source link

How do i removed SchemaReferenceHandling in NjsonSchema and have the entire block at same place. #1198

Open aksrxl opened 4 years ago

aksrxl commented 4 years ago

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": "string"
    },
    "onset": {
      "type": "string"
    },
    "recorder": { 
      "$ref": "#/definitions/ResourceReference"
    },

I do not want references , instead i want entire block here itself. I have tried below line of code but it does-not seems to be working.

var settings = new JsonSchemaGeneratorSettings();
setting.settings.AllowReferencesWithProperties = false;
var generator = new NJsonSchema.Generation.JsonSchemaGenerator(settings);

does not work also tried

var settings = new JsonSchemaGeneratorSettings();
settings.SerializerSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.All };
var generator = new NJsonSchema.Generation.JsonSchemaGenerator(settings);

does not work , i always get this reference in the json generated.

I was able to do this by using Newtonsoft.Json package(see below code), but Newtosoft.Json had limitation of 10 schema generation per hour , i had to switch to NJsonSchema.

var generator = new JSchemaGenerator { SchemaReferenceHandling = SchemaReferenceHandling.None };

Is there any way i can have the entire block and not have it referenced, using NJsonSchema.

RicoSuter commented 4 years ago

I think there is currently no simple config to inline schemas and avoid refs...

aksrxl commented 4 years ago

Oh Okay ,will have to manage then , also I could not find any pricing and limitation detail for generating and validating schema on github page, is it free without any limit ?

RicoSuter commented 4 years ago

also I could not find any pricing and limitation detail for generating and validating schema on github page

On GitHub? What are you referring to? The library is free (MIT license)

dnitsch commented 1 year ago

Just wondering if it is possible to now inline the entire document?

AsyncAPI and other tools break on locally defined refs :|.

        var settings = new JsonSchemaGeneratorSettings {
            SerializerSettings = null,
            FlattenInheritanceHierarchy = true,
            AllowReferencesWithProperties = false,
            SerializerOptions = serializerOptions
        };

specifically setting these 2, seems to not have any effect FlattenInheritanceHierarchy = true and AllowReferencesWithProperties = false

Edit 2:

is there a custom schema parser or something that can be passed to remove all definitions and insert the contents inline where they are referenced?