Repository navigation
Document the HTTP API with OpenAPI 3.1 and test it against the service - #13
Merged
Merged
Conversation
… schemas SchemaRegistry implements the draft 2020-12 keywords used in schemas/ and fails closed on any other keyword. Tests validate every recorded report, example design and example program against the published schemas.
error.schema.json describes the body of every error response; job.schema.json
gains the job summary and the {job} envelope returned on submission and stop.
API_ROUTES lists every API operation and the handler dispatches through it, so the routes can be compared with the API description. GET /api/openapi.json serves schemas/openapi.json bundled into one document: the referenced JSON Schemas are embedded under components/schemas and every reference is rewritten to a local pointer. A bundle request for a job that ended without a report now says so instead of reporting that the job has not finished.
schemas/openapi.json describes every route the service answers, reuses the JSON Schemas by $ref, lists the error responses each operation returns and states the Host/Origin policy, the queue limit and the job lifecycle. Examples are responses recorded from a live service. The test checks the description against API_ROUTES in both directions, validates every example against its schema, checks that every error code the handler can produce is documented, and validates live responses of an in-process service against the description.
Adds Client.openapi(), CryptificateError.retry_after for 429 responses, the job, stop and openapi commands, and OPERATIONS mapping each operationId to its method. New tests check that mapping against schemas/openapi.json and run the client against the responses recorded there. The README documents every method, the error fields and every command.
docs/api.md covers the endpoints, the Host/Origin security model, the job lifecycle, polling, the queue limit and the other limits, bundle download and the error codes, with curl examples. The README and the architecture page link it, and the description states which jobs survive a restart.
resolveJsonPointer takes an RFC 6901 pointer in its plain string form, where '%' is an ordinary character. SchemaRegistry.resolve now decodes the URI fragment of a $ref before resolving it and reports a malformed fragment as UnsupportedSchemaError.
A pipeline that holds the run slot keeps a second job queued, so the
409 not-ready answers ('the job has not finished' and 'the job ended
before it produced a report') and 429 queue-full are checked against
the OpenAPI description on every run. The 413 check now sends a
declared length over the limit, and both live tests assert every
operation/status pair they are meant to exercise. Local $ref fragments
are percent-decoded before pointer resolution.
A GET or POST under /api/ that matches no route answers 404, also on a documented path with the other method; every other method, HEAD included, answers 405, and no Allow header is sent. The error table in docs/api.md now says this, matching the OpenAPI info text, and the live test checks each case.
Resolve the overlap with the branches merged before it, as in the release/v0.2.0 integration.
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.
Summary
This PR makes the local service's HTTP API a documented integration surface:
schemas/openapi.jsonis an OpenAPI 3.1 description of every routeapps/serveranswers. It reuses the existing JSON Schemas by$ref, lists the error responses each operation can return, and states the Host/Origin security model, the queue limit and the job lifecycle. Its examples are responses recorded from a live service.GET /api/openapi.jsonas one self-contained document.docs/api.mddocuments the API for people, with curl examples.What is changed (precise)
No Lean, Rust or refinement code changed, and no proof or claim changed.
refinement/STATUS.mdandclaims.jsonare therefore unaffected.packages/schemaSchemaRegistry(src/jsonschema.ts): a dependency-free JSON Schema draft 2020-12 validator. It implements the keywords used inschemas/*.jsonandopenapi.json:$refacross files, resolved against$idtype,enum,constallOf,anyOf,oneOf,notif,then,elseUnsupportedSchemaErrorinstead of being ignored.formatis an annotation only.assertSupported(uri)walks a whole schema, checking that every keyword is implemented and every reference resolves.resolveJsonPointertakes an RFC 6901 pointer in its plain string form and does not percent-decode it ('%'is an ordinary character).SchemaRegistrypercent-decodes the URI fragment of a$refonce before resolving it, and reports a malformed fragment (such as#/a/100%) asUnsupportedSchemaError.schemas/error.schema.jsonfor the{error:{code,message,path?}, errors?}body of every error response. Its description lists every error code.job.schema.jsongains$defs/summaryand$defs/envelope, the{job:{id,kind,state,origin}}body returned by submission and stop. This is additive.openapi.jsonwith seven API operations andGET /(the web workbench):getCapabilities,getOpenApi,submitAnalysis,submitExperiment,getJob,stopJob,getJobBundleConnection: close), 415, 429 (withRetry-After: 30) and 500, as the handler returns theminfo.description: a GET or POST under/api/that matches no operation (an unknown path, or a described path with a method it does not list, such asGET /api/analyses) answers 404not-found; any other method, HEAD and OPTIONS included, answers 405method-not-allowed; no response sends anAllowheaderLocationandContent-Dispositionheaderscryptificate servebuilt from this branch (release engine, Lean library built locally). The recorded run includes a completed analysis in which the mis-wired AES circuit is refuted with a witness, plus queued, running and cancelled jobs, 429, 409 and every 4xx.apps/serverAPI_ROUTES(inserver.ts) lists every API operation, and the handler now dispatches throughmatchApiRoute. Two behaviours changed:GET /api/openapi.json(openapi.ts). It readsschemas/openapi.jsononce and returns it bundled: referenced schema files are embedded undercomponents/schemaswithout$idor$schema, and every$refis rewritten to a local pointer. A checkout without the file answers 404not-found.python/cryptificateClient.openapi().CryptificateError.retry_after, set on 429.OPERATIONS, which maps eachoperationIdto its method.python -m cryptificate job|stop|openapicommands.Docs
docs/api.mdcovers:--allow-origin, no CORS, the response headersREADME.mdanddocs/architecture.mdlink it.Tests run
npm ci: ok.npm run build && npm test(whole workspace):CRYPTIFICATE_INTEGRATION=1)python3 -m unittest discover -s tests(inpython/): 15 passed (6 new).apps/server/test/openapi.test.tschecks:/api/operations equalAPI_ROUTES(method, path, operationId) in both directions.assertSupported.validateAnalysisRequest/validateExperimentRequest.(status, code)thatsendError/HttpErrorproduces inserver.tsis documented.Locationheader and the bundleContent-Disposition). The 413 case sends a declaredContent-Lengthover the limit, so it does not depend on upload timing.queued. It checks, against the description and unconditionally: 409not-ready"the job has not finished" for a running and a queued job; 429queue-fullwithRetry-After: 30for both submission operations; a stopped queued job readscancelledwith no report and its bundle answers 409 "the job ended before it produced a report"; a stopped running job keeps its partial report and its bundle answers 200./api/paths: GET and POST answer 404not-found; PUT, DELETE, PATCH, HEAD and OPTIONS answer 405method-not-allowed; none sendsAllow.packages/schema/test/jsonschema.test.tschecks pointers with%in keys (/a%20b,/100%) resolve literally, that$reffragments are percent-decoded once (#/$defs/100%25), and that a malformed fragment throwsUnsupportedSchemaError.openapi-spec-validatoraccepts bothschemas/openapi.json(with its file references) and the served bundle as OpenAPI 3.1.jsonschema(Draft 2020-12) validates all 59 examples in the served bundle against their schemas, with 0 failures; a negative control is rejected.cargo build --release -p cryptificate-cli -j2,lake build Cryptificate(only Cryptificate modules were built), thennode apps/server/dist/src/cli.js serve. The curl workflow indocs/api.md(submit, poll, print claims,curl -OJthe bundle, stop) was run against it.cargo test --workspace,lean/scripts/check_examples.pyandrefinementchecks. No Rust, Lean or refinement file changed, and disk space was tight.Scope and limits
SchemaRegistryis a subset validator by design:unevaluated*,dependent*,contains,$dynamicRefand embedded$ids below a document root are not supported, and using them throws.formatis not asserted.API_ROUTES. It relies on the handler dispatching only through that table, which this PR makes true. The error-code check readsserver.tswith a regular expression over literalsendError/HttpErrorcalls, so a code built dynamically would not be seen.GET /is described as the workbench's entry point only. Other static paths and the client-side route fallback are explained in prose, because OpenAPI has no wildcard paths.Generated by Claude Code