All Projects → H2CO3 → magnet

H2CO3 / magnet

Licence: MIT license
A JSON/BSON schema generator

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to magnet

another-json-schema
Another JSON Schema validator, simple & flexible & intuitive.
Stars: ✭ 48 (+200%)
Mutual labels:  schema, json-schema
Vue Json Ui Editor
Edit JSON in UI form with JSON Schema and Vue.js
Stars: ✭ 392 (+2350%)
Mutual labels:  schema, json-schema
fform
Flexibile and extendable form builder with constructor
Stars: ✭ 26 (+62.5%)
Mutual labels:  schema, json-schema
sf-java-ui
Json Schema Form java based library allow developers to define schema and form using field annotations
Stars: ✭ 23 (+43.75%)
Mutual labels:  schema, json-schema
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+10193.75%)
Mutual labels:  schema, json-schema
ty
Here is a schema checker which can return well typed results. Tell your friends!
Stars: ✭ 21 (+31.25%)
Mutual labels:  schema, json-schema
Json Schema To Ts
Infer TS types from JSON schemas 📝
Stars: ✭ 261 (+1531.25%)
Mutual labels:  schema, json-schema
joyce
Joyce is a highly scalable event-driven Cloud Native Data Hub.
Stars: ✭ 37 (+131.25%)
Mutual labels:  schema, json-schema
Autocomplete Json
Atom autocomplete for JSON files
Stars: ✭ 60 (+275%)
Mutual labels:  schema, json-schema
Schm
Composable schemas for JavaScript and Node.js
Stars: ✭ 498 (+3012.5%)
Mutual labels:  schema, json-schema
element-schema-form
A schema-based element-ui form component for Vue2.x.
Stars: ✭ 31 (+93.75%)
Mutual labels:  schema, json-schema
Newtonsoft.json.schema
Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET
Stars: ✭ 167 (+943.75%)
Mutual labels:  schema, json-schema
typescript-to-json-schema
Generate JSON schema from your Typescript sources
Stars: ✭ 54 (+237.5%)
Mutual labels:  schema, json-schema
schema-shot
Framework-agnostic snapshot testing using "schema by example" for highly dynamic data
Stars: ✭ 34 (+112.5%)
Mutual labels:  schema, json-schema
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+475%)
Mutual labels:  schema, json-schema
Jsonschema
An implementation of the JSON Schema specification for Python
Stars: ✭ 3,474 (+21612.5%)
Mutual labels:  schema, json-schema
Avocado
Strongly-typed MongoDB driver for Rust
Stars: ✭ 70 (+337.5%)
Mutual labels:  json-schema, bson
Plank
A tool for generating immutable model objects
Stars: ✭ 449 (+2706.25%)
Mutual labels:  schema, json-schema
Typedload
Python library to load dynamically typed data into statically typed data structures
Stars: ✭ 120 (+650%)
Mutual labels:  schema, json-schema
Vue Form Json Schema
Create forms using JSON schema. Bring your components!
Stars: ✭ 253 (+1481.25%)
Mutual labels:  schema, json-schema

Magnet, a JSON schema generator

Magnet on crates.io Magnet on docs.rs Magnet Download Magnet License Lines of Code Twitter

These two related crates, magnet_derive and magnet_schema help you define (and, in most cases, automatically derive) MongoDB-flavored JSON schemas for your domain model types. Currently, the primary use case for this library is to make it easy to validate serializeable types when using Avocado or the MongoDB Rust driver.

The defined BsonSchema trait defines a single function, bson_schema, which should/will return a Bson Document that is a valid JSON schema describing the structure of the implementing type. Example:

#[macro_use]
extern crate serde_derive;
extern crate serde;
#[macro_use]
extern crate bson;
#[macro_use]
extern crate magnet_derive;
extern crate magnet_schema;
extern crate mongodb;

use std::collections::HashSet;
use magnet_schema::BsonSchema;

use mongodb::{ Client, ThreadedClient, CommandType };
use mongodb::db::{ ThreadedDatabase };

#[derive(BsonSchema)]
struct Person {
    name: String,
    nicknames: HashSet<String>,
    age: usize,
    contact: Option<Contact>,
}

#[derive(BsonSchema, Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
enum Contact {
    Email(String),
    Phone(u64),
}

fn main() {
    let schema = Person::bson_schema();
    let spec = doc! {
        "create": "Person",
        "validator": { "$jsonSchema": schema },
    };
    let client = Client::connect("localhost", 27017).expect("can't connect to mongod");
    let db = client.db("Example");
    db.command(spec, CommandType::CreateCollection, None).expect("network error");
    // etc.
}

For milestones and custom #[attributes], please see the documentation.

Release Notes

v0.8.0

  • Implement BsonSchema for VecDeque, BinaryHeap, LinkedList, Range, RangeInclusive, and PhantomData
  • Add Eq + Hash and Ord bounds on map keys and set elements where appropriate

v0.7.0

  • Upgrade uuid dependency to 0.7.1, and include v4 and serde features
  • Upgrade url dependency to 1.7.2

v0.6.0

  • impl BsonSchema for arrays of size 2N between 128 and 65536; and sizes 1.5 * 2N between 96 and 1536.
  • Rewrite generics handling using syn::Generics::split_for_impl
  • Use scoped lints in magnet_schema as well

v0.5.0

  • Handle generic types with default generic parameters correctly, by not including the defaults in the generated impl (which would result in a compiler error)
  • Use scoped lints for Clippy
  • Update some dependencies

v0.4.0

  • Update bson to 0.13.0 and require its u2i feature. This version fixes a bug where unit struct were serialized as 1-element arrays. The u2i feature allows unsigned integers (within the appropriate range) to be serialized as signed integers.

v0.3.3

  • Fix a bug where Option<enum> was not allowed to be null/None by the generated BSON schema
  • Remove an incorrect item from the documentation
  • Fix several Clippy lints
  • Update dependencies

v0.3.2

  • impl BsonSchema for Document
  • impl BsonSchema for ObjectId
  • Documentation improvements
  • Update dependencies

v0.3.1

  • Relax Display bound for HashMap/BTreeMap keys, use ToString instead
  • Update proc_macro2 dependency so that we can use TokenStream::default()

v0.3.0

  • Remove #[magnet(rename = "...")] attribute
  • UnorderedDoc::eq(), assert_doc_eq! and assert_doc_ne! no longer clone their arguments
  • Update syn and quote dependencies
  • Improve documentation

v0.2.1

  • Update bson dependency

v0.2.0

  • Support for generic types

v0.1.4

  • Unit tests and a test suite have been added.
  • Bug fix: Option::bson_schema() didn't handle the bsonType field, so Option<integer> wasn't allowed to be null. This has been corrected.
  • Bug fix: every generated schema now uses Bson::I64 for representing array lengths / collection counts
  • Enhancement: impl BsonSchema for { HashMap, BTreeMap } now has a less stringent trait bound on the key. It is now Display instead of AsRef<str>.

v0.1.3

  • Add support for #[magnet(min_incl = "...", min_excl = "...", max_incl = "...", max_excl = "...")] attributes on struct fields (named as well as newtype and tuple)

v0.1.2

  • Add support for enums, respecting Serde's tagging conventions (untagged/external/internal/adjacent), except newtype variants around other (inner) enums
  • Refactoring, code quality improvements

v0.1.1

  • Add support for newtype structs and tuple structs
  • Respect #[serde(rename_all = "...")] and #[serde(rename = "...")] attributes
  • Add Serde-conform case conversion
  • Code formatting / organization and documentation improvements

v0.1.0

  • Initial release, only regular structs with named fields are supported
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].