Skip to content

Commit 0fd15d4

Browse files
fredbiclaude
andcommitted
test(builders): cover the field-dispatch arms and the response items anchor
Extends two harnesses ahead of factoring the duplicated field dispatch out of the parameters and responses builders, because neither could see the change. The conformance suite's subjects were all named or alias types, which reach only two arms of the dispatch. It gains struct, interface, map, pointer, plain basic, and a slice with an inline element, so the arms about to be moved are compared in all three positions rather than guarded by goldens alone. The second gap was the dangerous one. The responses builder threads `descendBody("items")` through its array arms, and that affects cross-ref provenance pointers only — never the emitted spec. No golden can see it, and neither can a suite that compares schemas, so dropping those two lines would have passed everything. The provenance corpus gains an array-bodied response whose element is inline, which pins /responses/{name}/schema/items/properties/code and fails without the threading. Inline is the operative word: a named element anchors in its own definition instead, where the threading is unobservable, so a witness built from one would prove nothing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 3407a14 commit 0fd15d4

4 files changed

Lines changed: 249 additions & 3 deletions

File tree

‎fixtures/enhancements/builder-conformance/types.go‎

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ type StampAlias = time.Time
8585
// RawAlias is an alias to the open "any JSON" stdlib type.
8686
type RawAlias = json.RawMessage
8787

88+
// --- shape subjects: the arms of the field dispatch, rather than the classifiers ---
89+
//
90+
// The subjects above are all named or alias types, which reach only two arms of
91+
// `buildFromField`. These reach the rest — struct, interface, map, slice with an
92+
// inline element, pointer, plain basic — so that a factorization of those arms is
93+
// guarded in all three positions rather than by goldens alone.
94+
95+
// Plain is a struct reached directly as a field.
96+
type Plain struct {
97+
// Left is a plain property.
98+
Left string `json:"left"`
99+
}
100+
101+
// Speaker is a non-empty interface reached directly as a field.
102+
type Speaker interface {
103+
// Say returns a word.
104+
Say() string
105+
}
106+
88107
// ModelHost reaches every subject as a MODEL FIELD — the schema builder's view,
89108
// and the control for the other two.
90109
//
@@ -113,6 +132,27 @@ type ModelHost struct {
113132

114133
// Raw is the open-schema subject.
115134
Raw RawAlias `json:"raw"`
135+
136+
// Struct is the struct-arm subject.
137+
Struct Plain `json:"struct"`
138+
139+
// Iface is the interface-arm subject.
140+
Iface Speaker `json:"iface"`
141+
142+
// Mapping is the map-arm subject.
143+
Mapping map[string]Plain `json:"mapping"`
144+
145+
// Inline is the slice arm with an inline element.
146+
Inline []struct {
147+
// Code is the inline element property.
148+
Code string `json:"code"`
149+
} `json:"inline"`
150+
151+
// Ptr is the pointer arm.
152+
Ptr *Plain `json:"ptr"`
153+
154+
// Basic is the plain-basic arm.
155+
Basic int32 `json:"basic"`
116156
}
117157

