| 196 | } |
| 197 | |
| 198 | func TestDetect_LargeJSONNotOpenAPI(t *testing.T) { |
| 199 | // A huge JSON document that is not an OpenAPI spec must stay generic. |
| 200 | var b strings.Builder |
| 201 | b.WriteString(`{"name":"big","items":[`) |
| 202 | for i := 0; i < 5000; i++ { |
| 203 | if i > 0 { |
| 204 | b.WriteByte(',') |
| 205 | } |
| 206 | b.WriteString(`{"id":`) |
| 207 | b.WriteString(strings.Repeat("9", 20)) |
| 208 | b.WriteString(`,"value":"x"}`) |
| 209 | } |
| 210 | b.WriteString(`]}`) |
| 211 | body := []byte(b.String()) |
| 212 | if got := Detect("application/json", body); got != TypeGeneric { |
| 213 | t.Fatalf("Detect = %q, want %q for large non-OpenAPI JSON", got, TypeGeneric) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | func TestCanonicalMediaType(t *testing.T) { |
| 218 | tests := []struct { |