Repository navigation
fix(mock): match {param} path templates and resolve nested $ref/anyOf/oneOf/allOf - #29
Merged
Merged
Conversation
…/oneOf/allOf/const
- MockServer matches requests against templated spec paths after literal
paths; the most specific template wins; trailing slash and query handling kept.
- generate_instance resolves local $ref at any depth (schemas and responses),
handles anyOf/oneOf (non-null preferred), allOf (merged), const and 3.1 type
lists, with a cycle/depth guard.
- load_routes/parse_openapi keep the {spec_path: {METHOD: body}} shape.
Implementation authored by the Factory Coder lane (codex gpt-6.1-sol).
FactoryRun: baton-mock-templates-20261117
Built-By: Factory v0.8.29
Covers R1-R11: templated paths, literal/specificity precedence, 404 cases, nested and response $ref, recursion bounds, anyOf/oneOf/allOf/const, and unchanged example/default/enum precedence. Existing tests unchanged. Tests authored independently by the Factory Tester lane (cursor-agent grok-4.7-high). FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
A required self-reference returned {} at the first repetition, so e.g.
Node.child or Tree.kids were empty objects. Emit one full instance of a
directly self-referencing schema and cut only its next link; mutual
recursion and the depth guard are unchanged.
Implementation authored by the Factory Coder lane (codex gpt-6.1-sol), repair round 1.
FactoryRun: baton-mock-templates-20261117
Built-By: Factory v0.8.29
Required self-reference, required array of self-references (minItems 2) and required mutual recursion must load and serve in bounded time with the first followed instance generated. Tests authored independently by the Factory Tester lane (cursor-agent grok-4.7-high), repair round 1. FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
There was a problem hiding this comment.
Confidence Score: 4/5
Summary
Latest head adds allOf enum/const intersection and keeps $ref-plus-sibling allOf compositions; prior findings are resolved or explicitly accepted. 1223 tests pass, real infra-baton specs load with far fewer empty leaves. Low risk.
Important Files Changed
| File | Overview |
|---|---|
| src/baton/mock.py | _merge_schema now concatenates allOf and intersects enum/const; diagnostics set threaded per load |
| tests/test_mock.py | Three new allOf tests; fail on previous head, pass here |
Findings
src/baton/mock.py:65— Membership uses Python equality, so enum [1,2] intersected with const true yields 1; compare with matching JSON types (exclude bool/int cross-matches) if exactness matters.
Reviewed a7266a7...cba4d13 · ↻ Re-run review · View in Adapt
- $ref sibling keys are merged with the referenced schema (_merge_schema)
instead of replacing its properties/required.
- Maps (additionalProperties only) get entries only when minProperties
requires them; otherwise {} as before.
- Single example/default/enum/const precedence check after expansion.
- Unresolved-ref log de-duplication is scoped to one spec load.
Implementation authored by the Factory Coder lane (codex gpt-6.1-sol), repair round 2.
FactoryRun: baton-mock-templates-20261117
Built-By: Factory v0.8.29
No assertion changes. Tests authored independently by the Factory Tester lane (cursor-agent grok-4.7-high), repair round 2. FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
A spec path ending in / (literal or templated) now matches the request with or without the trailing slash. Exact literal matches still win first. Implementation authored by the Factory Coder lane (codex gpt-6.1-sol), repair round 3. FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
Tests authored independently by the Factory Tester lane (cursor-agent grok-4.7-high), repair round 3. FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
Collaborator
Author
|
@adaptcom review |
- A $ref whose target and sibling both have allOf now keeps both lists, so the referenced schema's required fields are not dropped. - allOf intersects enum/const values instead of overwriting them; an empty intersection falls back to the first part and is logged once at debug. Implementation authored by the Factory Coder lane (codex gpt-6.1-sol), repair round 4 (independent review findings). FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
Tests authored independently by the Factory Tester lane (cursor-agent grok-4.7-high), repair round 4. FactoryRun: baton-mock-templates-20261117 Built-By: Factory v0.8.29
Collaborator
Author
|
@adaptcom review |
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.
Why
infra-baton's staging Baton can't serve the current Wander service specs. Tested with the current
@wandercom/*-clientspecs on Baton 0.4.2:{param}never match.MockServerlooks routes up by exact text, soGET /invoices/123→ 404 for/invoices/{id}. This already affects the specs in use today: 32 of 46 payment paths and 30 of 39 property paths are templated. Search moved from literal/collections/wander/...to/collections/{collectionId}/..., so its mock started returning 404 too.$refand composite schemas produce{}.generate_instancedidn't follow$refbelow the top of the response, or#/components/responses/..., and didn't handleanyOf/oneOf/allOf/const. Examples:rate_cents: {}instead of an integer, anddata: [{}]instead of objects with their required fields.What changed (
src/baton/mock.pyonly)add_routescompiles{param}paths once. Lookup order: exact literal path, then a literal path differing only by a trailing slash, then templates, most specific first (more literal segments). A trailing slash is optional on both the spec path and the request, for literal and templated paths alike. Each placeholder matches exactly one non-empty segment. Query stripping, the 404 body and the method check are unchanged.$refis resolved at any depth (schemas and responses, JSON Pointer~0/~1).anyOf/oneOfproduce a value from one branch, preferring non-null.allOfmerges properties, required fields and bounds, intersectsenum/const, and keeps both compositions when a$refand its siblings each carryallOf.constand OpenAPI 3.1 type lists are supported.example/default/enumkeep their precedence.$refis generated once as a real instance, then cut off at the next repetition; a depth guard of 32 also applies. Output stays finite and fast, including a required array of self-references.load_routes()/parse_openapi()still return{spec_path: {METHOD: body}}, whichcollapse.pyrelies on.generate_instance(schema)still works without the new optionalcomponentsargument. No new dependencies.Tests (
tests/test_mock.py; existing tests unchanged)New
TestPathTemplatesandTestSchemaCompositioncover R1–R11: template matching, literal and most-specific precedence, 404 cases, nested and response$ref, required/self/mutual recursion in bounded time,anyOf/oneOf/allOf/const, and unchangedexample/default/enumprecedence. They exercise realMockServersockets andload_routes.Verification
main(a7266a7) and pass with this change.tests/smoke.py:smoke.pyliteral-path lookup that will be fixed in the spec refresh PR.Known, accepted differences
Template lookup is method-blind: the most specific matching path is chosen first, and a missing method there returns 404 without trying a less specific template. In the current specs this only affects unrealistic requests (for example
GET /invoices/preview, where/invoices/previewis POST-only).Because a trailing slash is optional,
/x/{id}and/x/{id}/compile to the same template. If a spec contained both with different methods, only the first one's methods would be reachable. None of the 6 mocked Wander specs has any path ending in/, so this can't occur today. A follow-up could merge method tables for identical templates.The template loop in
_handlestill checkspattern.fullmatch(path)beforealt_path. Since compiled templates never end with/, that first check is redundant. Cosmetic, no behavior impact.allOfenum/constintersection uses Python equality, sotrueand1compare equal (e.g.enum: [1, 2]withconst: trueyields1). No current Wander spec mixes booleans and integers in anallOf.After merge
Cut a release tag (for example
v0.4.3) so infra-baton can bump Baton and refresh its specs.How it was built
This PR was built by the Software Factory: Codex (gpt-6.1-sol) wrote the implementation, Cursor (grok-4.7-high) wrote the tests independently without seeing it, and Claude (validator) reviewed them, with agy (gemini-4-carbon-high) providing oversight. Repair rounds fixed recursive references being cut off too early and addressed every review finding (
$refsibling merging, no synthetic map keys, per-load log de-duplication, trailing-slash spec paths, test docstrings) and two independent review findings ($ref+ siblingallOfdropping required fields; overlappingenums inallOf).PR built by Factory v0.8.29
FactoryRun: baton-mock-templates-20261117
🤖 Generated with Claude Code