Comments (16)
So this is for the JSON Schema generator from a C# type? Can you provide a sample?
from njsonschema.
public class Connectivity
{
[Required]
[Display(Name = "External connections", Description = "Connections to external SaaS vendors triggered by or triggering projects")]
public List<Connector> connectors { get; set; }
}
public enum ConnectorType { twilio, sendgrid, skype, facebook, custom}
public class Connector
{
[Required]
[Display(Name = "SaaS vendor", Description = "The SaaS service you are connecting to.")]
public ConnectorType type { get; set; }
[Required]
[Display(Name = "Your ID", Description = "The SaaS service ID that identifies your account")]
public string id { get; set; }
[Required]
[Display(Name = "Your API key", Description = "The SaaS service secret token or API key")]
public string key { get; set; }
[Display(Name = "The destination address", Description = "The destination of any transmission over a public medium")]
public string dest { get; set; }
}
creates the schema:
{
"typeName": "Connectivity",
"additionalProperties": false,
"type": "object",
"required": [
"connectors"
],
"properties": {
"connectors": {
"items": {
"typeName": "Connector",
"additionalProperties": false,
"type": "object",
"required": [
"type",
"id",
"key"
],
"properties": {
"type": {
"typeName": "ConnectorType",
"type": "integer",
"enum": [
0,
1,
2,
3,
4
],
"enumNames": [
"twilio",
"sendgrid",
"skype",
"facebook",
"custom"
],
"title": "SaaS vendor",
"description": "The SaaS service you are connecting to."
},
"id": {
"type": "string",
"title": "Your ID",
"description": "The SaaS service ID that identifies your account"
},
"key": {
"type": "string",
"title": "Your API key",
"description": "The SaaS service secret token or API key"
},
"dest": {
"type": [
"null",
"string"
],
"title": "The destination address",
"description": "The destination of any transmission over a public medium"
}
}
},
"type": "array",
"title": "External connections",
"description": "Connections to external SaaS vendors triggered by or triggering projects"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
}
In order to get json-editor to display this in grid format, the first part of the schema should be:
{
"typeName": "Connectivity",
"additionalProperties": false,
"type": "object",
"format": "grid",
"required": [
"connectors"
],
I'm looking for some method to inject this. I want to use your tool to dynamically create the json so that changes to the classes are automatically reflected in the editor.
from njsonschema.
Can't you post process the generated schema and add the additional format
strings?
We could add a custom attribute like this:
[JsonFormat("grid")]
public class Connectivity
{
public List<Connector> connectors { get; set; }
}
However I'm not yet sure if this is a good idea (as it is a custom JSON Schema extension)
from njsonschema.
Hi, I certainly can post process, and that's the interim fix, but it's clumsy. Your solution looks good.
from njsonschema.
Hmm, the problem is, that there is currently no annotations NuGet... can we use an attribute of the .NET framework or Json.NET? Is DataTypeAttibute
a fit?
from njsonschema.
That was my guess. There is a custom datatype defined. Also, and I should probably make this a separate issue, do you support readOnly? It's in the Json schema spec, and the matching attribute is
[ReadOnly(true)]
from njsonschema.
The readonly keyword has been removed: http://json-schema.org/latest/json-schema-hypermedia.html#anchor15
from njsonschema.
And btw: Using the format
property for describing the UI is wrong. The property is intended to describe the format of the value (i.e. how to parse it) and not how to display it (i.e. list, grid, etc). See http://json-schema.org/latest/json-schema-validation.html#anchor104
from njsonschema.
Maybe you should write an object tree traverser to enhance the model for your needs... All your are extremely customized for your needs and do not really fit into a generic JSON Schema library...
from njsonschema.
Hi Rico,
They've moved it to the hyper schema. It's still there as far as I can see on your link.
You are probably right that json-editor is trying to stretch the spec, but it would be nice anyway.
from njsonschema.
I understand your problem, as I've implemented something similar: http://visualjsoneditor.org. It is important only add really required customizations because you can never remove/or change them later...
from njsonschema.
Ok, ill add the attributes JsonSchemaFormat
and JsonSchemaType
to the NuGet NJsonSchema
. Additionally a IsReadOnly
property to the JsonSchema4
class & documentation
from njsonschema.
... then you can "abuse" the format field ;-)
from njsonschema.
Ok, features added:
IsReadOnly: 0cf3a63
JsonSchemaAttribute: e56b008
from njsonschema.
NuGet v1.37 released: https://www.nuget.org/packages/NJsonSchema/1.37.5912.16399
from njsonschema.
Dokumented here: https://github.com/NJsonSchema/NJsonSchema/wiki/JsonSchemaGenerator
from njsonschema.
Related Issues (20)
- Improve base package readme
- AllowAdditionalProperties - not working
- Format "guid" vs "uuid"
- Validation Failures On All JSON Schema Draft Versions
- Private expression-bodied read-only properties should be ignored HOT 1
- Unable to generate document when XmlElement[] is a property of the class
- JsonProperty not working on version 11.0.0 (working on 10.9.0) HOT 1
- Referenced schema could not be loaded when defined in external schema file
- Fixed the bug. "System.InvalidOperationException: Could not resolve the path '#/paths/~1audienceCategories~1%7Ba "
- Annotations on separate lines?
- Polymorphic Schema Generation
- .Net6 to .Net8 upgrade - System.InvalidOperationException: This operation is only valid on generic types. HOT 1
- C# TimeSpan not resolved and generated as a DayJs duration HOT 1
- Property named '-1' generates wrong C# Property name
- Duplicated members
- IEquatable<T> interface
- Method Resolution Conflict in `SystemTextJsonReflectionService`
- INPC: Skip change check (to support partial patch) HOT 1
- Wrong discriminator for inheritance when using mutliple level of inheritance
- How can I create a schema that uses URLs as $ref value?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from njsonschema.