cvent / deprecated-json-schema-2-poco Goto Github PK
View Code? Open in Web Editor NEWConverts JSON schemas to C# POCOs
Converts JSON schemas to C# POCOs
Create a new class when there is a nested property.
Example: default: {}
if you use a title with extends, and extends is on one single line like:
"extends": { "$ref": "requestBase.json"},
with a 'title' element,
the class name is 'DefaultClassName.cs'
instead of what is given in 'title.'
The workaround is to make the extends use multiple lines, and the class name then correctly matches the title.
Example:
{
"default": true
}
Currently, all the validation attributes are made for validation with ASP.NET WebAPI. They come from the System.ComponentModel.DataAnnotations
namespace. To make the attributes work when deserializing with JSON.net, the attributes must be under the JsonProperty
attribute.
Example: Currently, a required attribute looks like this:
[Required()]
To be deserializable with JSON.net, it must look like this:
[JsonProperty(Required = Required.Always)]
An option should be given to decide which set of attributes to use.
I tried to generate poco's based off a schema that didn't have a title property, and the executable errored out with this stacktrace:
Unhandled Exception: System.ArgumentNullException: Value cannot be null. Parameter name: key at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at Cvent.JsonSchema2Poco.JsonSchema2Poco.GetUniqueSchemaClasses(JsonSchemaClass jsonClass, Dictionary2 uniqueClassesById, Dictionary2 uniqueClassesByName) at Cvent.JsonSchema2Poco.JsonSchema2Poco.GetUniqueSchemaClasses(IEnumerable1 schemas) at Cvent.JsonSchema2Poco.JsonSchema2Poco.Generate(IGenerationConfig configuration) at Cvent.JsonSchema2Poco.Program.Main(String[] args)
Preferably it should detect this is missing and throw a more informative error message.
When using this Basic example schema on : http://json-schema.org/examples.html
{
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}
The software generates this error:
2015-06-16 21:19:15.1404 [Error] Could not parse the schema: file:///c:/temp/jschema.json
Make sure your schema is compatible.Examine the stack trace below.
2015-06-16 21:19:15.1603 [Fatal] System.ArgumentException: Can not convert Array to Boolean.
at Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)
at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessSchemaProperties(JObject schemaObject)
at Newtonsoft.Json.Schema.JsonSchemaBuilder.BuildSchema(JToken token)
at Newtonsoft.Json.Schema.JsonSchemaBuilder.Read(JsonReader reader)
at Newtonsoft.Json.Schema.JsonSchema.Read(JsonReader reader, JsonSchemaResolver resolver)
at Newtonsoft.Json.Schema.JsonSchema.Parse(String json, JsonSchemaResolver resolver)
at Cvent.SchemaToPoco.Core.JsonSchemaResolver.ResolveSchemaHelper(Uri curr, Uri parent, String data) in C:\Users\Stef\Documents\Github\forks\json-schema-2-poco
Example: schema1
has a $ref
to schema2
, and schema2
has a $ref
to schema1
.
Cause: ResolveSchemas
in Program.cs
resolves references by scanning through the file for .json
and recursively calls itself.
Example: See dashboard.json
Example: "$ref": "http://jsonschema.net/examples/B.json"
Class names with a space will persist in generated C# code.
This repository has no license information included, which limits the benefit of sharing it publicly here as people may avoid using it to avoid facing legal issues.
If you intend to allow this code to be used freely, it would be helpful if you could select an open source license and note you are releasing the code under that license: http://opensource.org/licenses. (If that's not your intention, it would be helpful to note that as well!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.