Repository navigation
Option for minimal types, with the validation in a separate file - #14
Merged
Merged
Conversation
- `generate_module(...; validation = :separate)`: the constructors of the generated types only convert values to the types of their fields, and the checks of the constraints (the constraints of each type, the subschemas checked at runtime and the validator) go in a separate file, `validation.jl` (or `<name>_validation.jl`), that the module includes only if it is present. It provides `validate`, `violations`, `isvalid` and `check_formats!`, and makes `tojson`/`writejson` validate first. - `validation = :none`: minimal types, without the validation file. - `validation = :inline` (the default) is as before. - The runtime is split into `runtime.jl` (reading and writing) and `runtime_validation.jl` (the checks). - The conformance harness takes `--validation=separate`. - Docs, README, tests and an example (`AcmeNestedMinimal`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the option to generate minimal types: the same structs and constructors, without the runtime checks. The code for checking against the schema can go in a separate, optional file.
Changes
generate_module(...; validation = ...)::inline(the default) works as before: the constructors check the constraints of the schema.:separategives minimal types. Their constructors only convert values to the types of their fields (via_jsfrom), with no_jscheck, and the enum constructors do not check their values. Everything needed to check goes invalidation.jl(or<name>_validation.jlnext to the module file, withoutsplit): the runtime validator, the full metadata of each type (constraints, embedded subschemas, regexes) as_vspecs, and the root constraints. The module includes it only if it is present:validate,violations,isvalidandcheck_formats!, andtojson/writejsonvalidate before writing (unless givenvalidate = false). Reading is not checked;validate(readjson(T, file))does that. Without the file, the module only reads and writes.:nonegives the minimal types without the validation file.src/runtime.jl(reading and writing) andsrc/runtime_validation.jl(the checks). They are connected by a constant_INLINE_CHECKS, emitted by the generator, and a_VALIDATORhook that the validation code sets.checks!/with_checksmoved to the validation part, and are exported only with:inline.checks = falseonly applies withvalidation = :inline; any other combination throws anArgumentError.--validation=separateoption generates minimal modules, then reads each instance and runsvalidateon it.generate_moduledocstring, tests, and a committed example:examples/generated/AcmeNestedMinimal.jlplusAcmeNestedMinimal_validation.jl.Sizes (BeerJSON)
:inline:none:separatevalidation.jlChecks
Pkg.test()passes on Julia 1.13 (487 tests) and 1.10 (485 tests). The new tests::separate(split and single file), and are valid;violations/validate, and writing them throws;tojson(...; validate = true)then throws anArgumentError;:nonemodule has no validation code.--validation=separate, the same 2175 tests pass, with identical per-test results; only the wording of some error messages differs. CI runs the default mode only.Generated by Claude Code