GithubHelp home page GithubHelp logo

Comments (16)

RicoSuter avatar RicoSuter commented on August 12, 2024

So this is for the JSON Schema generator from a C# type? Can you provide a sample?

from njsonschema.

AndyEdmonds avatar AndyEdmonds commented on August 12, 2024
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.

RicoSuter avatar RicoSuter commented on August 12, 2024

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.

AndyEdmonds avatar AndyEdmonds commented on August 12, 2024

Hi, I certainly can post process, and that's the interim fix, but it's clumsy. Your solution looks good.

from njsonschema.

RicoSuter avatar RicoSuter commented on August 12, 2024

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.

AndyEdmonds avatar AndyEdmonds commented on August 12, 2024

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.

RicoSuter avatar RicoSuter commented on August 12, 2024

The readonly keyword has been removed: http://json-schema.org/latest/json-schema-hypermedia.html#anchor15

image

from njsonschema.

RicoSuter avatar RicoSuter commented on August 12, 2024

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.

RicoSuter avatar RicoSuter commented on August 12, 2024

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.

AndyEdmonds avatar AndyEdmonds commented on August 12, 2024

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.

RicoSuter avatar RicoSuter commented on August 12, 2024

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.

RicoSuter avatar RicoSuter commented on August 12, 2024

Ok, ill add the attributes JsonSchemaFormat and JsonSchemaType to the NuGet NJsonSchema. Additionally a IsReadOnly property to the JsonSchema4 class & documentation

from njsonschema.

RicoSuter avatar RicoSuter commented on August 12, 2024

... then you can "abuse" the format field ;-)

from njsonschema.

RicoSuter avatar RicoSuter commented on August 12, 2024

Ok, features added:

IsReadOnly: 0cf3a63
JsonSchemaAttribute: e56b008

from njsonschema.

RicoSuter avatar RicoSuter commented on August 12, 2024

NuGet v1.37 released: https://www.nuget.org/packages/NJsonSchema/1.37.5912.16399

from njsonschema.

RicoSuter avatar RicoSuter commented on August 12, 2024

Dokumented here: https://github.com/NJsonSchema/NJsonSchema/wiki/JsonSchemaGenerator

from njsonschema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.