Hi,
I was looking at this some months ago and there was no tool. I was thinking to do it in Python. With the recent work related to JSON in Cap'n Proto, it's maybe easier to do this in C++.
I think that having a JSON schema can be useful, because there are libraries automatically generating the web user interface.
It could be simple to do a basic cap'n proto schema to JSON schema tool. But, if you want to do more advanced things, like using minimum/maximum, title, reference, units, format, etc, it's harder because cap'n proto schema don't have all those things. You need to add annotations. I was thinking to have a schema to handle them. For example:
# String formats
const datetime :Text = "date-time"; # RFC 3339, section 5.6
const email :Text = "email"; # RFC 5322, section 3.4.1
const hostname :Text = "hostname"; # RFC 1034, section 3.1
const ipv4 :Text = "ipv4"; # RFC 2673, section 3.2
const ipv6 :Text = "ipv6"; # RFC 2373, section 2.2
const uri :Text = "uri"; # RFC 3986
# "units":
annotation units @0x9caa3354d2f1c633 (field) :Text;
const unitsAnnotationId :UInt64 = 0x9caa3354d2f1c633;
# "hidden": true
#annotation hidden (field) :Void;
#const hiddenAnnotationId :UInt64 = ;
#annotation rfc3339 @0xb6d6d8943d576768 (*) :Void;
#const rfc3339AnnotationId :UInt64 = 0xb6d6d8943d576768;
# readOnly=true
annotation readOnly @0xd437766f1b485772 (field, struct) :Void;
const readOnlyAnnotationId :UInt64 = 0xd437766f1b485772;
# "uniqueItems": true
annotation uniqueItems @0x9347cdc70f0ca3ac (field) :Void;
const uniqueItemsAnnotationId :UInt64 = 0x9347cdc70f0ca3ac;
# "pattern":
annotation pattern @0x80e125fe157241b8 (field) :Text;
const patternAnnotationId :UInt64 = 0x80e125fe157241b8;
# "format": "date-time", "email", "hostname", "ipv4", "ipv6", "uri"
annotation format @0xa6b3c8b9eaa3b416 (field) :Text;
const formatAnnotationId :UInt64 = 0xa6b3c8b9eaa3b416;
# "minLength":
annotation minLengthUint16 @0xe22fc2a6bab37f0c (field) :UInt16;
const minLengthUint16AnnotationId :UInt64 = 0xe22fc2a6bab37f0c;
# "maxLength:
annotation maxLengthUint16 @0xe47fc96550c8baa7 (field) :UInt16;
const maxLengthUint16AnnotationId :UInt64 = 0xe47fc96550c8baa7;
# "multipleOfFloat":
annotation multipleOfInt32 @0xdd886092a32b871f (field) :Float32;
const multipleOfInt32AnnotationId :UInt64 = 0xdd886092a32b871f;
#annotation multipleOfFloat32 (field) :Float32;
#const multipleOfFloat32AnnotationId :UInt64 = ;
annotation multipleOfFloat64 @0x857d1a06a23c76f9 (field) :Float64;
const multipleOfFloat64AnnotationId :UInt64 = 0x857d1a06a23c76f9;
# "exclusiveMinimum": true
annotation exclusiveMinimum @0x91e6230ba7bf0bf6 (field): Void;
const exclusiveMinimumAnnotationId :UInt64 = 0x91e6230ba7bf0bf6;
# "exclusiveMaximum": true
annotation exclusiveMaximum @0xfe1569266c25cd23 (field): Void;
const exclusiveMaximumAnnotationId :UInt64 = 0xfe1569266c25cd23;
# "minimum":
#annotation minimumInt16 (field) :Int16;
#const minimumInt16AnnotationId :UInt64 = ;
annotation minimumUint16 @0xf3a306fd9cb560cc (field) :UInt16;
const minimumUint16AnnotationId :UInt64 = 0xf3a306fd9cb560cc;
annotation minimumInt32 @0xe3a4c77f928f11f1 (field) :Int32;
const minimumInt32AnnotationId :UInt64 = 0xe3a4c77f928f11f1;
#annotation minimumUint32 (field) :UInt32;
#const minimumUint32AnnotationId :UInt64 = ;
#annotation minimumFloat32 (field) :Float32;
#const minimumFloat32AnnotationId :UInt64 = ;
annotation minimumFloat64 @0xc31db5c1eea61fa2 (field) :Float64;
const minimumFloat64AnnotationId :UInt64 = 0xc31db5c1eea61fa2;
# "maximum":
#annotation maximumInt16 (field) :Int16;
#const maximumInt16AnnotationId :UInt64 = ;
annotation maximumUint16 @0x8cc82e85ae657500 (field) :UInt16;
const maximumUint16AnnotationId :UInt64 = 0x8cc82e85ae657500;
annotation maximumInt32 @0x81f5d672443fc146 (field) :Int32;
const maximumInt32AnnotationId :UInt64 = 0x81f5d672443fc146;
#annotation maximumUint32 (field) :UInt32;
#const maximumUint32AnnotationId :UInt64 = ;
#annotation maximumFloat32 (field) :Float32;
#const maximumFloat32AnnotationId :UInt64 = ;
annotation maximumFloat64 @0xfedd17bd33458fb8 (field) :Float64;
const maximumFloat64AnnotationId :UInt64 = 0xfedd17bd33458fb8;
Then, a structure would be written like this in another cap'n proto schema:
struct Params
{
param1 @0 :Float64 = 50 $AttribJson.units("%") $AttribJson.minimumFloat64(0.0) $AttribJson.maximumFloat64(100.0) $AttribJson.multipleOfFloat64(0.1);
param2 @1 :UInt16 = 0 $AttribJson.units("ms")
$AttribJson.minimumUint16(0)
$AttribJson.maximumUint16(999);
}
Then, in the cap'n proto to JSON schema tool, you need to read the annotations.
Jean-François Gauvin