@@ -274,6 +274,7 @@ func TestEstimateMaxLengthJSON(t *testing.T) {
274274 Name string
275275 InputSchema * schema.Structural
276276 ExpectedMaxElements int64
277+ ExpectNilType bool
277278 }
278279 tests := []maxLengthTest {
279280 {
@@ -499,13 +500,61 @@ func TestEstimateMaxLengthJSON(t *testing.T) {
499500 // so we expect the max length to be exactly equal to the user-supplied one
500501 ExpectedMaxElements : 20 ,
501502 },
503+ {
504+ Name : "Property under array" ,
505+ InputSchema : & schema.Structural {
506+ Generic : schema.Generic {
507+ Type : "array" ,
508+ },
509+ Properties : map [string ]schema.Structural {
510+ "field" : {
511+ Generic : schema.Generic {
512+ Type : "string" ,
513+ Default : schema.JSON {Object : "default" },
514+ },
515+ },
516+ },
517+ },
518+ // Got nil for delType
519+ ExpectedMaxElements : 0 ,
520+ ExpectNilType : true ,
521+ },
522+ {
523+ Name : "Items under object" ,
524+ InputSchema : & schema.Structural {
525+ Generic : schema.Generic {
526+ Type : "object" ,
527+ },
528+ Items : & schema.Structural {
529+ Generic : schema.Generic {
530+ Type : "array" ,
531+ },
532+ Properties : map [string ]schema.Structural {
533+ "field" : {
534+ Generic : schema.Generic {
535+ Type : "string" ,
536+ Default : schema.JSON {Object : "default" },
537+ },
538+ },
539+ },
540+ ValueValidation : & schema.ValueValidation {
541+ Required : []string {"field" },
542+ },
543+ },
544+ },
545+ // Skip items under object for schema conversion.
546+ ExpectedMaxElements : 0 ,
547+ },
502548 }
503549 for _ , testCase := range tests {
504550 t .Run (testCase .Name , func (t * testing.T ) {
505551 decl := SchemaDeclType (testCase .InputSchema , false )
506- if decl .MaxElements != testCase .ExpectedMaxElements {
552+ if decl != nil && decl .MaxElements != testCase .ExpectedMaxElements {
507553 t .Errorf ("wrong maxElements (got %d, expected %d)" , decl .MaxElements , testCase .ExpectedMaxElements )
508554 }
555+ if testCase .ExpectNilType && decl != nil {
556+ t .Errorf ("expected nil type, got %v" , decl )
557+ }
509558 })
510559 }
511560}
0 commit comments