@@ -465,6 +465,9 @@ func createMockParameter() *v3.Parameter {
465465 KeyNode : & yaml.Node {},
466466 ValueNode : & yaml.Node {},
467467 },
468+ Required : low.NodeReference [bool ]{
469+ KeyNode : & yaml.Node {},
470+ },
468471 }
469472 return v3 .NewParameter (param )
470473}
@@ -825,3 +828,139 @@ func TestIncorrectPathParamBool(t *testing.T) {
825828 require .Contains (t , err .Reason , "The path parameter 'testQueryParam' is defined as being a boolean" )
826829 require .Contains (t , err .HowToFix , "milky" )
827830}
831+
832+ func TestIncorrectPathParamEnum (t * testing.T ) {
833+ items := `items:
834+ enum: [fish, crab, lobster]`
835+
836+ var n yaml.Node
837+ _ = yaml .Unmarshal ([]byte (items ), & n )
838+
839+ schemaProxy := & lowbase.SchemaProxy {}
840+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
841+
842+ highSchema := base .NewSchema (schemaProxy .Schema ())
843+ param := createMockParameter ()
844+ param .Schema = base .CreateSchemaProxy (highSchema )
845+ param .GoLow ().Schema .Value = schemaProxy
846+ param .GoLow ().Schema .Value .Schema ().Enum .Value = []low.ValueReference [* yaml.Node ]{
847+ {Value : & yaml.Node {Value : "fish, crab, lobster" }},
848+ }
849+ param .GoLow ().Schema .Value .Schema ().Enum .KeyNode = & yaml.Node {}
850+
851+ err := IncorrectPathParamEnum (param , "milky" , highSchema )
852+
853+ // Validate the error
854+ require .NotNil (t , err )
855+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
856+ require .Equal (t , helpers .ParameterValidationPath , err .ValidationSubType )
857+ require .Contains (t , err .Message , "Path parameter 'testQueryParam' does not match allowed values" )
858+ require .Contains (t , err .Reason , "The path parameter 'testQueryParam' has pre-defined values set via an enum" )
859+ require .Contains (t , err .HowToFix , "milky" )
860+ }
861+
862+ func TestIncorrectPathParamNumber (t * testing.T ) {
863+
864+ items := `items:
865+ type: number`
866+ var n yaml.Node
867+ _ = yaml .Unmarshal ([]byte (items ), & n )
868+
869+ schemaProxy := & lowbase.SchemaProxy {}
870+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
871+
872+ highSchema := base .NewSchema (schemaProxy .Schema ())
873+ param := createMockParameter ()
874+ param .Schema = base .CreateSchemaProxy (highSchema )
875+ param .GoLow ().Schema .KeyNode = & yaml.Node {}
876+
877+ err := IncorrectPathParamNumber (param , "milky" , highSchema )
878+
879+ // Validate the error
880+ require .NotNil (t , err )
881+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
882+ require .Equal (t , helpers .ParameterValidationPath , err .ValidationSubType )
883+ require .Contains (t , err .Message , "Path parameter 'testQueryParam' is not a valid number" )
884+ require .Contains (t , err .Reason , "The path parameter 'testQueryParam' is defined as being a number" )
885+ require .Contains (t , err .HowToFix , "milky" )
886+ }
887+
888+ func TestIncorrectPathParamArrayNumber (t * testing.T ) {
889+
890+ items := `items:
891+ type: number`
892+ var n yaml.Node
893+ _ = yaml .Unmarshal ([]byte (items ), & n )
894+
895+ schemaProxy := & lowbase.SchemaProxy {}
896+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
897+
898+ highSchema := base .NewSchema (schemaProxy .Schema ())
899+ highSchema .GoLow ().Items .Value .A .Schema ()
900+
901+ param := createMockParameter ()
902+ param .Name = "bubbles"
903+
904+ err := IncorrectPathParamArrayNumber (param , "milky" , highSchema , nil )
905+
906+ // Validate the error
907+ require .NotNil (t , err )
908+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
909+ require .Equal (t , helpers .ParameterValidationPath , err .ValidationSubType )
910+ require .Contains (t , err .Message , "Path array parameter 'bubbles' is not a valid number" )
911+ require .Contains (t , err .Reason , "The path parameter (which is an array) 'bubbles' is defined as being a number" )
912+ require .Contains (t , err .HowToFix , "milky" )
913+ }
914+
915+ func TestIncorrectPathParamArrayBoolean (t * testing.T ) {
916+
917+ items := `items:
918+ type: number`
919+ var n yaml.Node
920+ _ = yaml .Unmarshal ([]byte (items ), & n )
921+
922+ schemaProxy := & lowbase.SchemaProxy {}
923+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
924+
925+ highSchema := base .NewSchema (schemaProxy .Schema ())
926+ highSchema .GoLow ().Items .Value .A .Schema ()
927+
928+ param := createMockParameter ()
929+ param .Name = "bubbles"
930+
931+ err := IncorrectPathParamArrayBoolean (param , "milky" , highSchema , nil )
932+
933+ // Validate the error
934+ require .NotNil (t , err )
935+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
936+ require .Equal (t , helpers .ParameterValidationPath , err .ValidationSubType )
937+ require .Contains (t , err .Message , "Path array parameter 'bubbles' is not a valid boolean" )
938+ require .Contains (t , err .Reason , "The path parameter (which is an array) 'bubbles' is defined as being a boolean" )
939+ require .Contains (t , err .HowToFix , "milky" )
940+ }
941+
942+ func TestPathParameterMissing (t * testing.T ) {
943+
944+ items := `required:
945+ - testQueryParam`
946+ var n yaml.Node
947+ _ = yaml .Unmarshal ([]byte (items ), & n )
948+
949+ schemaProxy := & lowbase.SchemaProxy {}
950+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
951+
952+ highSchema := base .NewSchema (schemaProxy .Schema ())
953+ param := createMockParameter ()
954+ param .Schema = base .CreateSchemaProxy (highSchema )
955+ param .GoLow ().Schema .KeyNode = & yaml.Node {}
956+
957+ err := PathParameterMissing (param )
958+
959+ // Validate the error
960+ require .NotNil (t , err )
961+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
962+ require .Equal (t , helpers .ParameterValidationPath , err .ValidationSubType )
963+ require .Contains (t , err .Message , "Path parameter 'testQueryParam' is missing" )
964+ require .Contains (t , err .Reason , "The path parameter 'testQueryParam' is defined as being required" )
965+ require .Contains (t , err .HowToFix , "Ensure the value has been set" )
966+ }
0 commit comments