Marwes / schemafy

Crate for generating rust types from a json schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test against the JSON Schema Test Suite

adeschamps opened this issue · comments

I think it would be compelling to test this crate against the JSON Schema Test Suite. It's also a pretty efficient way to get one or two hundred unit tests almost for free.

I've been experimenting with it here. I added the test suite repo as a git submodule and created a test-suite crate with a build script that generates types and tests. The test crate behaves like this:

  • If schemafy ever panics or returns an error, then the build script will fail.
  • If schemafy generates invalid code, then the test crate will fail to compile.
  • If the test data can't be deserialized to the generated types, then the tests themselves will fail.

There are a few cases where schemafy panics, so I excluded a few of the test files so I could at least have a functioning test suite. This includes external refs (#3) and enums where some of the variants are numbers. I only included the tests where the data is valid, since schemafy doesn't check for properties such as minLength and so on.

Along the way I realized that JSON schema have a lot of weird edge cases, including some where I personally think the spec is too lenient.

If it's useful to have partial coverage, I can open a PR now.

Teems potentially useful, though at the moment this crate probably lacks to many features so at best it could be included piecemeal with features added a long the way to fix problems.

I'm going to close this, since I added the ability in #24 and I don't think that passing the entire test suite is going to happen anytime soon.