@@ -691,3 +691,137 @@ func TestInvalidCookieParamNumber(t *testing.T) {
691691 require .Contains (t , err .Reason , "The cookie parameter 'cookies' is defined as being a number" )
692692 require .Contains (t , err .HowToFix , "milky" )
693693}
694+
695+ func TestIncorrectCookieParamBool (t * testing.T ) {
696+
697+ enum := `name: blip`
698+ var n yaml.Node
699+ _ = yaml .Unmarshal ([]byte (enum ), & n )
700+
701+ schemaProxy := & lowbase.SchemaProxy {}
702+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
703+
704+ highSchema := base .NewSchema (schemaProxy .Schema ())
705+ param := createMockParameter ()
706+ param .Name = "cookies"
707+
708+ err := IncorrectCookieParamBool (param , "milky" , highSchema )
709+
710+ // Validate the error
711+ require .NotNil (t , err )
712+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
713+ require .Equal (t , helpers .ParameterValidationCookie , err .ValidationSubType )
714+ require .Contains (t , err .Message , "Cookie parameter 'cookies' is not a valid boolean" )
715+ require .Contains (t , err .Reason , "The cookie parameter 'cookies' is defined as being a boolean" )
716+ require .Contains (t , err .HowToFix , "milky" )
717+ }
718+
719+ func TestIncorrectCookieParamEnum (t * testing.T ) {
720+
721+ enum := `items:
722+ enum: [fish, crab, lobster]`
723+ var n yaml.Node
724+ _ = yaml .Unmarshal ([]byte (enum ), & n )
725+
726+ schemaProxy := & lowbase.SchemaProxy {}
727+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
728+
729+ highSchema := base .NewSchema (schemaProxy .Schema ())
730+ param := createMockParameter ()
731+ param .Schema = base .CreateSchemaProxy (highSchema )
732+ param .GoLow ().Schema .Value = schemaProxy
733+ param .GoLow ().Schema .Value .Schema ().Enum .Value = []low.ValueReference [* yaml.Node ]{
734+ {Value : & yaml.Node {Value : "fish, crab, lobster" }},
735+ }
736+ param .GoLow ().Schema .Value .Schema ().Enum .KeyNode = & yaml.Node {}
737+
738+ err := IncorrectCookieParamEnum (param , "milky" , highSchema )
739+
740+ // Validate the error
741+ require .NotNil (t , err )
742+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
743+ require .Equal (t , helpers .ParameterValidationCookie , err .ValidationSubType )
744+ require .Contains (t , err .Message , "Cookie parameter 'testQueryParam' does not match allowed values" )
745+ require .Contains (t , err .Reason , "The cookie parameter 'testQueryParam' has pre-defined values set via an enum" )
746+ require .Contains (t , err .HowToFix , "milky" )
747+ }
748+
749+ func TestIncorrectHeaderParamArrayBoolean (t * testing.T ) {
750+
751+ items := `items:
752+ type: boolean`
753+ var n yaml.Node
754+ _ = yaml .Unmarshal ([]byte (items ), & n )
755+
756+ schemaProxy := & lowbase.SchemaProxy {}
757+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
758+
759+ highSchema := base .NewSchema (schemaProxy .Schema ())
760+ highSchema .GoLow ().Items .Value .A .Schema ()
761+
762+ param := createMockParameter ()
763+ param .Name = "bubbles"
764+
765+ err := IncorrectHeaderParamArrayBoolean (param , "milky" , highSchema , nil )
766+
767+ // Validate the error
768+ require .NotNil (t , err )
769+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
770+ require .Equal (t , helpers .ParameterValidationHeader , err .ValidationSubType )
771+ require .Contains (t , err .Message , "Header array parameter 'bubbles' is not a valid boolean" )
772+ require .Contains (t , err .Reason , "The header parameter (which is an array) 'bubbles' is defined as being a boolean" )
773+ require .Contains (t , err .HowToFix , "milky" )
774+ }
775+
776+ func TestIncorrectHeaderParamArrayNumber (t * testing.T ) {
777+
778+ items := `items:
779+ type: number`
780+ var n yaml.Node
781+ _ = yaml .Unmarshal ([]byte (items ), & n )
782+
783+ schemaProxy := & lowbase.SchemaProxy {}
784+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
785+
786+ highSchema := base .NewSchema (schemaProxy .Schema ())
787+ highSchema .GoLow ().Items .Value .A .Schema ()
788+
789+ param := createMockParameter ()
790+ param .Name = "bubbles"
791+
792+ err := IncorrectHeaderParamArrayNumber (param , "milky" , highSchema , nil )
793+
794+ // Validate the error
795+ require .NotNil (t , err )
796+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
797+ require .Equal (t , helpers .ParameterValidationHeader , err .ValidationSubType )
798+ require .Contains (t , err .Message , "Header array parameter 'bubbles' is not a valid number" )
799+ require .Contains (t , err .Reason , "The header parameter (which is an array) 'bubbles' is defined as being a number" )
800+ require .Contains (t , err .HowToFix , "milky" )
801+ }
802+
803+ func TestIncorrectPathParamBool (t * testing.T ) {
804+
805+ items := `items:
806+ type: number`
807+ var n yaml.Node
808+ _ = yaml .Unmarshal ([]byte (items ), & n )
809+
810+ schemaProxy := & lowbase.SchemaProxy {}
811+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
812+
813+ highSchema := base .NewSchema (schemaProxy .Schema ())
814+ param := createMockParameter ()
815+ param .Schema = base .CreateSchemaProxy (highSchema )
816+ param .GoLow ().Schema .KeyNode = & yaml.Node {}
817+
818+ err := IncorrectPathParamBool (param , "milky" , highSchema )
819+
820+ // Validate the error
821+ require .NotNil (t , err )
822+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
823+ require .Equal (t , helpers .ParameterValidationPath , err .ValidationSubType )
824+ require .Contains (t , err .Message , "Path parameter 'testQueryParam' is not a valid boolean" )
825+ require .Contains (t , err .Reason , "The path parameter 'testQueryParam' is defined as being a boolean" )
826+ require .Contains (t , err .HowToFix , "milky" )
827+ }
0 commit comments