118158
// ParamsFmt reaches FmtNamed as a body parameter.
@@ -314,3 +354,159 @@ func HandlerStamp() {}
314354
//
315355
// 200: respRaw
316356
func HandlerRaw() {}
357+
358+
// ParamsStruct reaches the struct subject as a body parameter.
359+
//
360+
// swagger:parameters confStruct
361+
type ParamsStruct struct {
362+
// in: body
363+
Body Plain `json:"body"`
364+
}
365+
366+
// RespStruct reaches the struct subject as a response body.
367+
//
368+
// swagger:response respStruct
369+
type RespStruct struct {
370+
// in: body
371+
Body Plain `json:"body"`
372+
}
373+
374+
// HandlerStruct binds the struct subject.
375+
//
376+
// swagger:route POST /struct conf confStruct
377+
//
378+
// Responses:
379+
//
380+
// 200: respStruct
381+
func HandlerStruct() {}
382+
383+
// ParamsIface reaches the iface subject as a body parameter.
384+
//
385+
// swagger:parameters confIface
386+
type ParamsIface struct {
387+
// in: body
388+
Body Speaker `json:"body"`
389+
}
390+
391+
// RespIface reaches the iface subject as a response body.
392+
//
393+
// swagger:response respIface
394+
type RespIface struct {
395+
// in: body
396+
Body Speaker `json:"body"`
397+
}
398+
399+
// HandlerIface binds the iface subject.
400+
//
401+
// swagger:route POST /iface conf confIface
402+
//
403+
// Responses:
404+
//
405+
// 200: respIface
406+
func HandlerIface() {}
407+
408+
// ParamsMapping reaches the mapping subject as a body parameter.
409+
//
410+
// swagger:parameters confMapping
411+
type ParamsMapping struct {
412+
// in: body
413+
Body map[string]Plain `json:"body"`
414+
}
415+
416+
// RespMapping reaches the mapping subject as a response body.
417+
//
418+
// swagger:response respMapping
419+
type RespMapping struct {
420+
// in: body
421+
Body map[string]Plain `json:"body"`
422+
}
423+
424+
// HandlerMapping binds the mapping subject.
425+
//
426+
// swagger:route POST /mapping conf confMapping
427+
//
428+
// Responses:
429+
//
430+
// 200: respMapping
431+
func HandlerMapping() {}
432+
433+
// ParamsPtr reaches the ptr subject as a body parameter.
434+
//
435+
// swagger:parameters confPtr
436+
type ParamsPtr struct {
437+
// in: body
438+
Body *Plain `json:"body"`
439+
}
440+
441+
// RespPtr reaches the ptr subject as a response body.
442+
//
443+
// swagger:response respPtr
444+
type RespPtr struct {
445+
// in: body
446+
Body *Plain `json:"body"`
447+
}
448+
449+
// HandlerPtr binds the ptr subject.
450+
//
451+
// swagger:route POST /ptr conf confPtr
452+
//
453+
// Responses:
454+
//
455+
// 200: respPtr
456+
func HandlerPtr() {}
457+
458+
// ParamsBasic reaches the basic subject as a body parameter.
459+
//
460+
// swagger:parameters confBasic
461+
type ParamsBasic struct {
462+
// in: body
463+
Body int32 `json:"body"`
464+
}
465+
466+
// RespBasic reaches the basic subject as a response body.
467+
//
468+
// swagger:response respBasic
469+
type RespBasic struct {
470+
// in: body
471+
Body int32 `json:"body"`
472+
}
473+
474+
// HandlerBasic binds the basic subject.
475+
//
476+
// swagger:route POST /basic conf confBasic
477+
//
478+
// Responses:
479+
//
480+
// 200: respBasic
481+
func HandlerBasic() {}
482+
483+
// ParamsInline reaches the inline-element slice as a body parameter.
484+
//
485+
// swagger:parameters confInline
486+
type ParamsInline struct {
487+
// in: body
488+
Body []struct {
489+
// Code is the inline element property.
490+
Code string `json:"code"`
491+
} `json:"body"`
492+
}
493+
494+
// RespInline reaches the inline-element slice as a response body.
495+
//
496+
// swagger:response respInline
497+
type RespInline struct {
498+
// in: body
499+
Body []struct {
500+
// Code is the inline element property.
501+
Code string `json:"code"`
502+
} `json:"body"`
503+
}
504+
505+
// HandlerInline binds the inline-slice subject.
506+
//
507+
// swagger:route POST /inline conf confInline
508+
//
509+
// Responses:
510+
//
511+
// 200: respInline
512+
func HandlerInline() {}

‎fixtures/enhancements/provenance-params-responses/api.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,39 @@ type provResp struct {
3434
} `json:"body"`
3535
}
3636

