I wanted to propose an extension for JSON Schema
for classes. This not a proposal to alter JSON Schema itself at all, but is an
extended data format/structure that builds on JSON Schema, adding a few new
properties for defining methods, and this is actually a subset of the SMD (http://groups.google.com/group/json-schema/web/service-mapping-description-proposal),
providing method definition without the transport information. I will call it
JSON Schema Interfaces (open to better names). a JSON Schema Interface can
describe more than just data structures, it could define a full interface for
interacting with object instances. The primary extension point to a JSON Schema
would be that it could additionally include a property "methods". The "methods"
property would have an object value, the property names corresponding to the
names of methods, and the values being the definitions for the methods. The
method definition could consist of a "returns" property with a value being a
schema for the return value, and a "parameters" property which would be an
array, where each item is a schema defining the corresponding
parameter.
JSON Schema would be aligned with the SMD
definition for services. JSON Schema Interfaces would be an extension of JSON
Schema, and SMD would be an extension of JSON Schema Interfaces (adding
transport information):
JSON Schema < JSON Schema Interfaces <
SMD.
Here is an example JSON Schema Interface (JSI for
now on):
{
description: "A Person
Class",
type:"object",
methods: {
getName:{
parameters:[],
returns:{type:"string"}
},
setName:{
parameters:[{type:"string"}]
},
getAddress:{
parameters:[],
returns:{
type:"object",
methods:{
getState:{returns:{type:"string"}},
...
}
}
}
}
}
This essentially defines an interface. This
interface could be implemented in various languages. Just as an example, a Java
impl might look like:
public class Person{
private String
name;
private Address
address;
public String
getName(){
return
name;
}
public void setName(String
name){
}
public Address
getAddress(){
return
address;
}
public static class Address
{
public String
getState(){
...
}
}
This is intended to be a portable interface
definition. There is no class name definition, or any other constraints on how a
system may choose to implement the interface (except for maybe some
implementation hinting strategy per Christoph's suggestions).
The schema for JSI would be:
{
id:"schemaInterface",
description:"JSON Schema Interface",
properties:{
methods:{
additionalProperties:{
description:"Method
Description",
returns:{$ref:"schemaInterface"},
parameters:{
type:"array",
items:{
extends:{$ref:"schemaInterface"},
description:"Parameter Description",
properties:{
name:{type:"string"}
}
}
}
}
}
}
}
Thanks,
Kris