@@ -291,110 +291,3 @@ func TestJSONTagsAndInlineRefs_Complex(t *testing.T) {
291291 t .Fatalf ("expected required array in result type, got: %#v" , rt )
292292 }
293293}
294-
295- func TestInlineRefs_MethodRootPayloadResult (t * testing.T ) {
296- t .Cleanup (func () { plugexpr .Root .UseJSONTags = false ; plugexpr .Root .InlineRefs = false })
297-
298- docsMap := genDocs (t , func () {
299- InlineRefs ()
300- API ("Test" , func () {})
301- var PayloadType = Type ("PayloadType" , func () {
302- Field (1 , "Foo" , String )
303- Required ("Foo" )
304- })
305- var ResultType = Type ("ResultType" , func () {
306- Field (1 , "Bar" , String )
307- Required ("Bar" )
308- })
309- Service ("S" , func () {
310- Method ("M1" , func () {
311- Payload (PayloadType )
312- Result (ResultType )
313- HTTP (func () { GET ("/" ) })
314- GRPC (func () {})
315- })
316- })
317- })
318-
319- svc := docsMap ["services" ].(map [string ]any )["S" ].(map [string ]any )
320- methods := svc ["methods" ].(map [string ]any )
321- m1 := methods ["M1" ].(map [string ]any )
322- pt := m1 ["payload" ].(map [string ]any )["type" ].(map [string ]any )
323- if _ , hasRef := pt ["$ref" ]; hasRef {
324- t .Fatalf ("expected inlined payload schema at method root, found $ref: %#v" , pt )
325- }
326- rt := m1 ["result" ].(map [string ]any )["type" ].(map [string ]any )
327- if _ , hasRef := rt ["$ref" ]; hasRef {
328- t .Fatalf ("expected inlined result schema at method root, found $ref: %#v" , rt )
329- }
330- }
331-
332- func TestInlineRefs_CrossPackage (t * testing.T ) {
333- t .Cleanup (func () { plugexpr .Root .UseJSONTags = false ; plugexpr .Root .InlineRefs = false })
334- docsMap := genDocs (t , func () {
335- InlineRefs ()
336- API ("Test" , func () {})
337- // Service "S1" uses a type from a different package.
338- Service ("S1" , func () {
339- Method ("M1" , func () {
340- Payload (testdata .CrossPackageType )
341- HTTP (func () { GET ("/" ) })
342- GRPC (func () {})
343- })
344- })
345- })
346-
347- svc := docsMap ["services" ].(map [string ]any )["S1" ].(map [string ]any )
348- methods := svc ["methods" ].(map [string ]any )
349- m1 := methods ["M1" ].(map [string ]any )
350- pt := m1 ["payload" ].(map [string ]any )["type" ].(map [string ]any )
351- if _ , hasRef := pt ["$ref" ]; hasRef {
352- t .Fatalf ("expected inlined payload schema for cross-package type, found $ref: %#v" , pt )
353- }
354- assert .Equal (t , "object" , pt ["type" ])
355- props := pt ["properties" ].(map [string ]any )
356- _ , hasA := props ["A" ]
357- assert .True (t , hasA )
358- }
359-
360- func TestInlineRefs_CrossService (t * testing.T ) {
361- t .Cleanup (func () { plugexpr .Root .UseJSONTags = false ; plugexpr .Root .InlineRefs = false })
362- docsMap := genDocs (t , func () {
363- InlineRefs ()
364- API ("Test" , func () {})
365- var SharedType = Type ("SharedType" , func () {
366- Field (1 , "A" , String )
367- Required ("A" )
368- })
369- Service ("S1" , func () {
370- Method ("M1" , func () {
371- Payload (SharedType )
372- HTTP (func () { GET ("/" ) })
373- GRPC (func () {})
374- })
375- })
376- Service ("S2" , func () {
377- Method ("M2" , func () {
378- Payload (SharedType )
379- HTTP (func () { GET ("/s2" ) })
380- GRPC (func () {})
381- })
382- })
383- })
384-
385- // Check S1
386- s1 := docsMap ["services" ].(map [string ]any )["S1" ].(map [string ]any )
387- m1 := s1 ["methods" ].(map [string ]any )["M1" ].(map [string ]any )
388- pt1 := m1 ["payload" ].(map [string ]any )["type" ].(map [string ]any )
389- if _ , hasRef := pt1 ["$ref" ]; hasRef {
390- t .Fatalf ("S1: expected inlined payload schema for shared type, found $ref: %#v" , pt1 )
391- }
392-
393- // Check S2
394- s2 := docsMap ["services" ].(map [string ]any )["S2" ].(map [string ]any )
395- m2 := s2 ["methods" ].(map [string ]any )["M2" ].(map [string ]any )
396- pt2 := m2 ["payload" ].(map [string ]any )["type" ].(map [string ]any )
397- if _ , hasRef := pt2 ["$ref" ]; hasRef {
398- t .Fatalf ("S2: expected inlined payload schema for shared type, found $ref: %#v" , pt2 )
399- }
400- }
0 commit comments