Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ History
* (2009.10.05) "v0" -- "orderly-json.org":http://orderly-json.org was erected and a more fully baked proposal put together thanks to feedback.
* (2009.10.07) "v1" -- editorial review, small additions
* (2009.12.24) "v2" -- Major revisions. Complete reference implmeentation.

* (2009-2011) -- Fall behind the rapidly changing json schema standard

Contributing
------------

Expand Down
37 changes: 30 additions & 7 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
1. sh1ttons of broken jsonschemas!
2. sh1ttons of invalid, but legal json
3. track down 64-bit double error validator problem
In priority order
High
1. merge in language agnostic test suite
2. add conversion between the various standards for json schema :D
3. update to support all 3 draft versions (2,3, and 4 upon release).
we'll need to add a flag to orderly_writer_config to control
what version gets emitted
== incompatability notes ==
g2, we said "optional" : "true"
v3, that became default and we now say "required" : "false"
================
medium
4. extends
- implement merging of the extended schema
at ajv-alloc_schema() call.
- get lloyd to remind me what we discussed
here about binding to http and keeping a cache.
5. Verify we're using yajl version 2.
6. track down 64-bit double error validator problem

================
low
================
6. jsonschema "format" --
support via backticks currently, add to orderly?
7. disallow I'm thinking WONTFIX

other/later (add explicit support for?):
1. extends
2. disallow
3. maxDecimal
4. jsonschema "format" -- support via backticks currently, add to orderly?
8. disallow
9. diviibleBy
8. maxDecimal << not in V4 or V3

4 changes: 3 additions & 1 deletion src/api/ajv_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ ORDERLY_API yajl_status ajv_parse_complete(ajv_handle hand);
ORDERLY_API void ajv_free_error(ajv_handle hand, unsigned char *err);
ORDERLY_API unsigned int ajv_get_bytes_consumed(ajv_handle hand);
typedef int (*ajv_format_checker)(const char *string, unsigned int length);

/* Register a callback to give meaning to value for the "format"
key. */

ORDERLY_API void ajv_register_format(const char *name, ajv_format_checker checker);

#ifdef __cplusplus
Expand Down
7 changes: 6 additions & 1 deletion src/orderly_json_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,12 @@ parse_json_schema(orderly_alloc_funcs * alloc,
}
}
}
else {
else if (!strcmp(k->k, "$schema")) {
/* XXX: detect schema version, and store it somewhere!?,
then go back and adjust things */


} else {
orderly_json ** jPtr;

/* all unexpected properties are passed through using
Expand Down
26 changes: 20 additions & 6 deletions src/orderly_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#include <stdio.h>
#include <string.h>

#define JSON_SCHEMA_V_2 "http://json-schema.org/schema"


struct orderly_writer_t
{
struct orderly_writer_config cfg;
Expand Down Expand Up @@ -289,16 +292,21 @@ dumpNodeAsOrderly(orderly_writer w, const orderly_node * n, unsigned int indent,
#define YAJL_GEN_STRING_WLEN(yg, s) \
yajl_gen_string((yg), (const unsigned char *) (s), strlen(s));


static int
dumpNodeAsJSONSchema(orderly_writer w, const orderly_node * n, yajl_gen yg)
dumpNodeAsJSONSchema1(orderly_writer w, const orderly_node * n,
yajl_gen yg, int needs_schema_reference)
{
if (n) {
const char * type = orderly_node_type_to_string(n->t);
if (!type) return 0;

/* open up this entry */
yajl_gen_map_open(yg);

if (needs_schema_reference) {
YAJL_GEN_STRING_WLEN(yg, "$schema");
YAJL_GEN_STRING_WLEN(yg, JSON_SCHEMA_V_2);
}
/* dump the type */
if (n->t != orderly_node_union) {
YAJL_GEN_STRING_WLEN(yg, "type");
Expand All @@ -312,11 +320,11 @@ dumpNodeAsJSONSchema(orderly_writer w, const orderly_node * n, yajl_gen yg)
const orderly_node * k = NULL;
yajl_gen_array_open(yg);
for (k = n->child; k; k = k->sibling) {
dumpNodeAsJSONSchema(w, k, yg);
dumpNodeAsJSONSchema1(w, k, yg, 0);
}
yajl_gen_array_close(yg);
} else {
dumpNodeAsJSONSchema(w, n->child, yg);
dumpNodeAsJSONSchema1(w, n->child, yg, 0);
}
} else if (n->t == orderly_node_object) {
const orderly_node * kid = n->child;
Expand All @@ -325,7 +333,7 @@ dumpNodeAsJSONSchema(orderly_writer w, const orderly_node * n, yajl_gen yg)
for (kid = n->child; kid != NULL; kid = kid->sibling) {
if (!kid->name) return 0;
YAJL_GEN_STRING_WLEN(yg, kid->name);
dumpNodeAsJSONSchema(w, kid, yg);
dumpNodeAsJSONSchema1(w, kid, yg, 0);
}
yajl_gen_map_close(yg);
} else if (n->t == orderly_node_union) {
Expand All @@ -334,7 +342,7 @@ dumpNodeAsJSONSchema(orderly_writer w, const orderly_node * n, yajl_gen yg)
YAJL_GEN_STRING_WLEN(yg, "type");
yajl_gen_array_open(yg);
for (k = n->child; k; k = k->sibling) {
dumpNodeAsJSONSchema(w, k, yg);
dumpNodeAsJSONSchema1(w, k, yg, 0);
}
yajl_gen_array_close(yg);
}
Expand Down Expand Up @@ -449,6 +457,12 @@ dumpNodeAsJSONSchema(orderly_writer w, const orderly_node * n, yajl_gen yg)
}


static int
dumpNodeAsJSONSchema(orderly_writer w, const orderly_node * n, yajl_gen yg)
{
return dumpNodeAsJSONSchema1(w,n,yg,1);
}

static void
bufAppendCallback(void * ctx, const char * str, unsigned int len)
{
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/additional.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"employee": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/additional_any.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "array",
"items": {
"type": "any"
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/array_any_closed.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "array",
"items": {
"type": "any"
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/array_typing.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"simpleTypedArrayOfIntegers": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/backtick.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "string",
"title": "Service Name",
"description": "The name of the service",
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/default_values.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"mood": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/enum_values.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"mood": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/format.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "string",
"format": "orderly"
}
1 change: 1 addition & 0 deletions test/positive_cases/medium.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"age": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/minimum_hell.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"minLength": 7,
"minimum": 8
}
1 change: 1 addition & 0 deletions test/positive_cases/object.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"first": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/optional.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"foo": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/pattern.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"ipAddress": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/ranges.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"mystring": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/requires.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"foo": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/string.jsonschema
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"$schema": "http://json-schema.org/schema",
"type": "string"
}
1 change: 1 addition & 0 deletions test/positive_cases/types.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"properties": {
"string": {
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/union.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": [
{
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions test/positive_cases/union_hell.jsonschema
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json-schema.org/schema",
"type": [
{
"type": "string",
Expand Down