37+
// provListResp is a response whose body is an ARRAY with an INLINE element.
38+
//
39+
// This is the only shape in which the responses builder's descendBody("items")
40+
// decides an anchor: it advances the body cursor as the builder peels its own
41+
// array layer, so the element's properties land under …/schema/items/… rather
42+
// than directly under …/schema/. With a NAMED element the anchor moves to that
43+
// element's own definition instead and descendBody is unobservable — so a
44+
// witness for it has to use an inline element or it proves nothing.
45+
//
46+
// descendBody affects cross-ref pointers only, never the emitted spec, so no
47+
// golden can guard it and neither can a schema-comparing conformance suite.
48+
// This anchor is its only detector.
49+
//
50+
// swagger:response provListResp
51+
type provListResp struct {
52+
// in: body
53+
Body []struct {
54+
// Code is the inline element property whose anchor is at stake.
55+
Code string `json:"code"`
56+
} `json:"body"`
57+
}
58+
59+
// provListHandler binds the array-bodied response.
60+
//
61+
// swagger:route GET /prov-list provListOp
62+
//
63+
// Prov list.
64+
//
65+
// responses:
66+
//
67+
// 200: provListResp
68+
func provListHandler() {}
69+
3770
// provHandler is the route. It references provResp so the response is bound to
3871
// the operation, and provOp ties the parameter set to this path/method.
3972
//

‎internal/integration/builder_conformance_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ func TestBuilderConformance(t *testing.T) {
6161
{prop: "bytes", path: "/bytes", response: "respBytes"},
6262
{prop: "stamp", path: "/stamp", response: "respStamp"},
6363
{prop: "raw", path: "/raw", response: "respRaw"},
64+
65+
// Shape subjects: the arms of the field dispatch rather than the classifiers. The classifier
66+
// subjects above reach only the Named and Alias arms; these reach the rest, so a factorization
67+
// of those arms is guarded in all three positions.
68+
{prop: "struct", path: "/struct", response: "respStruct"},
69+
{prop: "iface", path: "/iface", response: "respIface"},
70+
{prop: "mapping", path: "/mapping", response: "respMapping"},
71+
{prop: "inline", path: "/inline", response: "respInline", note: "slice arm with an inline element"},
72+
{prop: "ptr", path: "/ptr", response: "respPtr"},
73+
{prop: "basic", path: "/basic", response: "respBasic"},
6474
}
6575

6676
model := doc.Definitions["ModelHost"].Properties

‎internal/integration/coverage_provenance_test.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,12 @@ func TestCoverage_ProvenancePatternPropertyPointer(t *testing.T) {
430430
// resolved only after path binding, so a body parameter's inner schema is intentionally not drilled
431431
// into); a response header anchors at /responses/{name}/headers/{h}; and an in:body response
432432
// field's inline struct anchors its properties at /responses/{name}/schema/properties/f.
433+
//
434+
// The array-bodied case is the guard for descendBody: when the responses builder peels its OWN array
435+
// layer, the inline element's properties must land under …/schema/items/… . That threading affects
436+
// cross-ref pointers only and never the emitted spec, so no golden and no schema-comparing suite can
437+
// see it — this anchor is its only detector, and only with an INLINE element (a named one anchors in
438+
// its own definition instead).
433439
func TestCoverage_ProvenanceParamsResponses(t *testing.T) {
434440
byPointer := map[string]scanner.Provenance{}
435441
doc, err := codescan.Run(&codescan.Options{
@@ -444,9 +450,10 @@ func TestCoverage_ProvenanceParamsResponses(t *testing.T) {
444450
require.NotNil(t, doc)
445451

446452
for _, ptr := range []string{
447-
"/paths/~1prov/get/parameters/0", // parameter level (stops here)
448-
"/responses/provResp/headers/X-Request-Id", // response header
449-
"/responses/provResp/schema/properties/status", // inline body property
453+
"/paths/~1prov/get/parameters/0", // parameter level (stops here)
454+
"/responses/provResp/headers/X-Request-Id", // response header
455+
"/responses/provResp/schema/properties/status", // inline body property
456+
"/responses/provListResp/schema/items/properties/code", // inline element of an array body
450457
} {
451458
prov, ok := byPointer[ptr]
452459
require.Truef(t, ok, "expected an anchor for %q; got %v", ptr, keysOf(byPointer))

0 commit comments

Comments
 (0)
⌂ 换网址