1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-03 00:38:44 +00:00

Replace rapidjson parser/writer in discord-rpc with rjson

This commit is contained in:
Bernhard Schelling 2020-10-29 16:55:23 +09:00
parent c52a22d839
commit f6f8d3e235
245 changed files with 323 additions and 38523 deletions

View File

@ -2126,8 +2126,7 @@ ifeq ($(HAVE_NETWORKING), 1)
ifeq ($(HAVE_DISCORD), 1)
NEED_CXX_LINKER = 1
DEFINES += -DHAVE_DISCORD
INCLUDE_DIRS += -Ideps/discord-rpc/include \
-Ideps/discord-rpc/thirdparty/rapidjson-1.1.0/include/
INCLUDE_DIRS += -Ideps/discord-rpc/include
ifneq ($(HAVE_THREADS), 1)
DEFINES += -DDISCORD_DISABLE_IO_THREAD

View File

@ -163,8 +163,43 @@ static void Discord_UpdateConnection(void)
if (!Connection->Read(message))
break;
const char *evtName = GetStrMember(&message, "evt");
const char *nonce = GetStrMember(&message, "nonce");
char *evtName = NULL;
char *nonce = NULL;
char *secret = NULL;
char *userId = NULL;
char *username = NULL;
char *avatar = NULL;
char *discriminator = NULL;
char *error_message = NULL;
int error_code = 0;
bool in_data = false, in_user = false;
for (JsonReader r(message); r.NextKey();)
{
if (r.depth == 1)
{
in_data = in_user = false;
if (!strcmp(r.key, "evt" )) r.NextStrDup(&evtName);
else if (!strcmp(r.key, "nonce")) r.NextStrDup(&nonce);
else if (!strcmp(r.key, "data" )) in_data = true;
}
else if (r.depth == 2 && in_data)
{
in_user = false;
if (!strcmp(r.key, "code" )) r.NextInt(&error_code);
else if (!strcmp(r.key, "message")) r.NextStrDup(&error_message);
else if (!strcmp(r.key, "secret" )) r.NextStrDup(&secret);
else if (!strcmp(r.key, "secret" )) r.NextStrDup(&secret);
else if (!strcmp(r.key, "user" )) in_user = true;
}
else if (r.depth == 3 && in_user)
{
if (!strcmp(r.key, "id" )) r.NextStrDup(&userId);
else if (!strcmp(r.key, "username" )) r.NextStrDup(&username);
else if (!strcmp(r.key, "avatar" )) r.NextStrDup(&avatar);
else if (!strcmp(r.key, "discriminator")) r.NextStrDup(&discriminator);
}
}
if (nonce)
{
@ -173,9 +208,8 @@ static void Discord_UpdateConnection(void)
if (evtName && !strcmp(evtName, "ERROR"))
{
JsonValue *data = GetObjMember(&message, "data");
LastErrorCode = GetIntMember(data, "code");
StringCopy(LastErrorMessage, GetStrMember(data, "message", ""));
LastErrorCode = error_code;
StringCopy(LastErrorMessage, error_message);
GotErrorMessage.store(true);
}
}
@ -185,11 +219,8 @@ static void Discord_UpdateConnection(void)
if (!evtName)
continue;
JsonValue *data = GetObjMember(&message, "data");
if (!strcmp(evtName, "ACTIVITY_JOIN"))
{
const char *secret = GetStrMember(data, "secret");
if (secret)
{
StringCopy(JoinGameSecret, secret);
@ -198,7 +229,6 @@ static void Discord_UpdateConnection(void)
}
else if (!strcmp(evtName, "ACTIVITY_SPECTATE"))
{
const char *secret = GetStrMember(data, "secret");
if (secret)
{
StringCopy(SpectateGameSecret, secret);
@ -207,18 +237,12 @@ static void Discord_UpdateConnection(void)
}
else if (!strcmp(evtName, "ACTIVITY_JOIN_REQUEST"))
{
JsonValue *user = GetObjMember(data, "user");
const char *userId = GetStrMember(user, "id");
const char *username = GetStrMember(user, "username");
const char *avatar = GetStrMember(user, "avatar");
auto joinReq = JoinAskQueue.GetNextAddMessage();
if (userId && username && joinReq)
{
StringCopy(joinReq->userId, userId);
StringCopy(joinReq->username, username);
const char *discriminator = GetStrMember(user,
"discriminator");
if (discriminator)
StringCopy(joinReq->discriminator, discriminator);
if (avatar)
@ -229,6 +253,15 @@ static void Discord_UpdateConnection(void)
}
}
}
if (evtName ) free(evtName );
if (nonce ) free(nonce );
if (secret ) free(secret );
if (userId ) free(userId );
if (username ) free(username );
if (avatar ) free(avatar );
if (discriminator) free(discriminator);
if (error_message) free(error_message);
}
/* writes */
@ -325,16 +358,36 @@ extern "C" void Discord_Initialize(
Connection->onConnect = [](JsonDocument& readyMessage)
{
Discord_UpdateHandlers(&QueuedHandlers);
JsonValue *data = GetObjMember(&readyMessage, "data");
JsonValue *user = GetObjMember(data, "user");
const char *userId = GetStrMember(user, "id");
const char *username = GetStrMember(user, "username");
const char *avatar = GetStrMember(user, "avatar");
char *userId = NULL;
char *username = NULL;
char *avatar = NULL;
char *discriminator = NULL;
bool in_data = false, in_user = false;
for (JsonReader r(readyMessage); r.NextKey();)
{
if (r.depth == 1)
{
in_data = !strcmp(r.key,"data");
in_user = false;
}
else if (r.depth == 2 && in_data)
{
in_user = !strcmp(r.key, "user");
}
else if (r.depth == 3 && in_user)
{
if (!strcmp(r.key, "id" )) r.NextStrDup(&userId);
else if (!strcmp(r.key, "username" )) r.NextStrDup(&username);
else if (!strcmp(r.key, "avatar" )) r.NextStrDup(&avatar);
else if (!strcmp(r.key, "discriminator")) r.NextStrDup(&discriminator);
}
}
if (userId && username)
{
StringCopy(connectedUser.userId, userId);
StringCopy(connectedUser.username, username);
const char *discriminator = GetStrMember(user, "discriminator");
if (discriminator)
StringCopy(connectedUser.discriminator, discriminator);
if (avatar)
@ -344,6 +397,11 @@ extern "C" void Discord_Initialize(
}
WasJustConnected.exchange(true);
ReconnectTimeMs.reset();
if (userId ) free(userId );
if (username ) free(username );
if (avatar ) free(avatar );
if (discriminator) free(discriminator);
};
Connection->onDisconnect = [](int err, const char* message)
{

View File

@ -37,11 +37,18 @@ void RpcConnection::Open()
JsonDocument message;
if (Read(message))
{
const char *cmd = GetStrMember(&message, "cmd");
const char *evt = GetStrMember(&message, "evt");
if (cmd && evt
&& !strcmp(cmd, "DISPATCH")
&& !strcmp(evt, "READY"))
bool cmdDispatch = false;
bool evtReady = false;
for (JsonReader r(message); r.NextKey();)
{
if (r.depth == 1 && !strcmp(r.key, "cmd"))
cmdDispatch = !strcmp(r.NextString(""), "DISPATCH");
else if (r.depth == 1 && !strcmp(r.key, "evt"))
evtReady = !strcmp(r.NextString(""), "READY");
}
if (cmdDispatch && evtReady)
{
state = State::Connected;
if (onConnect)
@ -124,8 +131,15 @@ bool RpcConnection::Read(JsonDocument& message)
{
case Opcode::Close:
message.ParseInsitu(readFrame.message);
lastErrorCode = GetIntMember(&message, "code");
StringCopy(lastErrorMessage, GetStrMember(&message, "message", ""));
lastErrorCode = 0;
lastErrorMessage[0] = '\0';
for (JsonReader r(message); r.NextKey();)
{
if (r.depth == 1 && !strcmp(r.key, "code"))
r.NextInt(&lastErrorCode);
else if (r.depth == 1 && !strcmp(r.key, "message"))
StringCopy(lastErrorMessage, r.NextString(""));
}
Close();
return false;
case Opcode::Frame:

View File

@ -32,13 +32,6 @@ void NumberToString(char* dest, T number)
*dest = 0;
}
// it's ever so slightly faster to not have to strlen the key
template <typename T>
void WriteKey(JsonWriter& w, T& k)
{
w.Key(k, sizeof(T) - 1);
}
struct WriteObject {
JsonWriter& writer;
WriteObject(JsonWriter& w)
@ -46,11 +39,10 @@ struct WriteObject {
{
writer.StartObject();
}
template <typename T>
WriteObject(JsonWriter& w, T& name)
WriteObject(JsonWriter& w, const char* name)
: writer(w)
{
WriteKey(writer, name);
writer.Key(name);
writer.StartObject();
}
~WriteObject() { writer.EndObject(); }
@ -58,22 +50,20 @@ struct WriteObject {
struct WriteArray {
JsonWriter& writer;
template <typename T>
WriteArray(JsonWriter& w, T& name)
WriteArray(JsonWriter& w, const char* name)
: writer(w)
{
WriteKey(writer, name);
writer.Key(name);
writer.StartArray();
}
~WriteArray() { writer.EndArray(); }
};
template <typename T>
void WriteOptionalString(JsonWriter& w, T& k, const char* value)
void WriteOptionalString(JsonWriter& w, const char* k, const char* value)
{
if (value && value[0])
{
w.Key(k, sizeof(T) - 1);
w.Key(k);
w.String(value);
}
}
@ -81,7 +71,7 @@ void WriteOptionalString(JsonWriter& w, T& k, const char* value)
static void JsonWriteNonce(JsonWriter& writer, int nonce)
{
char nonceBuffer[32];
WriteKey(writer, "nonce");
writer.Key("nonce");
NumberToString(nonceBuffer, nonce);
writer.String(nonceBuffer);
}
@ -99,13 +89,13 @@ size_t JsonWriteRichPresenceObj(char* dest,
JsonWriteNonce(writer, nonce);
WriteKey(writer, "cmd");
writer.Key("cmd");
writer.String("SET_ACTIVITY");
{
WriteObject args(writer, "args");
WriteKey(writer, "pid");
writer.Key("pid");
writer.Int(pid);
if (presence)
@ -121,13 +111,13 @@ size_t JsonWriteRichPresenceObj(char* dest,
if (presence->startTimestamp)
{
WriteKey(writer, "start");
writer.Key("start");
writer.Int64(presence->startTimestamp);
}
if (presence->endTimestamp)
{
WriteKey(writer, "end");
writer.Key("end");
writer.Int64(presence->endTimestamp);
}
}
@ -183,9 +173,9 @@ size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char*
{
WriteObject obj(writer);
WriteKey(writer, "v");
writer.Key("v");
writer.Int(version);
WriteKey(writer, "client_id");
writer.Key("client_id");
writer.String(applicationId);
}
@ -201,10 +191,10 @@ size_t JsonWriteSubscribeCommand(char* dest, size_t maxLen, int nonce, const cha
JsonWriteNonce(writer, nonce);
WriteKey(writer, "cmd");
writer.Key("cmd");
writer.String("SUBSCRIBE");
WriteKey(writer, "evt");
writer.Key("evt");
writer.String(evtName);
}
@ -220,10 +210,10 @@ size_t JsonWriteUnsubscribeCommand(char* dest, size_t maxLen, int nonce, const c
JsonWriteNonce(writer, nonce);
WriteKey(writer, "cmd");
writer.Key("cmd");
writer.String("UNSUBSCRIBE");
WriteKey(writer, "evt");
writer.Key("evt");
writer.String(evtName);
}
@ -237,17 +227,17 @@ size_t JsonWriteJoinReply(char* dest, size_t maxLen, const char* userId, int rep
{
WriteObject obj(writer);
WriteKey(writer, "cmd");
writer.Key("cmd");
if (reply == DISCORD_REPLY_YES)
writer.String("SEND_ACTIVITY_JOIN_INVITE");
else
writer.String("CLOSE_ACTIVITY_JOIN_REQUEST");
WriteKey(writer, "args");
writer.Key("args");
{
WriteObject args(writer);
WriteKey(writer, "user_id");
writer.Key("user_id");
writer.String(userId);
}

View File

@ -1,25 +1,16 @@
#pragma once
#include <stdint.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4061) /* enum is not explicitly handled by a case label */
#pragma warning(disable : 4365) /* signed/unsigned mismatch */
#pragma warning(disable : 4464) /* relative include path contains */
#pragma warning(disable : 4668) /* is not defined as a preprocessor macro */
#pragma warning(disable : 6313) /* Incorrect operator */
#endif /* _MSC_VER */
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#ifdef _MSC_VER
#pragma warning(pop)
/* avoid deprecated warning about strdup */
#define _CRT_NONSTDC_NO_DEPRECATE
#endif /* _MSC_VER */
#include <stdint.h>
#include <string.h> /* memcpy/strlen/strcmp/strdup */
#include <stdlib.h> /* malloc/realloc/free */
#include <formats/rjson.h>
/* if only there was a standard library function for this */
template <size_t Len>
inline size_t StringCopy(char (&dest)[Len], const char* src)
@ -50,156 +41,208 @@ size_t JsonWriteUnsubscribeCommand(char* dest, size_t maxLen, int nonce, const c
size_t JsonWriteJoinReply(char* dest, size_t maxLen, const char* userId, int reply, int nonce);
/* I want to use as few allocations as I can get away with, and to do that with RapidJson, you need
* to supply some of your own allocators for stuff rather than use the defaults
*/
class LinearAllocator
class JsonWriter
{
char* buf;
size_t buf_len;
size_t buf_cap;
rjsonwriter_t* writer;
bool need_comma;
static int writer_io(const void* inbuf, int inlen, void *user_data)
{
JsonWriter* self = (JsonWriter*)user_data;
size_t buf_remain = (self->buf_cap - self->buf_len);
if ((size_t)inlen > buf_remain) inlen = (int)buf_remain;
memcpy(self->buf + self->buf_len, inbuf, inlen);
self->buf_len += inlen;
self->buf[self->buf_len - (self->buf_len == self->buf_cap ? 1 : 0)] = '\0';
return inlen;
}
public:
char* buffer_;
char* end_;
LinearAllocator() { }
LinearAllocator(char* buffer, size_t size)
: buffer_(buffer)
, end_(buffer + size) { }
static const bool kNeedFree = false;
void* Malloc(size_t size)
{
char* res = buffer_;
buffer_ += size;
if (buffer_ > end_)
{
buffer_ = res;
return nullptr;
}
return res;
}
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize)
{
if (newSize == 0)
return nullptr;
return Malloc(newSize);
}
static void Free(void* ptr)
{
/* shrug */
(void)ptr;
}
};
template <size_t Size>
class FixedLinearAllocator : public LinearAllocator {
public:
char fixedBuffer_[Size];
FixedLinearAllocator()
: LinearAllocator(fixedBuffer_, Size) { }
static const bool kNeedFree = false;
};
/* wonder why this isn't a thing already, maybe I missed it */
class DirectStringBuffer {
public:
using Ch = char;
char* buffer_;
char* end_;
char* current_;
DirectStringBuffer(char* buffer, size_t maxLen)
: buffer_(buffer)
, end_(buffer + maxLen)
, current_(buffer) { }
void Put(char c)
{
if (current_ < end_)
*current_++ = c;
}
void Flush() {}
size_t GetSize() const { return (size_t)(current_ - buffer_); }
};
using MallocAllocator = rapidjson::CrtAllocator;
using PoolAllocator = rapidjson::MemoryPoolAllocator<MallocAllocator>;
using UTF8 = rapidjson::UTF8<char>;
/* Writer appears to need about 16 bytes per nested object level (with 64bit size_t) */
using StackAllocator = FixedLinearAllocator<2048>;
constexpr size_t WriterNestingLevels = 2048 / (2 * sizeof(size_t));
using JsonWriterBase =
rapidjson::Writer<DirectStringBuffer, UTF8, UTF8, StackAllocator, rapidjson::kWriteNoFlags>;
class JsonWriter : public JsonWriterBase
{
public:
DirectStringBuffer stringBuffer_;
StackAllocator stackAlloc_;
JsonWriter(char* dest, size_t maxLen)
: JsonWriterBase(stringBuffer_, &stackAlloc_, WriterNestingLevels)
, stringBuffer_(dest, maxLen)
, stackAlloc_()
{
}
: buf(dest), buf_len(0), buf_cap(maxLen),
need_comma(false)
{
writer = rjsonwriter_open_user(writer_io, this);
}
size_t Size() const { return stringBuffer_.GetSize(); }
~JsonWriter()
{
rjsonwriter_free(writer);
}
size_t Size()
{
rjsonwriter_flush(writer);
return buf_len;
}
void WriteComma()
{
if (!need_comma) return;
rjsonwriter_add_comma(writer);
need_comma = false;
}
void StartObject()
{
WriteComma();
rjsonwriter_add_start_object(writer);
}
void StartArray()
{
WriteComma();
rjsonwriter_add_start_array(writer);
}
void EndObject()
{
rjsonwriter_add_end_object(writer);
need_comma = true;
}
void EndArray()
{
rjsonwriter_add_end_array(writer);
need_comma = true;
}
void Key(const char* key)
{
WriteComma();
rjsonwriter_add_string(writer, key);
rjsonwriter_add_colon(writer);
}
void String(const char* val)
{
WriteComma();
rjsonwriter_add_string(writer, val);
need_comma = true;
}
void Int(int val)
{
WriteComma();
rjsonwriter_add_int(writer, val);
need_comma = true;
}
void Int64(int64_t val)
{
WriteComma();
char num[24], *pEnd = num + 24, *p = pEnd;
if (!val)
{
*(--p) = '0';
}
else if (val < 0)
{
for (; val; val /= 10)
*(--p) = '0' - (char)(val % 10);
*(--p) = '-';
}
else
{
for (; val; val /= 10)
*(--p) = '0' + (char)(val % 10);
}
rjsonwriter_raw(writer, p, (int)(pEnd - p));
need_comma = true;
}
void Bool(bool val)
{
WriteComma();
rjsonwriter_add_bool(writer, val);
need_comma = true;
}
};
using JsonDocumentBase = rapidjson::GenericDocument<UTF8, PoolAllocator, StackAllocator>;
class JsonDocument : public JsonDocumentBase
class JsonDocument
{
size_t json_cap;
enum { kDefaultChunkCapacity = 32 * 1024 };
public:
static const int kDefaultChunkCapacity = 32 * 1024;
/* json parser will use this buffer first, then allocate more if needed; I seriously doubt we
* send any messages that would use all of this, though. */
char parseBuffer_[32 * 1024];
MallocAllocator mallocAllocator_;
PoolAllocator poolAllocator_;
StackAllocator stackAllocator_;
size_t json_length;
char* json_data;
JsonDocument()
: JsonDocumentBase(rapidjson::kObjectType,
&poolAllocator_,
sizeof(stackAllocator_.fixedBuffer_),
&stackAllocator_)
, poolAllocator_(parseBuffer_, sizeof(parseBuffer_), kDefaultChunkCapacity, &mallocAllocator_)
, stackAllocator_()
{
}
: json_cap(kDefaultChunkCapacity), json_length(0),
json_data((char*)malloc(kDefaultChunkCapacity))
{ }
~JsonDocument()
{
free(json_data);
}
void ParseInsitu(const char* input)
{
size_t input_len = strlen(input);
while (json_length + input_len >= json_cap)
{
json_cap += kDefaultChunkCapacity;
json_data = (char*)realloc(json_data, json_cap);
}
memcpy(json_data + json_length, input, input_len);
json_length += input_len;
json_data[json_length] = '\0';
}
};
using JsonValue = rapidjson::GenericValue<UTF8, PoolAllocator>;
inline JsonValue* GetObjMember(JsonValue* obj, const char* name)
class JsonReader
{
if (obj)
{
auto member = obj->FindMember(name);
if (member != obj->MemberEnd() && member->value.IsObject())
return &member->value;
}
return nullptr;
}
rjson_t* reader;
inline int GetIntMember(JsonValue* obj,
const char* name,
int notFoundDefault = 0)
{
if (obj)
{
auto member = obj->FindMember(name);
if (member != obj->MemberEnd() && member->value.IsInt())
return member->value.GetInt();
}
return notFoundDefault;
}
public:
const char* key;
unsigned int depth;
inline const char* GetStrMember(JsonValue* obj,
const char* name,
const char* notFoundDefault = nullptr)
{
if (obj)
{
auto member = obj->FindMember(name);
if (member != obj->MemberEnd() && member->value.IsString())
return member->value.GetString();
}
return notFoundDefault;
}
JsonReader(JsonDocument& doc)
: reader(rjson_open_buffer(doc.json_data, doc.json_length))
{ }
~JsonReader()
{
rjson_free(reader);
}
bool NextKey()
{
for (;;)
{
enum rjson_type json_type = rjson_next(reader);
if (json_type == RJSON_DONE || json_type == RJSON_ERROR) return false;
if (json_type != RJSON_STRING) continue;
if (rjson_get_context_type(reader) != RJSON_OBJECT) continue;
if ((rjson_get_context_count(reader) & 1) != 1) continue;
depth = rjson_get_context_depth(reader);
key = rjson_get_string(reader, NULL);
return true;
}
}
const char* NextString(const char* default_val)
{
return (rjson_next(reader) != RJSON_STRING ? default_val :
rjson_get_string(reader, NULL));
}
void NextStrDup(char** val)
{
if (rjson_next(reader) == RJSON_STRING)
*val = strdup(rjson_get_string(reader, NULL));
}
void NextInt(int* val)
{
if (rjson_next(reader) == RJSON_NUMBER)
*val = rjson_get_int(reader);
}
};

View File

@ -1,22 +0,0 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.cpp text
*.h text
*.txt text
*.md text
*.cmake text
*.svg text
*.dot text
*.yml text
*.in text
*.sh text
*.autopkg text
Dockerfile text
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.json binary

View File

@ -1,25 +0,0 @@
/bin/*
!/bin/data
!/bin/encodings
!/bin/jsonchecker
!/bin/types
/build
/doc/html
/doc/doxygen_*.db
*.a
# Temporary files created during CMake build
CMakeCache.txt
CMakeFiles
cmake_install.cmake
CTestTestfile.cmake
Makefile
RapidJSON*.cmake
RapidJSON.pc
Testing
/googletest
install_manifest.txt
Doxyfile
Doxyfile.zh-cn
DartConfiguration.tcl
*.nupkg

View File

@ -1,3 +0,0 @@
[submodule "thirdparty/gtest"]
path = thirdparty/gtest
url = https://github.com/google/googletest.git

View File

@ -1,98 +0,0 @@
sudo: required
dist: precise
language: cpp
cache:
- ccache
env:
global:
- USE_CCACHE=1
- CCACHE_SLOPPINESS=pch_defines,time_macros
- CCACHE_COMPRESS=1
- CCACHE_MAXSIZE=100M
- ARCH_FLAGS_x86='-m32' # #266: don't use SSE on 32-bit
- ARCH_FLAGS_x86_64='-msse4.2' # use SSE4.2 on 64-bit
- GITHUB_REPO='miloyip/rapidjson'
- secure: "HrsaCb+N66EG1HR+LWH1u51SjaJyRwJEDzqJGYMB7LJ/bfqb9mWKF1fLvZGk46W5t7TVaXRDD5KHFx9DPWvKn4gRUVkwTHEy262ah5ORh8M6n/6VVVajeV/AYt2C0sswdkDBDO4Xq+xy5gdw3G8s1A4Inbm73pUh+6vx+7ltBbk="
before_install:
- sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install -y cmake valgrind g++-multilib libc6-dbg:i386
matrix:
include:
# gcc
- env: CONF=release ARCH=x86 CXX11=ON
compiler: gcc
- env: CONF=release ARCH=x86_64 CXX11=ON
compiler: gcc
- env: CONF=debug ARCH=x86 CXX11=OFF
compiler: gcc
- env: CONF=debug ARCH=x86_64 CXX11=OFF
compiler: gcc
# clang
- env: CONF=debug ARCH=x86 CXX11=ON CCACHE_CPP2=yes
compiler: clang
- env: CONF=debug ARCH=x86_64 CXX11=ON CCACHE_CPP2=yes
compiler: clang
- env: CONF=debug ARCH=x86 CXX11=OFF CCACHE_CPP2=yes
compiler: clang
- env: CONF=debug ARCH=x86_64 CXX11=OFF CCACHE_CPP2=yes
compiler: clang
- env: CONF=release ARCH=x86 CXX11=ON CCACHE_CPP2=yes
compiler: clang
- env: CONF=release ARCH=x86_64 CXX11=ON CCACHE_CPP2=yes
compiler: clang
# coverage report
- env: CONF=debug ARCH=x86 CXX11=ON GCOV_FLAGS='--coverage'
compiler: gcc
cache:
- ccache
- pip
after_success:
- pip install --user cpp-coveralls
- coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h
- env: CONF=debug ARCH=x86_64 GCOV_FLAGS='--coverage'
compiler: gcc
cache:
- ccache
- pip
after_success:
- pip install --user cpp-coveralls
- coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h
- script: # Documentation task
- cd build
- cmake .. -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON
- make travis_doc
cache: false
addons:
apt:
packages:
- doxygen
before_script:
- ccache -s
# hack to avoid Valgrind bug (https://bugs.kde.org/show_bug.cgi?id=326469),
# exposed by merging PR#163 (using -march=native)
# TODO: Since this bug is already fixed. Remove this when valgrind can be upgraded.
- sed -i "s/-march=native//" CMakeLists.txt
- mkdir build
script:
- if [ "$CXX" = "clang++" ]; then export CXXFLAGS="-stdlib=libc++ ${CXXFLAGS}"; fi
- >
eval "ARCH_FLAGS=\${ARCH_FLAGS_${ARCH}}" ;
(cd build && cmake
-DRAPIDJSON_HAS_STDSTRING=ON
-DRAPIDJSON_BUILD_CXX11=$CXX11
-DCMAKE_VERBOSE_MAKEFILE=ON
-DCMAKE_BUILD_TYPE=$CONF
-DCMAKE_CXX_FLAGS="$ARCH_FLAGS $GCOV_FLAGS"
-DCMAKE_EXE_LINKER_FLAGS=$GCOV_FLAGS
..)
- cd build
- make tests -j 2
- make examples -j 2
- ctest -j 2 -V `[ "$CONF" = "release" ] || echo "-E perftest"`

View File

@ -1,158 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## 1.1.0 - 2016-08-25
### Added
* Add GenericDocument ctor overload to specify JSON type (#369)
* Add FAQ (#372, #373, #374, #376)
* Add forward declaration header `fwd.h`
* Add @PlatformIO Library Registry manifest file (#400)
* Implement assignment operator for BigInteger (#404)
* Add comments support (#443)
* Adding coapp definition (#460)
* documenttest.cpp: EXPECT_THROW when checking empty allocator (470)
* GenericDocument: add implicit conversion to ParseResult (#480)
* Use <wchar.h> with C++ linkage on Windows ARM (#485)
* Detect little endian for Microsoft ARM targets
* Check Nan/Inf when writing a double (#510)
* Add JSON Schema Implementation (#522)
* Add iostream wrapper (#530)
* Add Jsonx example for converting JSON into JSONx (a XML format) (#531)
* Add optional unresolvedTokenIndex parameter to Pointer::Get() (#532)
* Add encoding validation option for Writer/PrettyWriter (#534)
* Add Writer::SetMaxDecimalPlaces() (#536)
* Support {0, } and {0, m} in Regex (#539)
* Add Value::Get/SetFloat(), Value::IsLossLessFloat/Double() (#540)
* Add stream position check to reader unit tests (#541)
* Add Templated accessors and range-based for (#542)
* Add (Pretty)Writer::RawValue() (#543)
* Add Document::Parse(std::string), Document::Parse(const char*, size_t length) and related APIs. (#553)
* Add move constructor for GenericSchemaDocument (#554)
* Add VS2010 and VS2015 to AppVeyor CI (#555)
* Add parse-by-parts example (#556, #562)
* Support parse number as string (#564, #589)
* Add kFormatSingleLineArray for PrettyWriter (#577)
* Added optional support for trailing commas (#584)
* Added filterkey and filterkeydom examples (#615)
* Added npm docs (#639)
* Allow options for writing and parsing NaN/Infinity (#641)
* Add std::string overload to PrettyWriter::Key() when RAPIDJSON_HAS_STDSTRING is defined (#698)
### Fixed
* Fix gcc/clang/vc warnings (#350, #394, #397, #444, #447, #473, #515, #582, #589, #595, #667)
* Fix documentation (#482, #511, #550, #557, #614, #635, #660)
* Fix emscripten alignment issue (#535)
* Fix missing allocator to uses of AddMember in document (#365)
* CMake will no longer complain that the minimum CMake version is not specified (#501)
* Make it usable with old VC8 (VS2005) (#383)
* Prohibit C++11 move from Document to Value (#391)
* Try to fix incorrect 64-bit alignment (#419)
* Check return of fwrite to avoid warn_unused_result build failures (#421)
* Fix UB in GenericDocument::ParseStream (#426)
* Keep Document value unchanged on parse error (#439)
* Add missing return statement (#450)
* Fix Document::Parse(const Ch*) for transcoding (#478)
* encodings.h: fix typo in preprocessor condition (#495)
* Custom Microsoft headers are necessary only for Visual Studio 2012 and lower (#559)
* Fix memory leak for invalid regex (26e69ffde95ba4773ab06db6457b78f308716f4b)
* Fix a bug in schema minimum/maximum keywords for 64-bit integer (e7149d665941068ccf8c565e77495521331cf390)
* Fix a crash bug in regex (#605)
* Fix schema "required" keyword cannot handle duplicated keys (#609)
* Fix cmake CMP0054 warning (#612)
* Added missing include guards in istreamwrapper.h and ostreamwrapper.h (#634)
* Fix undefined behaviour (#646)
* Fix buffer overrun using PutN (#673)
* Fix rapidjson::value::Get<std::string>() may returns wrong data (#681)
* Add Flush() for all value types (#689)
* Handle malloc() fail in PoolAllocator (#691)
* Fix builds on x32 platform. #703
### Changed
* Clarify problematic JSON license (#392)
* Move Travis to container based infrastructure (#504, #558)
* Make whitespace array more compact (#513)
* Optimize Writer::WriteString() with SIMD (#544)
* x86-64 48-bit pointer optimization for GenericValue (#546)
* Define RAPIDJSON_HAS_CXX11_RVALUE_REFS directly in clang (#617)
* Make GenericSchemaDocument constructor explicit (#674)
* Optimize FindMember when use std::string (#690)
## [1.0.2] - 2015-05-14
### Added
* Add Value::XXXMember(...) overloads for std::string (#335)
### Fixed
* Include rapidjson.h for all internal/error headers.
* Parsing some numbers incorrectly in full-precision mode (`kFullPrecisionParseFlag`) (#342)
* Fix some numbers parsed incorrectly (#336)
* Fix alignment of 64bit platforms (#328)
* Fix MemoryPoolAllocator::Clear() to clear user-buffer (0691502573f1afd3341073dd24b12c3db20fbde4)
### Changed
* CMakeLists for include as a thirdparty in projects (#334, #337)
* Change Document::ParseStream() to use stack allocator for Reader (ffbe38614732af8e0b3abdc8b50071f386a4a685)
## [1.0.1] - 2015-04-25
### Added
* Changelog following [Keep a CHANGELOG](https://github.com/olivierlacan/keep-a-changelog) suggestions.
### Fixed
* Parsing of some numbers (e.g. "1e-00011111111111") causing assertion (#314).
* Visual C++ 32-bit compilation error in `diyfp.h` (#317).
## [1.0.0] - 2015-04-22
### Added
* 100% [Coverall](https://coveralls.io/r/miloyip/rapidjson?branch=master) coverage.
* Version macros (#311)
### Fixed
* A bug in trimming long number sequence (4824f12efbf01af72b8cb6fc96fae7b097b73015).
* Double quote in unicode escape (#288).
* Negative zero roundtrip (double only) (#289).
* Standardize behavior of `memcpy()` and `malloc()` (0c5c1538dcfc7f160e5a4aa208ddf092c787be5a, #305, 0e8bbe5e3ef375e7f052f556878be0bd79e9062d).
### Removed
* Remove an invalid `Document::ParseInsitu()` API (e7f1c6dd08b522cfcf9aed58a333bd9a0c0ccbeb).
## 1.0-beta - 2015-04-8
### Added
* RFC 7159 (#101)
* Optional Iterative Parser (#76)
* Deep-copy values (#20)
* Error code and message (#27)
* ASCII Encoding (#70)
* `kParseStopWhenDoneFlag` (#83)
* `kParseFullPrecisionFlag` (881c91d696f06b7f302af6d04ec14dd08db66ceb)
* Add `Key()` to handler concept (#134)
* C++11 compatibility and support (#128)
* Optimized number-to-string and vice versa conversions (#137, #80)
* Short-String Optimization (#131)
* Local stream optimization by traits (#32)
* Travis & Appveyor Continuous Integration, with Valgrind verification (#24, #242)
* Redo all documentation (English, Simplified Chinese)
### Changed
* Copyright ownership transfered to THL A29 Limited (a Tencent company).
* Migrating from Premake to CMAKE (#192)
* Resolve all warning reports
### Removed
* Remove other JSON libraries for performance comparison (#180)
## 0.11 - 2012-11-16
## 0.1 - 2011-11-18
[Unreleased]: https://github.com/miloyip/rapidjson/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/miloyip/rapidjson/compare/v1.0.2...v1.1.0
[1.0.2]: https://github.com/miloyip/rapidjson/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/miloyip/rapidjson/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/miloyip/rapidjson/compare/v1.0-beta...v1.0.0

View File

@ -1,173 +0,0 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
if(POLICY CMP0025)
# detect Apple's Clang
cmake_policy(SET CMP0025 NEW)
endif()
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
PROJECT(RapidJSON CXX)
set(LIB_MAJOR_VERSION "1")
set(LIB_MINOR_VERSION "1")
set(LIB_PATCH_VERSION "0")
set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}")
# compile in release with debug info mode by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
# Build all binaries in a separate directory
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON)
option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON)
option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON)
option(RAPIDJSON_BUILD_THIRDPARTY_GTEST
"Use gtest installation in `thirdparty/gtest` by default if available" OFF)
option(RAPIDJSON_BUILD_CXX11 "Build rapidjson with C++11 (gcc/clang)" ON)
option(RAPIDJSON_BUILD_ASAN "Build rapidjson with address sanitizer (gcc/clang)" OFF)
option(RAPIDJSON_BUILD_UBSAN "Build rapidjson with undefined behavior sanitizer (gcc/clang)" OFF)
option(RAPIDJSON_HAS_STDSTRING "" OFF)
if(RAPIDJSON_HAS_STDSTRING)
add_definitions(-DRAPIDJSON_HAS_STDSTRING)
endif()
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics")
endif()
endif(CCACHE_FOUND)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror")
if (RAPIDJSON_BUILD_CXX11)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
if (RAPIDJSON_BUILD_ASAN)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.0")
message(FATAL_ERROR "GCC < 4.8 doesn't support the address sanitizer")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
endif()
if (RAPIDJSON_BUILD_UBSAN)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0")
message(FATAL_ERROR "GCC < 4.9 doesn't support the undefined behavior sanitizer")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers")
if (RAPIDJSON_BUILD_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if (RAPIDJSON_BUILD_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
if (RAPIDJSON_BUILD_UBSAN)
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
#add extra search paths for libraries and includes
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation")
IF(UNIX OR CYGWIN)
SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}")
ELSEIF(WIN32)
SET(_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/cmake")
ENDIF()
SET(CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" CACHE PATH "The directory cmake fiels are installed in")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
if(RAPIDJSON_BUILD_DOC)
add_subdirectory(doc)
endif()
add_custom_target(travis_doc)
add_custom_command(TARGET travis_doc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/travis-doxygen.sh)
if(RAPIDJSON_BUILD_EXAMPLES)
add_subdirectory(example)
endif()
if(RAPIDJSON_BUILD_TESTS)
if(MSVC11)
# required for VS2012 due to missing support for variadic templates
add_definitions(-D_VARIADIC_MAX=10)
endif(MSVC11)
add_subdirectory(test)
include(CTest)
endif()
# pkg-config
IF (UNIX OR CYGWIN)
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY)
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION "${LIB_INSTALL_DIR}/pkgconfig"
COMPONENT pkgconfig)
ENDIF()
install(FILES readme.md
DESTINATION "${DOC_INSTALL_DIR}"
COMPONENT doc)
install(DIRECTORY include/rapidjson
DESTINATION "${INCLUDE_INSTALL_DIR}"
COMPONENT dev)
install(DIRECTORY example/
DESTINATION "${DOC_INSTALL_DIR}/examples"
COMPONENT examples
# Following patterns are for excluding the intermediate/object files
# from an install of in-source CMake build.
PATTERN "CMakeFiles" EXCLUDE
PATTERN "Makefile" EXCLUDE
PATTERN "cmake_install.cmake" EXCLUDE)
# Provide config and version files to be used by other applications
# ===============================
export(PACKAGE ${PROJECT_NAME})
# cmake-modules
CONFIGURE_FILE(${PROJECT_NAME}Config.cmake.in
${PROJECT_NAME}Config.cmake
@ONLY)
CONFIGURE_FILE(${PROJECT_NAME}ConfigVersion.cmake.in
${PROJECT_NAME}ConfigVersion.cmake
@ONLY)
INSTALL(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_DIR}"
COMPONENT dev)

View File

@ -1,30 +0,0 @@
SET(GTEST_SEARCH_PATH
"${GTEST_SOURCE_DIR}"
"${CMAKE_CURRENT_LIST_DIR}/../thirdparty/gtest/googletest")
IF(UNIX)
IF(RAPIDJSON_BUILD_THIRDPARTY_GTEST)
LIST(APPEND GTEST_SEARCH_PATH "/usr/src/gtest")
ELSE()
LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest")
ENDIF()
ENDIF()
FIND_PATH(GTEST_SOURCE_DIR
NAMES CMakeLists.txt src/gtest_main.cc
PATHS ${GTEST_SEARCH_PATH})
# Debian installs gtest include directory in /usr/include, thus need to look
# for include directory separately from source directory.
FIND_PATH(GTEST_INCLUDE_DIR
NAMES gtest/gtest.h
PATH_SUFFIXES include
HINTS ${GTEST_SOURCE_DIR}
PATHS ${GTEST_SEARCH_PATH})
INCLUDE(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GTestSrc DEFAULT_MSG
GTEST_SOURCE_DIR
GTEST_INCLUDE_DIR)

View File

@ -1,7 +0,0 @@
includedir=@INCLUDE_INSTALL_DIR@
Name: @PROJECT_NAME@
Description: A fast JSON parser/generator for C++ with both SAX/DOM style API
Version: @LIB_VERSION_STRING@
URL: https://github.com/miloyip/rapidjson
Cflags: -I${includedir}

View File

@ -1,3 +0,0 @@
get_filename_component(RAPIDJSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(RAPIDJSON_INCLUDE_DIRS "@INCLUDE_INSTALL_DIR@")
message(STATUS "RapidJSON found. Headers: ${RAPIDJSON_INCLUDE_DIRS}")

View File

@ -1,10 +0,0 @@
SET(PACKAGE_VERSION "@LIB_VERSION_STRING@")
IF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
SET(PACKAGE_VERSION_EXACT "true")
ENDIF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
IF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
SET(PACKAGE_VERSION_COMPATIBLE "true")
ELSE (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
SET(PACKAGE_VERSION_UNSUITABLE "true")
ENDIF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)

View File

@ -1,41 +0,0 @@
os: Visual Studio 2015 CTP
version: 1.1.0.{build}
configuration:
- Debug
- Release
environment:
matrix:
# - VS_VERSION: 9 2008
# VS_PLATFORM: win32
# - VS_VERSION: 9 2008
# VS_PLATFORM: x64
- VS_VERSION: 10 2010
VS_PLATFORM: win32
- VS_VERSION: 10 2010
VS_PLATFORM: x64
- VS_VERSION: 11 2012
VS_PLATFORM: win32
- VS_VERSION: 11 2012
VS_PLATFORM: x64
- VS_VERSION: 12 2013
VS_PLATFORM: win32
- VS_VERSION: 12 2013
VS_PLATFORM: x64
- VS_VERSION: 14 2015
VS_PLATFORM: win32
- VS_VERSION: 14 2015
VS_PLATFORM: x64
before_build:
- git submodule update --init --recursive
- cmake -H. -BBuild/VS -G "Visual Studio %VS_VERSION%" -DCMAKE_GENERATOR_PLATFORM=%VS_PLATFORM% -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_SHARED_LIBS=true -Wno-dev
build:
project: Build\VS\RapidJSON.sln
parallel: true
verbosity: minimal
test_script:
- cd Build\VS && if %CONFIGURATION%==Debug (ctest --verbose -E perftest --build-config %CONFIGURATION%) else (ctest --verbose --build-config %CONFIGURATION%)

View File

@ -1,22 +0,0 @@
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}

View File

@ -1,27 +0,0 @@
{"menu": {
"header": "SVG Viewer",
"items": [
{"id": "Open"},
{"id": "OpenNew", "label": "Open New"},
null,
{"id": "ZoomIn", "label": "Zoom In"},
{"id": "ZoomOut", "label": "Zoom Out"},
{"id": "OriginalView", "label": "Original View"},
null,
{"id": "Quality"},
{"id": "Pause"},
{"id": "Mute"},
null,
{"id": "Find", "label": "Find..."},
{"id": "FindAgain", "label": "Find Again"},
{"id": "Copy"},
{"id": "CopyAgain", "label": "Copy Again"},
{"id": "CopySVG", "label": "Copy SVG"},
{"id": "ViewSVG", "label": "View SVG"},
{"id": "ViewSource", "label": "View Source"},
{"id": "SaveAs", "label": "Save As"},
null,
{"id": "Help"},
{"id": "About", "label": "About Adobe CVG Viewer..."}
]
}}

View File

@ -1 +0,0 @@
sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip

File diff suppressed because it is too large Load Diff

View File

@ -1,88 +0,0 @@
{"web-app": {
"servlet": [
{
"servlet-name": "cofaxCDS",
"servlet-class": "org.cofax.cds.CDSServlet",
"init-param": {
"configGlossary:installationAt": "Philadelphia, PA",
"configGlossary:adminEmail": "ksm@pobox.com",
"configGlossary:poweredBy": "Cofax",
"configGlossary:poweredByIcon": "/images/cofax.gif",
"configGlossary:staticPath": "/content/static",
"templateProcessorClass": "org.cofax.WysiwygTemplate",
"templateLoaderClass": "org.cofax.FilesTemplateLoader",
"templatePath": "templates",
"templateOverridePath": "",
"defaultListTemplate": "listTemplate.htm",
"defaultFileTemplate": "articleTemplate.htm",
"useJSP": false,
"jspListTemplate": "listTemplate.jsp",
"jspFileTemplate": "articleTemplate.jsp",
"cachePackageTagsTrack": 200,
"cachePackageTagsStore": 200,
"cachePackageTagsRefresh": 60,
"cacheTemplatesTrack": 100,
"cacheTemplatesStore": 50,
"cacheTemplatesRefresh": 15,
"cachePagesTrack": 200,
"cachePagesStore": 100,
"cachePagesRefresh": 10,
"cachePagesDirtyRead": 10,
"searchEngineListTemplate": "forSearchEnginesList.htm",
"searchEngineFileTemplate": "forSearchEngines.htm",
"searchEngineRobotsDb": "WEB-INF/robots.db",
"useDataStore": true,
"dataStoreClass": "org.cofax.SqlDataStore",
"redirectionClass": "org.cofax.SqlRedirection",
"dataStoreName": "cofax",
"dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
"dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
"dataStoreUser": "sa",
"dataStorePassword": "dataStoreTestQuery",
"dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
"dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
"dataStoreInitConns": 10,
"dataStoreMaxConns": 100,
"dataStoreConnUsageLimit": 100,
"dataStoreLogLevel": "debug",
"maxUrlLength": 500}},
{
"servlet-name": "cofaxEmail",
"servlet-class": "org.cofax.cds.EmailServlet",
"init-param": {
"mailHost": "mail1",
"mailHostOverride": "mail2"}},
{
"servlet-name": "cofaxAdmin",
"servlet-class": "org.cofax.cds.AdminServlet"},
{
"servlet-name": "fileServlet",
"servlet-class": "org.cofax.cds.FileServlet"},
{
"servlet-name": "cofaxTools",
"servlet-class": "org.cofax.cms.CofaxToolsServlet",
"init-param": {
"templatePath": "toolstemplates/",
"log": 1,
"logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
"logMaxSize": "",
"dataLog": 1,
"dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
"dataLogMaxSize": "",
"removePageCache": "/content/admin/remove?cache=pages&id=",
"removeTemplateCache": "/content/admin/remove?cache=templates&id=",
"fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
"lookInContext": 1,
"adminGroupID": 4,
"betaServer": true}}],
"servlet-mapping": {
"cofaxCDS": "/",
"cofaxEmail": "/cofaxutil/aemail/*",
"cofaxAdmin": "/admin/*",
"fileServlet": "/static/*",
"cofaxTools": "/tools/*"},
"taglib": {
"taglib-uri": "cofax.tld",
"taglib-location": "/WEB-INF/tlds/cofax.tld"}}}

View File

@ -1,26 +0,0 @@
{"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}

View File

@ -1,150 +0,0 @@
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
}
},
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"$schema": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": { "$ref": "#/definitions/positiveInteger" },
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
"exclusiveMinimum": [ "minimum" ]
},
"default": {}
}

View File

@ -1,7 +0,0 @@
{
"en":"I can eat glass and it doesn't hurt me.",
"zh-Hant":"我能吞下玻璃而不傷身體。",
"zh-Hans":"我能吞下玻璃而不伤身体。",
"ja":"私はガラスを食べられます。それは私を傷つけません。",
"ko":"나는 유리를 먹을 수 있어요. 그래도 아프지 않아요"
}

View File

@ -1,7 +0,0 @@
{
"en":"I can eat glass and it doesn't hurt me.",
"zh-Hant":"我能吞下玻璃而不傷身體。",
"zh-Hans":"我能吞下玻璃而不伤身体。",
"ja":"私はガラスを食べられます。それは私を傷つけません。",
"ko":"나는 유리를 먹을 수 있어요. 그래도 아프지 않아요"
}

View File

@ -1 +0,0 @@
"A JSON payload should be an object or array, not a string."

View File

@ -1 +0,0 @@
{"Extra value after close": true} "misplaced quoted value"

View File

@ -1 +0,0 @@
{"Illegal expression": 1 + 2}

View File

@ -1 +0,0 @@
{"Illegal invocation": alert()}

View File

@ -1 +0,0 @@
{"Numbers cannot have leading zeroes": 013}

View File

@ -1 +0,0 @@
{"Numbers cannot be hex": 0x14}

View File

@ -1 +0,0 @@
["Illegal backslash escape: \x15"]

View File

@ -1 +0,0 @@
["Illegal backslash escape: \017"]

View File

@ -1 +0,0 @@
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]

View File

@ -1 +0,0 @@
{"Missing colon" null}

View File

@ -1 +0,0 @@
["Unclosed array"

View File

@ -1 +0,0 @@
{"Double colon":: null}

View File

@ -1 +0,0 @@
{"Comma instead of colon", null}

View File

@ -1 +0,0 @@
["Colon instead of comma": false]

View File

@ -1 +0,0 @@
["Bad value", truth]

View File

@ -1 +0,0 @@
['single quote']

View File

@ -1 +0,0 @@
[" tab character in string "]

View File

@ -1 +0,0 @@
["tab\ character\ in\ string\ "]

View File

@ -1,2 +0,0 @@
["line
break"]

View File

@ -1,2 +0,0 @@
["line\
break"]

View File

@ -1 +0,0 @@
{unquoted_key: "keys must be quoted"}

View File

@ -1 +0,0 @@
{"Comma instead if closing brace": true,

View File

@ -1 +0,0 @@
["mismatch"}

View File

@ -1 +0,0 @@
["extra comma",]

View File

@ -1 +0,0 @@
["double extra comma",,]

View File

@ -1 +0,0 @@
[ , "<-- missing value"]

View File

@ -1 +0,0 @@
["Comma after the close"],

View File

@ -1 +0,0 @@
["Extra close"]]

View File

@ -1 +0,0 @@
{"Extra comma": true,}

View File

@ -1,58 +0,0 @@
[
"JSON Test Pattern pass1",
{"object with 1 member":["array with 1 element"]},
{},
[],
-42,
true,
false,
null,
{
"integer": 1234567890,
"real": -9876.543210,
"e": 0.123456789e-12,
"E": 1.234567890E+34,
"": 23456789012E66,
"zero": 0,
"one": 1,
"space": " ",
"quote": "\"",
"backslash": "\\",
"controls": "\b\f\n\r\t",
"slash": "/ & \/",
"alpha": "abcdefghijklmnopqrstuvwyz",
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
"digit": "0123456789",
"0123456789": "digit",
"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
"true": true,
"false": false,
"null": null,
"array":[ ],
"object":{ },
"address": "50 St. James Street",
"url": "http://www.JSON.org/",
"comment": "// /* <!-- --",
"# -- --> */": " ",
" s p a c e d " :[1,2 , 3
,
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
"quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
: "A key can be any string"
},
0.5 ,98.6
,
99.44
,
1066,
1e1,
0.1e1,
1e-1,
1e00,2e+00,2e-00
,"rosebud"]

View File

@ -1 +0,0 @@
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]

View File

@ -1,6 +0,0 @@
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}

View File

@ -1,3 +0,0 @@
Test suite from http://json.org/JSON_checker/.
If the JSON_checker is working correctly, it must accept all of the pass*.json files and reject all of the fail*.json files.

View File

@ -1,4 +0,0 @@
language: python
python: "2.7"
install: pip install jsonschema
script: bin/jsonschema_suite check

View File

@ -1,19 +0,0 @@
Copyright (c) 2012 Julian Berman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,148 +0,0 @@
JSON Schema Test Suite [![Build Status](https://travis-ci.org/json-schema/JSON-Schema-Test-Suite.png?branch=develop)](https://travis-ci.org/json-schema/JSON-Schema-Test-Suite)
======================
This repository contains a set of JSON objects that implementors of JSON Schema
validation libraries can use to test their validators.
It is meant to be language agnostic and should require only a JSON parser.
The conversion of the JSON objects into tests within your test framework of
choice is still the job of the validator implementor.
Structure of a Test
-------------------
If you're going to use this suite, you need to know how tests are laid out. The
tests are contained in the `tests` directory at the root of this repository.
Inside that directory is a subdirectory for each draft or version of the
schema. We'll use `draft3` as an example.
If you look inside the draft directory, there are a number of `.json` files,
which logically group a set of test cases together. Often the grouping is by
property under test, but not always, especially within optional test files
(discussed below).
Inside each `.json` file is a single array containing objects. It's easiest to
illustrate the structure of these with an example:
```json
{
"description": "the description of the test case",
"schema": {"the schema that should" : "be validated against"},
"tests": [
{
"description": "a specific test of a valid instance",
"data": "the instance",
"valid": true
},
{
"description": "another specific test this time, invalid",
"data": 15,
"valid": false
}
]
}
```
So a description, a schema, and some tests, where tests is an array containing
one or more objects with descriptions, data, and a boolean indicating whether
they should be valid or invalid.
Coverage
--------
Draft 3 and 4 should have full coverage. If you see anything missing or think
there is a useful test missing, please send a pull request or open an issue.
Who Uses the Test Suite
-----------------------
This suite is being used by:
### Coffeescript ###
* [jsck](https://github.com/pandastrike/jsck)
### Dart ###
* [json_schema](https://github.com/patefacio/json_schema)
### Erlang ###
* [jesse](https://github.com/klarna/jesse)
### Go ###
* [gojsonschema](https://github.com/sigu-399/gojsonschema)
* [validate-json](https://github.com/cesanta/validate-json)
### Haskell ###
* [aeson-schema](https://github.com/timjb/aeson-schema)
* [hjsonschema](https://github.com/seagreen/hjsonschema)
### Java ###
* [json-schema-validator](https://github.com/fge/json-schema-validator)
### JavaScript ###
* [json-schema-benchmark](https://github.com/Muscula/json-schema-benchmark)
* [direct-schema](https://github.com/IreneKnapp/direct-schema)
* [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid)
* [jassi](https://github.com/iclanzan/jassi)
* [JaySchema](https://github.com/natesilva/jayschema)
* [json-schema-valid](https://github.com/ericgj/json-schema-valid)
* [Jsonary](https://github.com/jsonary-js/jsonary)
* [jsonschema](https://github.com/tdegrunt/jsonschema)
* [request-validator](https://github.com/bugventure/request-validator)
* [skeemas](https://github.com/Prestaul/skeemas)
* [tv4](https://github.com/geraintluff/tv4)
* [z-schema](https://github.com/zaggino/z-schema)
* [jsen](https://github.com/bugventure/jsen)
* [ajv](https://github.com/epoberezkin/ajv)
### Node.js ###
The JSON Schema Test Suite is also available as an
[npm](https://www.npmjs.com/package/json-schema-test-suite) package.
Node-specific support is maintained on the [node branch](https://github.com/json-schema/JSON-Schema-Test-Suite/tree/node).
See [NODE-README.md](https://github.com/json-schema/JSON-Schema-Test-Suite/blob/node/NODE-README.md)
for more information.
### .NET ###
* [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema)
### PHP ###
* [json-schema](https://github.com/justinrainbow/json-schema)
### Python ###
* [jsonschema](https://github.com/Julian/jsonschema)
### Ruby ###
* [json-schema](https://github.com/hoxworth/json-schema)
### Rust ###
* [valico](https://github.com/rustless/valico)
### Swift ###
* [JSONSchema](https://github.com/kylef/JSONSchema.swift)
If you use it as well, please fork and send a pull request adding yourself to
the list :).
Contributing
------------
If you see something missing or incorrect, a pull request is most welcome!
There are some sanity checks in place for testing the test suite. You can run
them with `bin/jsonschema_suite check` or `tox`. They will be run automatically by
[Travis CI](https://travis-ci.org/) as well.

View File

@ -1,283 +0,0 @@
#! /usr/bin/env python
from __future__ import print_function
import sys
import textwrap
try:
import argparse
except ImportError:
print(textwrap.dedent("""
The argparse library could not be imported. jsonschema_suite requires
either Python 2.7 or for you to install argparse. You can do so by
running `pip install argparse`, `easy_install argparse` or by
downloading argparse and running `python2.6 setup.py install`.
See https://pypi.python.org/pypi/argparse for details.
""".strip("\n")))
sys.exit(1)
import errno
import fnmatch
import json
import os
import random
import shutil
import unittest
import warnings
if getattr(unittest, "skipIf", None) is None:
unittest.skipIf = lambda cond, msg : lambda fn : fn
try:
import jsonschema
except ImportError:
jsonschema = None
else:
validators = getattr(
jsonschema.validators, "validators", jsonschema.validators
)
ROOT_DIR = os.path.join(
os.path.dirname(__file__), os.pardir).rstrip("__pycache__")
SUITE_ROOT_DIR = os.path.join(ROOT_DIR, "tests")
REMOTES = {
"integer.json": {"type": "integer"},
"subSchemas.json": {
"integer": {"type": "integer"},
"refToInteger": {"$ref": "#/integer"},
},
"folder/folderInteger.json": {"type": "integer"}
}
REMOTES_DIR = os.path.join(ROOT_DIR, "remotes")
TESTSUITE_SCHEMA = {
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"description": {"type": "string", "required": True},
"schema": {"required": True},
"tests": {
"type": "array",
"items": {
"type": "object",
"properties": {
"description": {"type": "string", "required": True},
"data": {"required": True},
"valid": {"type": "boolean", "required": True}
},
"additionalProperties": False
},
"minItems": 1
}
},
"additionalProperties": False,
"minItems": 1
}
}
def files(paths):
for path in paths:
with open(path) as test_file:
yield json.load(test_file)
def groups(paths):
for test_file in files(paths):
for group in test_file:
yield group
def cases(paths):
for test_group in groups(paths):
for test in test_group["tests"]:
test["schema"] = test_group["schema"]
yield test
def collect(root_dir):
for root, dirs, files in os.walk(root_dir):
for filename in fnmatch.filter(files, "*.json"):
yield os.path.join(root, filename)
class SanityTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("Looking for tests in %s" % SUITE_ROOT_DIR)
cls.test_files = list(collect(SUITE_ROOT_DIR))
print("Found %s test files" % len(cls.test_files))
assert cls.test_files, "Didn't find the test files!"
def test_all_files_are_valid_json(self):
for path in self.test_files:
with open(path) as test_file:
try:
json.load(test_file)
except ValueError as error:
self.fail("%s contains invalid JSON (%s)" % (path, error))
def test_all_descriptions_have_reasonable_length(self):
for case in cases(self.test_files):
descript = case["description"]
self.assertLess(
len(descript),
60,
"%r is too long! (keep it to less than 60 chars)" % (descript,)
)
def test_all_descriptions_are_unique(self):
for group in groups(self.test_files):
descriptions = set(test["description"] for test in group["tests"])
self.assertEqual(
len(descriptions),
len(group["tests"]),
"%r contains a duplicate description" % (group,)
)
@unittest.skipIf(jsonschema is None, "Validation library not present!")
def test_all_schemas_are_valid(self):
for schema in os.listdir(SUITE_ROOT_DIR):
schema_validator = validators.get(schema)
if schema_validator is not None:
test_files = collect(os.path.join(SUITE_ROOT_DIR, schema))
for case in cases(test_files):
try:
schema_validator.check_schema(case["schema"])
except jsonschema.SchemaError as error:
self.fail("%s contains an invalid schema (%s)" %
(case, error))
else:
warnings.warn("No schema validator for %s" % schema)
@unittest.skipIf(jsonschema is None, "Validation library not present!")
def test_suites_are_valid(self):
validator = jsonschema.Draft3Validator(TESTSUITE_SCHEMA)
for tests in files(self.test_files):
try:
validator.validate(tests)
except jsonschema.ValidationError as error:
self.fail(str(error))
def test_remote_schemas_are_updated(self):
for url, schema in REMOTES.items():
filepath = os.path.join(REMOTES_DIR, url)
with open(filepath) as schema_file:
self.assertEqual(json.load(schema_file), schema)
def main(arguments):
if arguments.command == "check":
suite = unittest.TestLoader().loadTestsFromTestCase(SanityTests)
result = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(not result.wasSuccessful())
elif arguments.command == "flatten":
selected_cases = [case for case in cases(collect(arguments.version))]
if arguments.randomize:
random.shuffle(selected_cases)
json.dump(selected_cases, sys.stdout, indent=4, sort_keys=True)
elif arguments.command == "remotes":
json.dump(REMOTES, sys.stdout, indent=4, sort_keys=True)
elif arguments.command == "dump_remotes":
if arguments.update:
shutil.rmtree(arguments.out_dir, ignore_errors=True)
try:
os.makedirs(arguments.out_dir)
except OSError as e:
if e.errno == errno.EEXIST:
print("%s already exists. Aborting." % arguments.out_dir)
sys.exit(1)
raise
for url, schema in REMOTES.items():
filepath = os.path.join(arguments.out_dir, url)
try:
os.makedirs(os.path.dirname(filepath))
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(filepath, "wb") as out_file:
json.dump(schema, out_file, indent=4, sort_keys=True)
elif arguments.command == "serve":
try:
from flask import Flask, jsonify
except ImportError:
print(textwrap.dedent("""
The Flask library is required to serve the remote schemas.
You can install it by running `pip install Flask`.
Alternatively, see the `jsonschema_suite remotes` or
`jsonschema_suite dump_remotes` commands to create static files
that can be served with your own web server.
""".strip("\n")))
sys.exit(1)
app = Flask(__name__)
@app.route("/<path:path>")
def serve_path(path):
if path in REMOTES:
return jsonify(REMOTES[path])
return "Document does not exist.", 404
app.run(port=1234)
parser = argparse.ArgumentParser(
description="JSON Schema Test Suite utilities",
)
subparsers = parser.add_subparsers(help="utility commands", dest="command")
check = subparsers.add_parser("check", help="Sanity check the test suite.")
flatten = subparsers.add_parser(
"flatten",
help="Output a flattened file containing a selected version's test cases."
)
flatten.add_argument(
"--randomize",
action="store_true",
help="Randomize the order of the outputted cases.",
)
flatten.add_argument(
"version", help="The directory containing the version to output",
)
remotes = subparsers.add_parser(
"remotes",
help="Output the expected URLs and their associated schemas for remote "
"ref tests as a JSON object."
)
dump_remotes = subparsers.add_parser(
"dump_remotes", help="Dump the remote ref schemas into a file tree",
)
dump_remotes.add_argument(
"--update",
action="store_true",
help="Update the remotes in an existing directory.",
)
dump_remotes.add_argument(
"--out-dir",
default=REMOTES_DIR,
type=os.path.abspath,
help="The output directory to create as the root of the file tree",
)
serve = subparsers.add_parser(
"serve",
help="Start a webserver to serve schemas used by remote ref tests."
)
if __name__ == "__main__":
main(parser.parse_args())

View File

@ -1,3 +0,0 @@
{
"type": "integer"
}

View File

@ -1,8 +0,0 @@
{
"integer": {
"type": "integer"
},
"refToInteger": {
"$ref": "#/integer"
}
}

View File

@ -1,82 +0,0 @@
[
{
"description": "additionalItems as schema",
"schema": {
"items": [],
"additionalItems": {"type": "integer"}
},
"tests": [
{
"description": "additional items match schema",
"data": [ 1, 2, 3, 4 ],
"valid": true
},
{
"description": "additional items do not match schema",
"data": [ 1, 2, 3, "foo" ],
"valid": false
}
]
},
{
"description": "items is schema, no additionalItems",
"schema": {
"items": {},
"additionalItems": false
},
"tests": [
{
"description": "all items match schema",
"data": [ 1, 2, 3, 4, 5 ],
"valid": true
}
]
},
{
"description": "array of items with no additionalItems",
"schema": {
"items": [{}, {}, {}],
"additionalItems": false
},
"tests": [
{
"description": "no additional items present",
"data": [ 1, 2, 3 ],
"valid": true
},
{
"description": "additional items are not permitted",
"data": [ 1, 2, 3, 4 ],
"valid": false
}
]
},
{
"description": "additionalItems as false without items",
"schema": {"additionalItems": false},
"tests": [
{
"description":
"items defaults to empty schema so everything is valid",
"data": [ 1, 2, 3, 4, 5 ],
"valid": true
},
{
"description": "ignores non-arrays",
"data": {"foo" : "bar"},
"valid": true
}
]
},
{
"description": "additionalItems are allowed by default",
"schema": {"items": []},
"tests": [
{
"description": "only the first items are validated",
"data": [1, "foo", false],
"valid": true
}
]
}
]

View File

@ -1,88 +0,0 @@
[
{
"description":
"additionalProperties being false does not allow other properties",
"schema": {
"properties": {"foo": {}, "bar": {}},
"patternProperties": { "^v": {} },
"additionalProperties": false
},
"tests": [
{
"description": "no additional properties is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "an additional property is invalid",
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
"valid": false
},
{
"description": "ignores non-objects",
"data": [1, 2, 3],
"valid": true
},
{
"description": "patternProperties are not additional properties",
"data": {"foo":1, "vroom": 2},
"valid": true
}
]
},
{
"description":
"additionalProperties allows a schema which should validate",
"schema": {
"properties": {"foo": {}, "bar": {}},
"additionalProperties": {"type": "boolean"}
},
"tests": [
{
"description": "no additional properties is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "an additional valid property is valid",
"data": {"foo" : 1, "bar" : 2, "quux" : true},
"valid": true
},
{
"description": "an additional invalid property is invalid",
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
"valid": false
}
]
},
{
"description":
"additionalProperties can exist by itself",
"schema": {
"additionalProperties": {"type": "boolean"}
},
"tests": [
{
"description": "an additional valid property is valid",
"data": {"foo" : true},
"valid": true
},
{
"description": "an additional invalid property is invalid",
"data": {"foo" : 1},
"valid": false
}
]
},
{
"description": "additionalProperties are allowed by default",
"schema": {"properties": {"foo": {}, "bar": {}}},
"tests": [
{
"description": "additional properties are allowed",
"data": {"foo": 1, "bar": 2, "quux": true},
"valid": true
}
]
}
]

View File

@ -1,49 +0,0 @@
[
{
"description": "invalid type for default",
"schema": {
"properties": {
"foo": {
"type": "integer",
"default": []
}
}
},
"tests": [
{
"description": "valid when property is specified",
"data": {"foo": 13},
"valid": true
},
{
"description": "still valid when the invalid default is used",
"data": {},
"valid": true
}
]
},
{
"description": "invalid string value for default",
"schema": {
"properties": {
"bar": {
"type": "string",
"minLength": 4,
"default": "bad"
}
}
},
"tests": [
{
"description": "valid when property is specified",
"data": {"bar": "good"},
"valid": true
},
{
"description": "still valid when the invalid default is used",
"data": {},
"valid": true
}
]
}
]

View File

@ -1,108 +0,0 @@
[
{
"description": "dependencies",
"schema": {
"dependencies": {"bar": "foo"}
},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependant",
"data": {"foo": 1},
"valid": true
},
{
"description": "with dependency",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "missing dependency",
"data": {"bar": 2},
"valid": false
},
{
"description": "ignores non-objects",
"data": "foo",
"valid": true
}
]
},
{
"description": "multiple dependencies",
"schema": {
"dependencies": {"quux": ["foo", "bar"]}
},
"tests": [
{
"description": "neither",
"data": {},
"valid": true
},
{
"description": "nondependants",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "with dependencies",
"data": {"foo": 1, "bar": 2, "quux": 3},
"valid": true
},
{
"description": "missing dependency",
"data": {"foo": 1, "quux": 2},
"valid": false
},
{
"description": "missing other dependency",
"data": {"bar": 1, "quux": 2},
"valid": false
},
{
"description": "missing both dependencies",
"data": {"quux": 1},
"valid": false
}
]
},
{
"description": "multiple dependencies subschema",
"schema": {
"dependencies": {
"bar": {
"properties": {
"foo": {"type": "integer"},
"bar": {"type": "integer"}
}
}
}
},
"tests": [
{
"description": "valid",
"data": {"foo": 1, "bar": 2},
"valid": true
},
{
"description": "wrong type",
"data": {"foo": "quux", "bar": 2},
"valid": false
},
{
"description": "wrong type other",
"data": {"foo": 2, "bar": "quux"},
"valid": false
},
{
"description": "wrong type both",
"data": {"foo": "quux", "bar": "quux"},
"valid": false
}
]
}
]

View File

@ -1,80 +0,0 @@
[
{
"description": "disallow",
"schema": {
"disallow": "integer"
},
"tests": [
{
"description": "allowed",
"data": "foo",
"valid": true
},
{
"description": "disallowed",
"data": 1,
"valid": false
}
]
},
{
"description": "multiple disallow",
"schema": {
"disallow": ["integer", "boolean"]
},
"tests": [
{
"description": "valid",
"data": "foo",
"valid": true
},
{
"description": "mismatch",
"data": 1,
"valid": false
},
{
"description": "other mismatch",
"data": true,
"valid": false
}
]
},
{
"description": "multiple disallow subschema",
"schema": {
"disallow":
["string",
{
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}]
},
"tests": [
{
"description": "match",
"data": 1,
"valid": true
},
{
"description": "other match",
"data": {"foo": 1},
"valid": true
},
{
"description": "mismatch",
"data": "foo",
"valid": false
},
{
"description": "other mismatch",
"data": {"foo": "bar"},
"valid": false
}
]
}
]

View File

@ -1,60 +0,0 @@
[
{
"description": "by int",
"schema": {"divisibleBy": 2},
"tests": [
{
"description": "int by int",
"data": 10,
"valid": true
},
{
"description": "int by int fail",
"data": 7,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "foo",
"valid": true
}
]
},
{
"description": "by number",
"schema": {"divisibleBy": 1.5},
"tests": [
{
"description": "zero is divisible by anything (except 0)",
"data": 0,
"valid": true
},
{
"description": "4.5 is divisible by 1.5",
"data": 4.5,
"valid": true
},
{
"description": "35 is not divisible by 1.5",
"data": 35,
"valid": false
}
]
},
{
"description": "by small number",
"schema": {"divisibleBy": 0.0001},
"tests": [
{
"description": "0.0075 is divisible by 0.0001",
"data": 0.0075,
"valid": true
},
{
"description": "0.00751 is not divisible by 0.0001",
"data": 0.00751,
"valid": false
}
]
}
]

View File

@ -1,71 +0,0 @@
[
{
"description": "simple enum validation",
"schema": {"enum": [1, 2, 3]},
"tests": [
{
"description": "one of the enum is valid",
"data": 1,
"valid": true
},
{
"description": "something else is invalid",
"data": 4,
"valid": false
}
]
},
{
"description": "heterogeneous enum validation",
"schema": {"enum": [6, "foo", [], true, {"foo": 12}]},
"tests": [
{
"description": "one of the enum is valid",
"data": [],
"valid": true
},
{
"description": "something else is invalid",
"data": null,
"valid": false
},
{
"description": "objects are deep compared",
"data": {"foo": false},
"valid": false
}
]
},
{
"description": "enums in properties",
"schema": {
"type":"object",
"properties": {
"foo": {"enum":["foo"]},
"bar": {"enum":["bar"], "required":true}
}
},
"tests": [
{
"description": "both properties are valid",
"data": {"foo":"foo", "bar":"bar"},
"valid": true
},
{
"description": "missing optional property is valid",
"data": {"bar":"bar"},
"valid": true
},
{
"description": "missing required property is invalid",
"data": {"foo":"foo"},
"valid": false
},
{
"description": "missing all properties is invalid",
"data": {},
"valid": false
}
]
}
]

View File

@ -1,94 +0,0 @@
[
{
"description": "extends",
"schema": {
"properties": {"bar": {"type": "integer", "required": true}},
"extends": {
"properties": {
"foo": {"type": "string", "required": true}
}
}
},
"tests": [
{
"description": "extends",
"data": {"foo": "baz", "bar": 2},
"valid": true
},
{
"description": "mismatch extends",
"data": {"foo": "baz"},
"valid": false
},
{
"description": "mismatch extended",
"data": {"bar": 2},
"valid": false
},
{
"description": "wrong type",
"data": {"foo": "baz", "bar": "quux"},
"valid": false
}
]
},
{
"description": "multiple extends",
"schema": {
"properties": {"bar": {"type": "integer", "required": true}},
"extends" : [
{
"properties": {
"foo": {"type": "string", "required": true}
}
},
{
"properties": {
"baz": {"type": "null", "required": true}
}
}
]
},
"tests": [
{
"description": "valid",
"data": {"foo": "quux", "bar": 2, "baz": null},
"valid": true
},
{
"description": "mismatch first extends",
"data": {"bar": 2, "baz": null},
"valid": false
},
{
"description": "mismatch second extends",
"data": {"foo": "quux", "bar": 2},
"valid": false
},
{
"description": "mismatch both",
"data": {"bar": 2},
"valid": false
}
]
},
{
"description": "extends simple types",
"schema": {
"minimum": 20,
"extends": {"maximum": 30}
},
"tests": [
{
"description": "valid",
"data": 25,
"valid": true
},
{
"description": "mismatch extends",
"data": 35,
"valid": false
}
]
}
]

View File

@ -1,46 +0,0 @@
[
{
"description": "a schema given for items",
"schema": {
"items": {"type": "integer"}
},
"tests": [
{
"description": "valid items",
"data": [ 1, 2, 3 ],
"valid": true
},
{
"description": "wrong type of items",
"data": [1, "x"],
"valid": false
},
{
"description": "ignores non-arrays",
"data": {"foo" : "bar"},
"valid": true
}
]
},
{
"description": "an array of schemas for items",
"schema": {
"items": [
{"type": "integer"},
{"type": "string"}
]
},
"tests": [
{
"description": "correct types",
"data": [ 1, "foo" ],
"valid": true
},
{
"description": "wrong types",
"data": [ "foo", 1 ],
"valid": false
}
]
}
]

View File

@ -1,28 +0,0 @@
[
{
"description": "maxItems validation",
"schema": {"maxItems": 2},
"tests": [
{
"description": "shorter is valid",
"data": [1],
"valid": true
},
{
"description": "exact length is valid",
"data": [1, 2],
"valid": true
},
{
"description": "too long is invalid",
"data": [1, 2, 3],
"valid": false
},
{
"description": "ignores non-arrays",
"data": "foobar",
"valid": true
}
]
}
]

View File

@ -1,33 +0,0 @@
[
{
"description": "maxLength validation",
"schema": {"maxLength": 2},
"tests": [
{
"description": "shorter is valid",
"data": "f",
"valid": true
},
{
"description": "exact length is valid",
"data": "fo",
"valid": true
},
{
"description": "too long is invalid",
"data": "foo",
"valid": false
},
{
"description": "ignores non-strings",
"data": 10,
"valid": true
},
{
"description": "two supplementary Unicode code points is long enough",
"data": "\uD83D\uDCA9\uD83D\uDCA9",
"valid": true
}
]
}
]

View File

@ -1,42 +0,0 @@
[
{
"description": "maximum validation",
"schema": {"maximum": 3.0},
"tests": [
{
"description": "below the maximum is valid",
"data": 2.6,
"valid": true
},
{
"description": "above the maximum is invalid",
"data": 3.5,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
},
{
"description": "exclusiveMaximum validation",
"schema": {
"maximum": 3.0,
"exclusiveMaximum": true
},
"tests": [
{
"description": "below the maximum is still valid",
"data": 2.2,
"valid": true
},
{
"description": "boundary point is invalid",
"data": 3.0,
"valid": false
}
]
}
]

View File

@ -1,28 +0,0 @@
[
{
"description": "minItems validation",
"schema": {"minItems": 1},
"tests": [
{
"description": "longer is valid",
"data": [1, 2],
"valid": true
},
{
"description": "exact length is valid",
"data": [1],
"valid": true
},
{
"description": "too short is invalid",
"data": [],
"valid": false
},
{
"description": "ignores non-arrays",
"data": "",
"valid": true
}
]
}
]

View File

@ -1,33 +0,0 @@
[
{
"description": "minLength validation",
"schema": {"minLength": 2},
"tests": [
{
"description": "longer is valid",
"data": "foo",
"valid": true
},
{
"description": "exact length is valid",
"data": "fo",
"valid": true
},
{
"description": "too short is invalid",
"data": "f",
"valid": false
},
{
"description": "ignores non-strings",
"data": 1,
"valid": true
},
{
"description": "one supplementary Unicode code point is not long enough",
"data": "\uD83D\uDCA9",
"valid": false
}
]
}
]

View File

@ -1,42 +0,0 @@
[
{
"description": "minimum validation",
"schema": {"minimum": 1.1},
"tests": [
{
"description": "above the minimum is valid",
"data": 2.6,
"valid": true
},
{
"description": "below the minimum is invalid",
"data": 0.6,
"valid": false
},
{
"description": "ignores non-numbers",
"data": "x",
"valid": true
}
]
},
{
"description": "exclusiveMinimum validation",
"schema": {
"minimum": 1.1,
"exclusiveMinimum": true
},
"tests": [
{
"description": "above the minimum is still valid",
"data": 1.2,
"valid": true
},
{
"description": "boundary point is invalid",
"data": 1.1,
"valid": false
}
]
}
]

View File

@ -1,107 +0,0 @@
[
{
"description": "integer",
"schema": {"type": "integer"},
"tests": [
{
"description": "a bignum is an integer",
"data": 12345678910111213141516171819202122232425262728293031,
"valid": true
}
]
},
{
"description": "number",
"schema": {"type": "number"},
"tests": [
{
"description": "a bignum is a number",
"data": 98249283749234923498293171823948729348710298301928331,
"valid": true
}
]
},
{
"description": "integer",
"schema": {"type": "integer"},
"tests": [
{
"description": "a negative bignum is an integer",
"data": -12345678910111213141516171819202122232425262728293031,
"valid": true
}
]
},
{
"description": "number",
"schema": {"type": "number"},
"tests": [
{
"description": "a negative bignum is a number",
"data": -98249283749234923498293171823948729348710298301928331,
"valid": true
}
]
},
{
"description": "string",
"schema": {"type": "string"},
"tests": [
{
"description": "a bignum is not a string",
"data": 98249283749234923498293171823948729348710298301928331,
"valid": false
}
]
},
{
"description": "integer comparison",
"schema": {"maximum": 18446744073709551615},
"tests": [
{
"description": "comparison works for high numbers",
"data": 18446744073709551600,
"valid": true
}
]
},
{
"description": "float comparison with high precision",
"schema": {
"maximum": 972783798187987123879878123.18878137,
"exclusiveMaximum": true
},
"tests": [
{
"description": "comparison works for high numbers",
"data": 972783798187987123879878123.188781371,
"valid": false
}
]
},
{
"description": "integer comparison",
"schema": {"minimum": -18446744073709551615},
"tests": [
{
"description": "comparison works for very negative numbers",
"data": -18446744073709551600,
"valid": true
}
]
},
{
"description": "float comparison with high precision on negative numbers",
"schema": {
"minimum": -972783798187987123879878123.18878137,
"exclusiveMinimum": true
},
"tests": [
{
"description": "comparison works for very negative numbers",
"data": -972783798187987123879878123.188781371,
"valid": false
}
]
}
]

View File

@ -1,222 +0,0 @@
[
{
"description": "validation of regular expressions",
"schema": {"format": "regex"},
"tests": [
{
"description": "a valid regular expression",
"data": "([abc])+\\s+$",
"valid": true
},
{
"description": "a regular expression with unclosed parens is invalid",
"data": "^(abc]",
"valid": false
}
]
},
{
"description": "validation of date-time strings",
"schema": {"format": "date-time"},
"tests": [
{
"description": "a valid date-time string",
"data": "1963-06-19T08:30:06.283185Z",
"valid": true
},
{
"description": "an invalid date-time string",
"data": "06/19/1963 08:30:06 PST",
"valid": false
},
{
"description": "only RFC3339 not all of ISO 8601 are valid",
"data": "2013-350T01:01:01",
"valid": false
}
]
},
{
"description": "validation of date strings",
"schema": {"format": "date"},
"tests": [
{
"description": "a valid date string",
"data": "1963-06-19",
"valid": true
},
{
"description": "an invalid date string",
"data": "06/19/1963",
"valid": false
}
]
},
{
"description": "validation of time strings",
"schema": {"format": "time"},
"tests": [
{
"description": "a valid time string",
"data": "08:30:06",
"valid": true
},
{
"description": "an invalid time string",
"data": "8:30 AM",
"valid": false
}
]
},
{
"description": "validation of URIs",
"schema": {"format": "uri"},
"tests": [
{
"description": "a valid URI",
"data": "http://foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "a valid protocol-relative URI",
"data": "//foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "an invalid URI",
"data": "\\\\WINDOWS\\fileshare",
"valid": false
},
{
"description": "an invalid URI though valid URI reference",
"data": "abc",
"valid": false
}
]
},
{
"description": "validation of e-mail addresses",
"schema": {"format": "email"},
"tests": [
{
"description": "a valid e-mail address",
"data": "joe.bloggs@example.com",
"valid": true
},
{
"description": "an invalid e-mail address",
"data": "2962",
"valid": false
}
]
},
{
"description": "validation of IP addresses",
"schema": {"format": "ip-address"},
"tests": [
{
"description": "a valid IP address",
"data": "192.168.0.1",
"valid": true
},
{
"description": "an IP address with too many components",
"data": "127.0.0.0.1",
"valid": false
},
{
"description": "an IP address with out-of-range values",
"data": "256.256.256.256",
"valid": false
}
]
},
{
"description": "validation of IPv6 addresses",
"schema": {"format": "ipv6"},
"tests": [
{
"description": "a valid IPv6 address",
"data": "::1",
"valid": true
},
{
"description": "an IPv6 address with out-of-range values",
"data": "12345::",
"valid": false
},
{
"description": "an IPv6 address with too many components",
"data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1",
"valid": false
},
{
"description": "an IPv6 address containing illegal characters",
"data": "::laptop",
"valid": false
}
]
},
{
"description": "validation of host names",
"schema": {"format": "host-name"},
"tests": [
{
"description": "a valid host name",
"data": "www.example.com",
"valid": true
},
{
"description": "a host name starting with an illegal character",
"data": "-a-host-name-that-starts-with--",
"valid": false
},
{
"description": "a host name containing illegal characters",
"data": "not_a_valid_host_name",
"valid": false
},
{
"description": "a host name with a component too long",
"data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component",
"valid": false
}
]
},
{
"description": "validation of CSS colors",
"schema": {"format": "color"},
"tests": [
{
"description": "a valid CSS color name",
"data": "fuchsia",
"valid": true
},
{
"description": "a valid six-digit CSS color code",
"data": "#CC8899",
"valid": true
},
{
"description": "a valid three-digit CSS color code",
"data": "#C89",
"valid": true
},
{
"description": "an invalid CSS color code",
"data": "#00332520",
"valid": false
},
{
"description": "an invalid CSS color name",
"data": "puce",
"valid": false
},
{
"description": "a CSS color name containing invalid characters",
"data": "light_grayish_red-violet",
"valid": false
}
]
}
]

View File

@ -1,18 +0,0 @@
[
{
"description": "ECMA 262 regex dialect recognition",
"schema": { "format": "regex" },
"tests": [
{
"description": "[^] is a valid regex",
"data": "[^]",
"valid": true
},
{
"description": "ECMA 262 has no support for lookbehind",
"data": "(?<=foo)bar",
"valid": false
}
]
}
]

View File

@ -1,15 +0,0 @@
[
{
"description": "some languages do not distinguish between different types of numeric value",
"schema": {
"type": "integer"
},
"tests": [
{
"description": "a float is not an integer even without fractional part",
"data": 1.0,
"valid": false
}
]
}
]

View File

@ -1,34 +0,0 @@
[
{
"description": "pattern validation",
"schema": {"pattern": "^a*$"},
"tests": [
{
"description": "a matching pattern is valid",
"data": "aaa",
"valid": true
},
{
"description": "a non-matching pattern is invalid",
"data": "abc",
"valid": false
},
{
"description": "ignores non-strings",
"data": true,
"valid": true
}
]
},
{
"description": "pattern is not anchored",
"schema": {"pattern": "a+"},
"tests": [
{
"description": "matches a substring",
"data": "xxaayy",
"valid": true
}
]
}
]

Some files were not shown because too many files have changed in this diff Show More