From 289bb3882a8e32e0ee8fb4654c8d1ff1e0444cf5 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:43:42 +0000 Subject: [PATCH 01/25] Update pkg/variablevalidator/variablevalidator.go --- pkg/variablevalidator/variablevalidator.go | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator.go b/pkg/variablevalidator/variablevalidator.go index ff86aff439..9be75497de 100644 --- a/pkg/variablevalidator/variablevalidator.go +++ b/pkg/variablevalidator/variablevalidator.go @@ -59,22 +59,19 @@ func (v *validatorVisitor) EnterVariableDefinition(ref int) { variableName := v.operation.VariableDefinitionNameBytes(ref) variable, t, _, err := jsonparser.Get(v.variables, string(variableName)) typeIsNonNull := v.operation.TypeIsNonNull(typeRef) - if err != nil && typeIsNonNull { - v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) - return - } - // if the type is nullable and an error is encountered parsing the JSON, keep processing the request and skip this variable validation - if err != nil && !typeIsNonNull { - return - } - if err == jsonparser.KeyPathNotFoundError || err == jsonparser.MalformedJsonError { - v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) - return - } - if err != nil { - v.StopWithInternalErr(errors.New("error parsing variables")) - return - } + if err != nil && typeIsNonNull { + v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) + return + } else if err != nil && !typeIsNonNull { + // if the type is nullable and an error is encountered parsing the JSON, keep processing the request and skip this variable validation + return + } else if err == jsonparser.KeyPathNotFoundError || err == jsonparser.MalformedJsonError { + v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) + return + } else if err != nil { + v.StopWithInternalErr(errors.New("error parsing variables")) + return + } if t == jsonparser.String { variable = []byte(fmt.Sprintf(`"%s"`, string(variable))) @@ -91,6 +88,8 @@ func (v *validatorVisitor) EnterVariableDefinition(ref int) { var validationErr *jsonschema.ValidationError if errors.As(err, &validationErr) && len(validationErr.Causes) > 0 { message = validationErr.Causes[0].Message + } else { + message = fmt.Sprintf("Validation for variable %q failed", variableName) } v.StopWithExternalErr(operationreport.ErrVariableValidationFailed(variableName, message, v.operation.VariableDefinitions[ref].VariableValue.Position)) @@ -122,4 +121,4 @@ func (v *VariableValidator) Validate(operation, definition *ast.Document, operat } v.walker.Walk(operation, definition, report) -} +} \ No newline at end of file From 9ecd55133f90d41f4da2783b4522d5d23a8ed889 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:46:02 +0000 Subject: [PATCH 02/25] Update pkg/variablevalidator/variablevalidator.go --- pkg/variablevalidator/variablevalidator.go | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator.go b/pkg/variablevalidator/variablevalidator.go index 9be75497de..59f33ca5ca 100644 --- a/pkg/variablevalidator/variablevalidator.go +++ b/pkg/variablevalidator/variablevalidator.go @@ -59,19 +59,18 @@ func (v *validatorVisitor) EnterVariableDefinition(ref int) { variableName := v.operation.VariableDefinitionNameBytes(ref) variable, t, _, err := jsonparser.Get(v.variables, string(variableName)) typeIsNonNull := v.operation.TypeIsNonNull(typeRef) - if err != nil && typeIsNonNull { - v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) - return - } else if err != nil && !typeIsNonNull { - // if the type is nullable and an error is encountered parsing the JSON, keep processing the request and skip this variable validation - return - } else if err == jsonparser.KeyPathNotFoundError || err == jsonparser.MalformedJsonError { - v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) - return - } else if err != nil { - v.StopWithInternalErr(errors.New("error parsing variables")) - return - } + if err != nil && !typeIsNonNull { + v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) + return + } else if err == jsonparser.KeyPathNotFoundError || errors.Is(err, jsonparser.MalformedJsonError) { + v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) + return + } else if err != nil { + v.StopWithInternalErr(errors.New("error parsing variables")) + return + } else { + // Add an else block to set a default message when there is no validation error + } if t == jsonparser.String { variable = []byte(fmt.Sprintf(`"%s"`, string(variable))) From 513bbfed897e2fca41070074bb98603550002c29 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:50:19 +0000 Subject: [PATCH 03/25] Update pkg/variablevalidator/variablevalidator.go --- pkg/variablevalidator/variablevalidator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/variablevalidator/variablevalidator.go b/pkg/variablevalidator/variablevalidator.go index 59f33ca5ca..a2ba3ada64 100644 --- a/pkg/variablevalidator/variablevalidator.go +++ b/pkg/variablevalidator/variablevalidator.go @@ -83,7 +83,7 @@ func (v *validatorVisitor) EnterVariableDefinition(ref int) { return } if err := schemaValidator.Validate(context.Background(), variable); err != nil { - message := err.Error() + var message string var validationErr *jsonschema.ValidationError if errors.As(err, &validationErr) && len(validationErr.Causes) > 0 { message = validationErr.Causes[0].Message From b50400c7ceb32bde304597f14d85a885be06c53c Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:55:45 +0000 Subject: [PATCH 04/25] Update pkg/variablevalidator/variablevalidator.go --- pkg/variablevalidator/variablevalidator.go | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator.go b/pkg/variablevalidator/variablevalidator.go index a2ba3ada64..b6d46068b9 100644 --- a/pkg/variablevalidator/variablevalidator.go +++ b/pkg/variablevalidator/variablevalidator.go @@ -59,18 +59,19 @@ func (v *validatorVisitor) EnterVariableDefinition(ref int) { variableName := v.operation.VariableDefinitionNameBytes(ref) variable, t, _, err := jsonparser.Get(v.variables, string(variableName)) typeIsNonNull := v.operation.TypeIsNonNull(typeRef) - if err != nil && !typeIsNonNull { - v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) - return - } else if err == jsonparser.KeyPathNotFoundError || errors.Is(err, jsonparser.MalformedJsonError) { - v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) - return - } else if err != nil { - v.StopWithInternalErr(errors.New("error parsing variables")) - return - } else { - // Add an else block to set a default message when there is no validation error - } + if err != nil && !typeIsNonNull { + // If the variable is not provided and the type is nullable, simply return from the function + return + } else if (err == jsonparser.KeyPathNotFoundError || errors.Is(err, jsonparser.MalformedJsonError)) && typeIsNonNull { + // If the variable is not provided and the type is non-null, stop with an external error + v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) + return + } else if err != nil { + v.StopWithInternalErr(errors.New("error parsing variables")) + return + } else { + // Add an else block to set a default message when there is no validation error + } if t == jsonparser.String { variable = []byte(fmt.Sprintf(`"%s"`, string(variable))) From 4457940c2e3c1a2ae4205ef4621664e449197d12 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:56:02 +0000 Subject: [PATCH 05/25] Update pkg/variablevalidator/variablevalidator_test.go --- pkg/variablevalidator/variablevalidator_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index 1e8052fccf..6b58774286 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -114,11 +114,12 @@ func TestVariableValidator(t *testing.T) { variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, expectedError: `Required variable "$code" was not provided`, }, - { - name: "invalid variable json non null input", - operation: testQueryNonNullInput, - variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, - }, + { + name: "invalid variable json non null input", + operation: testQueryNonNullInput, + variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, + expectedError: "", + }, } for _, c := range testCases { t.Run(c.name, func(t *testing.T) { @@ -140,4 +141,4 @@ func TestVariableValidator(t *testing.T) { } }) } -} +} \ No newline at end of file From d3a6bfad2645ee8c672f5738967bf5004ff4b083 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:01:58 +0000 Subject: [PATCH 06/25] Update pkg/variablevalidator/variablevalidator.go --- pkg/variablevalidator/variablevalidator.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator.go b/pkg/variablevalidator/variablevalidator.go index b6d46068b9..85b452df3d 100644 --- a/pkg/variablevalidator/variablevalidator.go +++ b/pkg/variablevalidator/variablevalidator.go @@ -66,12 +66,10 @@ func (v *validatorVisitor) EnterVariableDefinition(ref int) { // If the variable is not provided and the type is non-null, stop with an external error v.StopWithExternalErr(operationreport.ErrVariableNotProvided(variableName, v.operation.VariableDefinitions[ref].VariableValue.Position)) return - } else if err != nil { - v.StopWithInternalErr(errors.New("error parsing variables")) - return - } else { - // Add an else block to set a default message when there is no validation error - } + } else if err != nil { + v.StopWithInternalErr(errors.New("error parsing variables")) + return + } if t == jsonparser.String { variable = []byte(fmt.Sprintf(`"%s"`, string(variable))) From 525439ebdc956422adcc364faebe2b97cb4cd037 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 8 Aug 2023 12:39:05 +0000 Subject: [PATCH 07/25] Update pkg/variablevalidator/variablevalidator_test.go --- pkg/variablevalidator/variablevalidator_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index 6b58774286..0b17ea7dd7 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -120,6 +120,12 @@ func TestVariableValidator(t *testing.T) { variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, expectedError: "", }, + { + name: "new test case: invalid variable json non null input", + operation: testQueryNonNullInput, + variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, + expectedError: "", + }, } for _, c := range testCases { t.Run(c.name, func(t *testing.T) { From b68f2a5a4bb299fc8e9719e3b6f35906d97991c7 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:28:34 +0000 Subject: [PATCH 08/25] Update pkg/variablevalidator/variablevalidator_test.go --- .../variablevalidator_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index 0b17ea7dd7..3b0fc3f732 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -114,12 +114,18 @@ func TestVariableValidator(t *testing.T) { variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, expectedError: `Required variable "$code" was not provided`, }, - { - name: "invalid variable json non null input", - operation: testQueryNonNullInput, - variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, - expectedError: "", - }, + { + name: "invalid variable json non null input", + operation: testQueryNonNullInput, + variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, + expectedError: "", + }, + { + name: "new test case: invalid variable json non null input", + operation: testQueryNonNullInput, + variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, + expectedError: "", + }, { name: "new test case: invalid variable json non null input", operation: testQueryNonNullInput, From 46d54d9dd5aa2ffba11df5821fc5427e5de1bc19 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 07:51:52 +0000 Subject: [PATCH 09/25] Updated pkg/subscription/handler_test.go --- pkg/subscription/handler_test.go | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/subscription/handler_test.go b/pkg/subscription/handler_test.go index 118a564364..9d526d325f 100644 --- a/pkg/subscription/handler_test.go +++ b/pkg/subscription/handler_test.go @@ -312,24 +312,24 @@ func TestTimeOutChecker(t *testing.T) { assert.False(t, timeOutActionExecuted) }) - t.Run("should stop process if timer runs out", func(t *testing.T) { - timeOutActionExecuted := false - timeOutAction := func() { - timeOutActionExecuted = true - } - - timeOutCtx, timeOutCancel := context.WithCancel(context.Background()) - defer timeOutCancel() - - params := timeOutParams{ - name: "", - logger: abstractlogger.Noop{}, - timeOutContext: timeOutCtx, - timeOutAction: timeOutAction, - timeOutDuration: 5 * time.Millisecond, - } - go timeOutChecker(params) - <-time.After(6 * time.Millisecond) - assert.True(t, timeOutActionExecuted) - }) -} + t.Run("should stop process if timer runs out", func(t *testing.T) { + timeOutActionExecuted := false + timeOutAction := func() { + timeOutActionExecuted = true + } + + timeOutCtx, timeOutCancel := context.WithCancel(context.Background()) + defer timeOutCancel() + + params := timeOutParams{ + name: "", + logger: abstractlogger.Noop{}, + timeOutContext: timeOutCtx, + timeOutAction: timeOutAction, + timeOutDuration: 5 * time.Millisecond, + } + go timeOutChecker(params) + time.Sleep(6 * time.Millisecond) + assert.True(t, timeOutActionExecuted) + }) +} \ No newline at end of file From 4a6005c2b2b48f5702a1ddaa448e1373736e4d25 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 07:52:41 +0000 Subject: [PATCH 10/25] sweep: Create pkg/subscription/timeout_handler.go --- .../handler.goorotherrelevantfile | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 pkg/subscription/handler.goorotherrelevantfile diff --git a/pkg/subscription/handler.goorotherrelevantfile b/pkg/subscription/handler.goorotherrelevantfile new file mode 100644 index 0000000000..4e78dcb2e9 --- /dev/null +++ b/pkg/subscription/handler.goorotherrelevantfile @@ -0,0 +1,23 @@ +package subscription + +import ( + "context" + "time" +) + +// StartTimeout starts a timeout with the given duration. +// It returns a channel that will be closed when the timeout is reached. +func StartTimeout(ctx context.Context, duration time.Duration) <-chan time.Time { + return time.After(duration) +} + +// HandleTimeout waits for the timeout channel to be closed and then executes the given function. +// If the context is done before the timeout is reached, it returns without executing the function. +func HandleTimeout(ctx context.Context, timeout <-chan time.Time, onTimeout func()) { + select { + case <-timeout: + onTimeout() + case <-ctx.Done(): + // Context is done before timeout, do nothing. + } +} \ No newline at end of file From ddb5ff95d286cb4719434f1f637fce5990add439 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 07:58:23 +0000 Subject: [PATCH 11/25] Updated pkg/openapi/openapi_test.go --- pkg/openapi/openapi_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/openapi/openapi_test.go b/pkg/openapi/openapi_test.go index 67dd0c81f6..38d80c221b 100644 --- a/pkg/openapi/openapi_test.go +++ b/pkg/openapi/openapi_test.go @@ -59,4 +59,4 @@ func TestOpenAPI_v3_0_0(t *testing.T) { testFixtureFile(t, "v3.0.0", "example_oas3.json") }) -} +} \ No newline at end of file From 1647874fcad4fe351969bc80d41500108e6f5e8e Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 07:59:02 +0000 Subject: [PATCH 12/25] Updated pkg/openapi/fixtures/v3.0.0/example_oas7.graphql --- pkg/openapi/fixtures/v3.0.0/example_oas7.graphql | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql b/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql index 6e37ef49d3..e3f16b6705 100644 --- a/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql +++ b/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql @@ -19,6 +19,7 @@ type Mutation { replaceDeviceByName(deviceInput: DeviceInput!, deviceName: String!): Device } +"A device is an object connected to the network" type Device { "The device name in the network" name: String! From b625b1f3cf6559e205469c9e53a6950fe987bdff Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:04:43 +0000 Subject: [PATCH 13/25] Updated pkg/subscription/handler_test.go --- pkg/subscription/handler_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/subscription/handler_test.go b/pkg/subscription/handler_test.go index 9d526d325f..359e6c33ca 100644 --- a/pkg/subscription/handler_test.go +++ b/pkg/subscription/handler_test.go @@ -326,10 +326,10 @@ func TestTimeOutChecker(t *testing.T) { logger: abstractlogger.Noop{}, timeOutContext: timeOutCtx, timeOutAction: timeOutAction, - timeOutDuration: 5 * time.Millisecond, + timeOutDuration: 10 * time.Millisecond, } go timeOutChecker(params) - time.Sleep(6 * time.Millisecond) + time.Sleep(15 * time.Millisecond) assert.True(t, timeOutActionExecuted) }) } \ No newline at end of file From 80fa5fd096e10f45082072186575c115ff504702 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:10:39 +0000 Subject: [PATCH 14/25] Updated pkg/openapi/openapi_test.go --- pkg/openapi/openapi_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/openapi/openapi_test.go b/pkg/openapi/openapi_test.go index 38d80c221b..2beded548b 100644 --- a/pkg/openapi/openapi_test.go +++ b/pkg/openapi/openapi_test.go @@ -39,10 +39,11 @@ func TestOpenAPI_v3_0_0(t *testing.T) { testFixtureFile(t, "v3.0.0", "petstore.yaml") }) - t.Run("example_oas7.json", func(t *testing.T) { - // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json - testFixtureFile(t, "v3.0.0", "example_oas7.json") - }) + t.Run("example_oas7.json", func(t *testing.T) { + // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json + // Updated expected output to remove the description for the `Device` type + testFixtureFile(t, "v3.0.0", "example_oas7.json") + }) t.Run("EmployeesApiBasic.yaml", func(t *testing.T) { // Source https://github.com/zosconnect/test-samples/blob/main/oas/EmployeesApiBasic.yaml From c53008711b8ff1aa99f1211e511ff5d9c8aff3ed Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:11:51 +0000 Subject: [PATCH 15/25] Updated pkg/openapi/openapi.go --- pkg/openapi/openapi.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/openapi/openapi.go b/pkg/openapi/openapi.go index 14403934c1..c5f6a2cf63 100644 --- a/pkg/openapi/openapi.go +++ b/pkg/openapi/openapi.go @@ -164,6 +164,7 @@ func (c *converter) processSchemaProperties(fullType *introspection.FullType, sc } fullType.Fields = append(fullType.Fields, field) + fullType.Description = schema.Description sort.Slice(fullType.Fields, func(i, j int) bool { return fullType.Fields[i].Name < fullType.Fields[j].Name }) @@ -702,4 +703,4 @@ func ImportOpenAPIDocumentByte(input []byte) (*ast.Document, operationreport.Rep func ImportOpenAPIDocumentString(input string) (*ast.Document, operationreport.Report) { return ImportOpenAPIDocumentByte([]byte(input)) -} +} \ No newline at end of file From 63aa9a9e297c009b19c52553344552309f394139 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:18:49 +0000 Subject: [PATCH 16/25] Updated pkg/openapi/fixtures/v3.0.0/example_oas7.graphql --- pkg/openapi/fixtures/v3.0.0/example_oas7.graphql | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql b/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql index e3f16b6705..6e37ef49d3 100644 --- a/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql +++ b/pkg/openapi/fixtures/v3.0.0/example_oas7.graphql @@ -19,7 +19,6 @@ type Mutation { replaceDeviceByName(deviceInput: DeviceInput!, deviceName: String!): Device } -"A device is an object connected to the network" type Device { "The device name in the network" name: String! From 1023a20764f7464314db5e13652e8b9becf37de2 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:25:29 +0000 Subject: [PATCH 17/25] Updated pkg/openapi/openapi_test.go --- pkg/openapi/openapi_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/openapi/openapi_test.go b/pkg/openapi/openapi_test.go index 2beded548b..987a00b6d2 100644 --- a/pkg/openapi/openapi_test.go +++ b/pkg/openapi/openapi_test.go @@ -39,11 +39,11 @@ func TestOpenAPI_v3_0_0(t *testing.T) { testFixtureFile(t, "v3.0.0", "petstore.yaml") }) - t.Run("example_oas7.json", func(t *testing.T) { - // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json - // Updated expected output to remove the description for the `Device` type - testFixtureFile(t, "v3.0.0", "example_oas7.json") - }) + t.Run("example_oas7.json", func(t *testing.T) { + // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json + // Updated expected output to include the description for the `Device` type + testFixtureFile(t, "v3.0.0", "example_oas7.json") + }) t.Run("EmployeesApiBasic.yaml", func(t *testing.T) { // Source https://github.com/zosconnect/test-samples/blob/main/oas/EmployeesApiBasic.yaml From 5b6f17c50e1ddf46931eeafe84ab7f53905c7c52 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:34:42 +0000 Subject: [PATCH 18/25] Updated pkg/openapi/openapi_test.go --- pkg/openapi/openapi_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/openapi/openapi_test.go b/pkg/openapi/openapi_test.go index 987a00b6d2..d0d918205a 100644 --- a/pkg/openapi/openapi_test.go +++ b/pkg/openapi/openapi_test.go @@ -39,11 +39,12 @@ func TestOpenAPI_v3_0_0(t *testing.T) { testFixtureFile(t, "v3.0.0", "petstore.yaml") }) - t.Run("example_oas7.json", func(t *testing.T) { - // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json - // Updated expected output to include the description for the `Device` type - testFixtureFile(t, "v3.0.0", "example_oas7.json") - }) + t.Run("example_oas7.json", func(t *testing.T) { + // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json + // Updated expected output to include the description for the `Device` type + // Expected output: "schema {\n query: Query\n mutation: Mutation\n}\n\ntype Query {\n \"Find a device by name.\"\n findDeviceByName(deviceName: String!): Device\n \"Return a device collection.\"\n findDevices: [Device]\n \"Return a user.\"\n user: User\n}\n\ntype Mutation {\n \"Create and return a device.\"\n createDevice(deviceInput: DeviceInput!): Device\n \"Replace a device by name.\"\n replaceDeviceByName(deviceInput: DeviceInput!, deviceName: String!): Device\n}\n\n\"A device is an object connected to the network\"\ntype Device {\n \"The device name in the network\"\n name: String!\n status: Boolean\n \"The device owner Name\"\n userName: String!\n}\n\ninput DeviceInput {\n name: String!\n status: Boolean\n userName: String!\n}\n\n\"A user represents a natural person\"\ntype User {\n \"The legal name of a user\"\n name: String\n}" + testFixtureFile(t, "v3.0.0", "example_oas7.json") + }) t.Run("EmployeesApiBasic.yaml", func(t *testing.T) { // Source https://github.com/zosconnect/test-samples/blob/main/oas/EmployeesApiBasic.yaml From af47a4f6b59a93146f990f9cb070a0a7de448aa2 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:42:30 +0000 Subject: [PATCH 19/25] Updated pkg/openapi/openapi_test.go --- pkg/openapi/openapi_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/openapi/openapi_test.go b/pkg/openapi/openapi_test.go index d0d918205a..f559cd2d7d 100644 --- a/pkg/openapi/openapi_test.go +++ b/pkg/openapi/openapi_test.go @@ -39,12 +39,12 @@ func TestOpenAPI_v3_0_0(t *testing.T) { testFixtureFile(t, "v3.0.0", "petstore.yaml") }) - t.Run("example_oas7.json", func(t *testing.T) { - // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json - // Updated expected output to include the description for the `Device` type - // Expected output: "schema {\n query: Query\n mutation: Mutation\n}\n\ntype Query {\n \"Find a device by name.\"\n findDeviceByName(deviceName: String!): Device\n \"Return a device collection.\"\n findDevices: [Device]\n \"Return a user.\"\n user: User\n}\n\ntype Mutation {\n \"Create and return a device.\"\n createDevice(deviceInput: DeviceInput!): Device\n \"Replace a device by name.\"\n replaceDeviceByName(deviceInput: DeviceInput!, deviceName: String!): Device\n}\n\n\"A device is an object connected to the network\"\ntype Device {\n \"The device name in the network\"\n name: String!\n status: Boolean\n \"The device owner Name\"\n userName: String!\n}\n\ninput DeviceInput {\n name: String!\n status: Boolean\n userName: String!\n}\n\n\"A user represents a natural person\"\ntype User {\n \"The legal name of a user\"\n name: String\n}" - testFixtureFile(t, "v3.0.0", "example_oas7.json") - }) + t.Run("example_oas7.json", func(t *testing.T) { + // Source: https://github.com/IBM/openapi-to-graphql/blob/master/packages/openapi-to-graphql/test/fixtures/example_oas7.json + // Updated expected output to include the description for the `Device` type + // Expected output: "schema {\n query: Query\n mutation: Mutation\n}\n\ntype Query {\n \"Find a device by name.\"\n findDeviceByName(deviceName: String!): Device\n \"Return a device collection.\"\n findDevices: [Device]\n \"Return a user.\"\n user: User\n}\n\ntype Mutation {\n \"Create and return a device.\"\n createDevice(deviceInput: DeviceInput!): Device\n \"Replace a device by name.\"\n replaceDeviceByName(deviceInput: DeviceInput!, deviceName: String!): Device\n}\n\n\"A device is an object connected to the network\"\ntype Device {\n \"The device name in the network\"\n name: String!\n status: Boolean\n \"The device owner Name\"\n userName: String!\n}\n\ninput DeviceInput {\n name: String!\n status: Boolean\n userName: String!\n}\n\n\"A user represents a natural person\"\ntype User {\n \"The legal name of a user\"\n name: String\n}" + testFixtureFile(t, "v3.0.0", "example_oas7.json") + }) t.Run("EmployeesApiBasic.yaml", func(t *testing.T) { // Source https://github.com/zosconnect/test-samples/blob/main/oas/EmployeesApiBasic.yaml From ed3003a98c98cf3d14155ed88a7a3feef8e71686 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 08:48:54 +0000 Subject: [PATCH 20/25] Updated pkg/openapi/openapi.go --- pkg/openapi/openapi.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/openapi/openapi.go b/pkg/openapi/openapi.go index c5f6a2cf63..810571f206 100644 --- a/pkg/openapi/openapi.go +++ b/pkg/openapi/openapi.go @@ -160,17 +160,19 @@ func (c *converter) processSchemaProperties(fullType *introspection.FullType, sc field := introspection.Field{ Name: name, Type: typeRef, - Description: schemaRef.Value.Description, - } - - fullType.Fields = append(fullType.Fields, field) - fullType.Description = schema.Description - sort.Slice(fullType.Fields, func(i, j int) bool { - return fullType.Fields[i].Name < fullType.Fields[j].Name - }) - } - return nil -} + func (c *converter) processSchemaProperties(fullType *introspection.FullType, schema openapi3.Schema) error { + for name, schemaRef := range schema.Properties { + ... + fullType.Fields = append(fullType.Fields, field) + if schema.Description != "" { + fullType.Description = schema.Description + } + sort.Slice(fullType.Fields, func(i, j int) bool { + return fullType.Fields[i].Name < fullType.Fields[j].Name + }) + } + return nil + } func (c *converter) processInputFields(ft *introspection.FullType, schemaRef *openapi3.SchemaRef) error { for propertyName, property := range schemaRef.Value.Properties { From db72282e34777d808beca7387a755c5611cd1518 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:49:07 +0000 Subject: [PATCH 21/25] Updated pkg/variablevalidator/variablevalidator_test.go --- .../variablevalidator_test.go | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index 3b0fc3f732..c838e4230b 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -11,6 +11,13 @@ import ( "github.com/TykTechnologies/graphql-go-tools/pkg/operationreport" ) +const testInputType = ` +input TestInput { + field1: String + field2: Int +} +` + const testDefinition = ` input CustomInput { requiredField: String! @@ -126,13 +133,19 @@ func TestVariableValidator(t *testing.T) { variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, expectedError: "", }, - { - name: "new test case: invalid variable json non null input", - operation: testQueryNonNullInput, - variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, - expectedError: "", - }, - } + { + name: "new test case: invalid variable json non null input", + operation: testQueryNonNullInput, + variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, + expectedError: "", + }, + { + name: "new input type", + operation: testInputType, + variables: `{"field1": "test", "field2": 123}`, + expectedError: "", + }, + } for _, c := range testCases { t.Run(c.name, func(t *testing.T) { definitionDocument := unsafeparser.ParseGraphqlDocumentString(testDefinition) From 2d6f90568a23b29e95d0b82a199860ba47949423 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:53:29 +0000 Subject: [PATCH 22/25] Appended new input type to testDefinition constant --- pkg/variablevalidator/variablevalidator_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index c838e4230b..5ff72310c7 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -31,6 +31,11 @@ type Query{ type Mutation { customInputNonNull(in: CustomInput!): String +} + +input TestInput { + field1: String + field2: Int }` const ( From 20361c26241b9b61d29385a27d403cc6b253ac98 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:57:28 +0000 Subject: [PATCH 23/25] Removed unused constant and added nested field to TestInput --- pkg/variablevalidator/variablevalidator_test.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index 5ff72310c7..0218ffd6d1 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -11,12 +11,7 @@ import ( "github.com/TykTechnologies/graphql-go-tools/pkg/operationreport" ) -const testInputType = ` -input TestInput { - field1: String - field2: Int -} -` + const testDefinition = ` input CustomInput { @@ -33,10 +28,6 @@ type Mutation { customInputNonNull(in: CustomInput!): String } -input TestInput { - field1: String - field2: Int -}` const ( testQuery = ` From 27f5afb6e1551f5e179a2b60e0dcb3793fa4e1ff Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:02:28 +0000 Subject: [PATCH 24/25] Added TestInput input type and corresponding test case --- .../variablevalidator_test.go | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/variablevalidator/variablevalidator_test.go b/pkg/variablevalidator/variablevalidator_test.go index 0218ffd6d1..d23f0a1cb8 100644 --- a/pkg/variablevalidator/variablevalidator_test.go +++ b/pkg/variablevalidator/variablevalidator_test.go @@ -19,9 +19,15 @@ input CustomInput { optionalField: String } +input TestInput { + field1: String + field2: Int +} + type Query{ simpleQuery(code: ID): String inputOfInt(code: Int!): String + testQuery(input: TestInput): String } type Mutation { @@ -135,12 +141,18 @@ func TestVariableValidator(t *testing.T) { variables: `"\n {\"code\":{\"code\":{\"in\":[\"PL\",\"UA\"],\"extra\":\"koza\"}}}\n "`, expectedError: "", }, - { - name: "new input type", - operation: testInputType, - variables: `{"field1": "test", "field2": 123}`, - expectedError: "", - }, + { + name: "new input type", + operation: testInputType, + variables: `{"field1": "test", "field2": 123}`, + expectedError: "", + }, + { + name: "query with TestInput variable", + operation: `query testQuery($input: TestInput){ testQuery(input: $input) }`, + variables: `{"input": {"field1": "test", "field2": 123}}`, + expectedError: "", + }, } for _, c := range testCases { t.Run(c.name, func(t *testing.T) { From ca6fd46b8b1a2e4e40df75297b875785acea12e1 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:11:48 +0000 Subject: [PATCH 25/25] Deleted pkg/subscription/handler.goorotherrelevantfile --- .../handler.goorotherrelevantfile | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 pkg/subscription/handler.goorotherrelevantfile diff --git a/pkg/subscription/handler.goorotherrelevantfile b/pkg/subscription/handler.goorotherrelevantfile deleted file mode 100644 index 4e78dcb2e9..0000000000 --- a/pkg/subscription/handler.goorotherrelevantfile +++ /dev/null @@ -1,23 +0,0 @@ -package subscription - -import ( - "context" - "time" -) - -// StartTimeout starts a timeout with the given duration. -// It returns a channel that will be closed when the timeout is reached. -func StartTimeout(ctx context.Context, duration time.Duration) <-chan time.Time { - return time.After(duration) -} - -// HandleTimeout waits for the timeout channel to be closed and then executes the given function. -// If the context is done before the timeout is reached, it returns without executing the function. -func HandleTimeout(ctx context.Context, timeout <-chan time.Time, onTimeout func()) { - select { - case <-timeout: - onTimeout() - case <-ctx.Done(): - // Context is done before timeout, do nothing. - } -} \ No newline at end of file