Skip to content

Json schema

Maxim edited this page Feb 21, 2020 · 4 revisions

From file:

IEdmModel edmModel;
using (var reader = XmlReader.Create("edmx_schema.xml"))
    edmModel = CsdlReader.Parse(reader);

var generator = new OeJsonSchemaGenerator(edmModel);
using (var utf8Json = new MemoryStream())
{
    generator.Generate(utf8Json);
    utf8Json.Position = 0;
    File.WriteAllBytes("json_schema.json", utf8Json.ToArray());
}

From code:

var dataAdapter = new OeEfCoreDataAdapter<OrderContext>(OrderContextOptions.Create(true));
var generator = new OeJsonSchemaGenerator(dataAdapter.BuildEdmModel());
using (var utf8Json = new MemoryStream())
{
    generator.Generate(utf8Json);
    utf8Json.Position = 0;
    Console.WriteLine(new StreamReader(utf8Json).ReadToEnd());
}

Asp .net core:

public void Configure(IApplicationBuilder app)
{
    var dataAdapter = new OrderDataAdapter(true, true);
    app.UseOdataToEntityMiddleware<OePageMiddleware>("/api", dataAdapter.BuildEdmModelFromEfCoreModel());
}

OePageMiddleware add endpoint $json-schema like http://localhost:5000/api/$json-schema.

Generating code javascript, typescript, c# from json schema, recommended way to use quicktype.