Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ jobs:
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
docs:
name: Documentation
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JSONSchema2Types

[![Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://rmsrosa.github.io/JSONSchema2Types.jl/dev/) [![CI](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![GitHub repo size](https://img.shields.io/github/repo-size/rmsrosa/JSONSchema2Types.jl)
[![Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://rmsrosa.github.io/JSONSchema2Types.jl/dev/) [![CI](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/rmsrosa/JSONSchema2Types.jl/actions/workflows/CI.yml) [![codecov](https://codecov.io/gh/rmsrosa/JSONSchema2Types.jl/graph/badge.svg)](https://codecov.io/gh/rmsrosa/JSONSchema2Types.jl) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![GitHub repo size](https://img.shields.io/github/repo-size/rmsrosa/JSONSchema2Types.jl)

Generate Julia types from a [JSON Schema](https://json-schema.org), together with functions
to read and write JSON documents that conform to the schema.
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,27 @@ module. Returns the generated module.
function load_generated(schema; split = false, kwargs...)
output = joinpath(mktempdir(), split ? "generated" : "generated.jl")
file = generate_module(schema, output; split, kwargs...)
split || include_runtime_sources!(file)
# the file contains a single `module ... end`, which evaluates to the module itself
return Base.include(Module(), file)
end

# A generated file contains a copy of the runtime code of the package (`src/runtime*.jl`).
# Replace each copy by an `include` of its source file, the same code, so that the code
# coverage of the tests is recorded for the source files.
const RUNTIME_SOURCES = [JSONSchema2Types.RUNTIME_CODE => "runtime.jl",
JSONSchema2Types.VALIDATION_CODE => "runtime_validation.jl",
JSONSchema2Types.FORMATS_CODE => "runtime_formats.jl"]
function include_runtime_sources!(file)
code = read(file, String)
for (source, name) in RUNTIME_SOURCES
path = joinpath(pkgdir(JSONSchema2Types), "src", name)
code = replace(code, source => "include(" * repr(path) * ")\n"; count = 1)
end
write(file, code)
return file
end

# Compare JSON values regardless of the order of keys and of `1` vs `1.0`.
canon(x::AbstractDict) = Dict(String(k) => canon(v) for (k, v) in x)
canon(x::AbstractVector) = Any[canon(v) for v in x]
Expand Down
Loading