H2CO3 / magnet

A JSON/BSON schema generator
MIT License
17 stars 4 forks source link

Json schema #3

Open xoac opened 6 years ago

xoac commented 6 years ago

Hi, You described crate as JSON/BSON schema generator. But for now there is no Json schema generator (or I can't find)? Do you have plan to add it?

For example: Generate from rust struct used bson_schema().

{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "i"
  ],
  "properties": {
    "i": {
      "bsonType": [
        "int",
        "long"
      ],
      "minimum": -2147483648,
      "maximum": 2147483647
    }
  }
}

for json should looks like this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "i": {
      "type": "integer",
      "minimum": -2147483648, 
      "maximum": 2147483647
    }
  },
  "required": [
    "i"
  ]
}

I am not using it with mongo, so question is that u want to make it more general?

H2CO3 commented 6 years ago

Hi, and thanks for contributing!

Yes, generation of regular standard-conformant JSON schemas is also planned, it's just that I needed this for MongoDB validation so that was the first thing I implemented. The code needs some refactoring anyway, because the way it handles some features (e.g. enum tagging and maximum/minimum bounds) got a bit convoluted, but after that, two additional things should be possible: – JSON schema generation and – adding comment fields based on doc comments for human consumers of the schemas (there's an outstanding partial pull request for it already).

xoac commented 6 years ago

Great. I need JSON schema to my project. I am new to rust macros. But if u have some plan how to refactor and describe how would u like API should be. I can try submit PR.

Are u plan to support just draft4 or draft7 also?

H2CO3 commented 6 years ago

I think if we adhere to a standard it might as well be the latest one, so I'd say let's target v7 unless there's something in it that's excessively difficult to implement (I haven't yet looked at the differences, will do during the weekend.)

xoac commented 6 years ago

Feel free to notify me with your plan of impl/refactor. I am rather junior but I will try help if you wish.

jo2wan commented 5 years ago

Hi guys,

Any update on your plan regarding this json schema generator? I may be able to contribute, also, I expect also some convergence with serde json. Perhaps you already have some good view on the next steps to get a good json schema generator

H2CO3 commented 5 years ago

Hey there! Unfortunately, these days I have very little time to add new features. 😞 Implementing this without excessive code copy-and-paste would require at least some sort of refactoring. Anyone is welcome to start that, so if you're interested, let me explain it in more detail.

jo2wan commented 5 years ago

Yes, sure, please share your plan for refactoring/impl. I'll see how I can contribute.

H2CO3 commented 5 years ago

Awesome! So, here are a couple of things – this list is possibly (likely) non-exhaustive, so I'll have to trust you with good taste and style:

Thanks for picking this up, and good luck!