formats: JSON Schema validation of the 2020-12 in-place keywords in std/json-schema (step 1 of #80) #434
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Step 1 of #80 (
std/json-schema). The package, the schema model and a validator for the in-place keywords of draft 2020-12: read a schema from JSON, check a JSON document against it, get the list of failures with the places they were found. No references ($ref,$dynamicRef), nounevaluated*, no earlier drafts, no writing and no derivation from a type yet; those are the later steps of the epic.Source
Encode/Decode; the versions of one format share one model.std/tomlandstd/xmlare the layout model (format value, tree, parser, vendored public suite, docs page);std/jsonprovidesJsonValue, the document the validator reads.Design record point
ROADMAP "Which versions a format supports" (the JSON Schema row: one model, an earlier draft is read into the current one) and ENCODING.md section 9. Decided by the loop:
std/json-schema(std/json-schema/project.trb,src/lib.trbre-exporting fromschema.trb,keywords.trb,validate.trb,error.trb), written in TorbScript, nonative, not in the prelude. Hyphenated like the plannedstd/language-model.public type JsonSchemais the model of the current draft (2020-12 vocabulary), built from aJsonValueor from text:JsonSchema.parse(value: JsonValue): Result<JsonSchema, JsonSchemaError>andJsonSchema.read(text: String): Result<JsonSchema, JsonSchemaError>. A boolean schema is a schema. Methods, not free functions (#146). Exact names beyond these follow the conventions ofstd/tomlandstd/xml.JsonSchema.validate(instance: JsonValue): Validation, whereValidationhasvalid: Boolanderrors: List<ValidationError>; aValidationErrorhas thekeyword, theschemaLocationand theinstanceLocation(both JSON Pointer text) and amessage. Output is the "basic" shape of the specification, flattened.ValidationimplementsShow.type,enum,const;multipleOf,maximum,exclusiveMaximum,minimum,exclusiveMinimum;maxLength,minLength,pattern;maxItems,minItems,uniqueItems,maxContains,minContains,prefixItems,items,contains;maxProperties,minProperties,required,dependentRequired,dependentSchemas,properties,patternProperties,additionalProperties,propertyNames;allOf,anyOf,oneOf,not,if/then/else. The annotation keywords (title,description,default,examples,deprecated,readOnly,writeOnly,$comment) are read and kept, not evaluated; an unknown keyword is ignored, as the specification says.$schema: absent or the 2020-12 URI is accepted; any other value is aJsonSchemaErrorthat names it, until its step adds the draft (never a silent misread). A schema using$ref,$dynamicReforunevaluated*is likewise refused with a clear error, so step 1 never answers "valid" for a keyword it does not check.patternandpatternPropertiesrun onstd/regex(RE2 syntax, linear time). Where ECMA 262 syntax outside RE2 (lookahead, backreferences) is used, the pattern is aJsonSchemaErrorat read time; the cases of the suite that need it are listed as exclusions in the test with the reason.JsonValue.Numberis aFloat64: integer-ness (type: "integer",1.0counts as an integer),multipleOfand the comparison keywords follow the specification on that representation; arbitrary-precision cases are the suite's optionalbignumfile and are excluded with that reason.Acceptance criteria
use JsonSchema, Validation, ValidationError, JsonSchemaError from "std/json-schema"works;JsonSchema.read(text)reads a 2020-12 schema andvalidate(instance)answersvalidor the list of failures, oneValidationErrorper failed keyword, withinstanceLocationas a JSON Pointer (for example/items/2/name).$schema, a keyword of a later step, a pattern outside RE2) areJsonSchemaErrors that name what was refused.std/json-schema/tests/suite-cases.trbwith its notice and the pinned release tag in the header (the model isstd/yaml/tests/suite-cases.trb), for the files oftests/draft2020-12/that are about the keywords above; each case is its own test and passes. Files and cases about$ref,$dynamicRef,unevaluated*,format,content,vocabulary,optional/and thebignumfile are excluded by name, and every other exclusion (a case that needs a reference, a lookahead pattern) is listed in the test with its reason, so the exclusions shrink with the later steps.docs/standard-library/json-schema.md(front matter asjson.md, atrb checkexample that validates a small document and prints the failures), listed indocs/standard-library/index.md;torb docs check,docs index --check,docs skill --checkanddoc --check --no-run stdare green; ROADMAP's Formats item notes the package as started (JSON Schema validation, 2020-12 in-place keywords) without claiming the epic done.sh tools/gates.sh a); every public declaration has its doc comment; touched files passtorb format --check.Touches the seed?
No.
std/json-schemais a new package that the compiler does not import, and no std name is looked up by string, so no two-commit rule applies. One or two Conventional Commits:feat(std/json-schema): validate JSON against the in-place keywords of 2020-12and, if the diff is large,docs(std/json-schema): ...(page, index, regeneratedskills/).Dependencies
std/json(JsonValue),std/regexandstd/testexist.[loop:torbscript] claim implement by session:loop-torbscript-20261023 until 2026-10-23T21:02Z
JsonPointer(RFC 6901) instd/json(step 1 of #81) #435[loop:torbscript] implement: std/json-schema reads 2020-12 schemas and validates the in-place keywords (694 suite cases from JSON-Schema-Test-Suite 23.1.0, two groups mixing in later-step keywords listed as refused), page + index + skills + ROADMAP note added, one docs-declarations fix after the first CI round, PR #436, CI green (tier A, docs gates, pdisc), next: review. Tokens: about 0.3M for this item across two context windows (estimate).
std/json-schema:$id,$ref,$defs,$anchorand a registry of supplied documents (step 2a of #80) #553std/json-schema(step 2b of #80) #567std/json-schema(step 3 of #80) #690formatassertion for the formats std can parse (step 4a of #80) #697