MCPcopy
hub / github.com/zeromicro/go-zero / TestArrayWithoutDefinitions

Function TestArrayWithoutDefinitions

tools/goctl/api/swagger/swagger_test.go:89–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestArrayWithoutDefinitions(t *testing.T) {
90 // Test that arrays work correctly when useDefinitions is false
91 ctx := Context{
92 UseDefinitions: false, // This is the default
93 }
94
95 // Create the same test struct
96 testStruct := spec.DefineStruct{
97 RawName: "TestStruct",
98 Members: []spec.Member{
99 {
100 Name: "ArrayField",
101 Type: spec.ArrayType{
102 Value: spec.DefineStruct{
103 RawName: "ItemStruct",
104 Members: []spec.Member{
105 {
106 Name: "ItemName",
107 Type: spec.PrimitiveType{RawName: "string"},
108 Tag: `json:"itemName"`,
109 },
110 },
111 },
112 },
113 Tag: `json:"arrayField"`,
114 },
115 },
116 }
117
118 properties, _ := propertiesFromType(ctx, testStruct)
119
120 assert.Contains(t, properties, "arrayField")
121 arrayField := properties["arrayField"]
122
123 // Should be array type
124 assert.Equal(t, "array", arrayField.Type[0])
125
126 // Should have items with full schema, no $ref
127 assert.NotNil(t, arrayField.Items)
128 assert.NotNil(t, arrayField.Items.Schema)
129
130 // Should NOT have $ref at schema level
131 assert.Empty(t, arrayField.Ref.String(), "Schema should not have $ref when useDefinitions is false")
132
133 // Should NOT have $ref in items either
134 assert.Empty(t, arrayField.Items.Schema.Ref.String(), "Items should not have $ref when useDefinitions is false")
135
136 // Should have full schema properties in items
137 assert.Equal(t, "object", arrayField.Items.Schema.Type[0])
138 assert.Contains(t, arrayField.Items.Schema.Properties, "itemName")
139 assert.Equal(t, []string{"itemName"}, arrayField.Items.Schema.Required)
140}

Callers

nothing calls this directly

Calls 6

propertiesFromTypeFunction · 0.85
NotNilMethod · 0.80
EmptyMethod · 0.80
EqualMethod · 0.65
ContainsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…