nebulab / cangaroo

Connect Any App to Any Service
https://github.com/nebulab/cangaroo
MIT License
107 stars 18 forks source link

Fix validate json schema #32

Closed AlessioRocco closed 8 years ago

AlessioRocco commented 8 years ago

Related to this issue https://github.com/nebulab/cangaroo/issues/22. Update the json validator to accept an extra parameter (parameters) that can be present when data come from a remote connection.

bricesanchez commented 8 years ago

I'm not sure this PR fix #22. I've the same error than before :

➜  acc-001-api git:(master) ✗ rake cangaroo:poll
Running via Spring preloader in process 3584
I, [2016-05-20T08:58:19.134407 #3584]  INFO -- : initiating poll: job=Cangaroo::GetProducts job_id=8656d9e7-6f43-4316-b503-c2ef46f2d48a connection=chaindrive last_poll=0
I, [2016-05-20T08:58:23.775910 #3584]  INFO -- : processing poll results: job=Cangaroo::GetProducts job_id=8656d9e7-6f43-4316-b503-c2ef46f2d48a connection=chaindrive
rake aborted!
Cangaroo::Webhook::Error: The property '#/' contains additional properties ["request_id"] outside of the schema when none are allowed in schema Cangaroo Object#, The property '#/summary' of type String did not match the following type: array in schema Cangaroo Object#
/Users/bci20/Sites/acc-001-api/app/jobs/cangaroo/poll_job.rb:39:in `perform'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/execution.rb:32:in `block in perform_now'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:117:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/translation.rb:7:in `block (2 levels) in <module:Translation>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `instance_exec'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:342:in `block in simple'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:497:in `block in around'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:23:in `block (4 levels) in <module:Logging>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:22:in `block (3 levels) in <module:Logging>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `block in tag_logger'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `tagged'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `tag_logger'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:19:in `block (2 levels) in <module:Logging>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `instance_exec'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:342:in `block in simple'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:497:in `block in around'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_perform_callbacks'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/execution.rb:31:in `perform_now'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/execution.rb:21:in `execute'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/queue_adapters/inline_adapter.rb:14:in `enqueue'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/enqueuing.rb:71:in `block in enqueue'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:117:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:14:in `block (3 levels) in <module:Logging>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `block in tag_logger'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `tagged'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `tag_logger'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/logging.rb:13:in `block (2 levels) in <module:Logging>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `instance_exec'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:342:in `block in simple'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:497:in `block in around'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_enqueue_callbacks'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/bci20/Sites/acc-001-api/.gems/gems/activejob-4.2.6/lib/active_job/enqueuing.rb:67:in `enqueue'
/Users/bci20/Sites/acc-001-api/.gems/bundler/gems/cangaroo-021d8f37df5e/app/interactors/cangaroo/run_polls.rb:7:in `block in call'
/Users/bci20/Sites/acc-001-api/.gems/bundler/gems/cangaroo-021d8f37df5e/app/interactors/cangaroo/run_polls.rb:6:in `each'
/Users/bci20/Sites/acc-001-api/.gems/bundler/gems/cangaroo-021d8f37df5e/app/interactors/cangaroo/run_polls.rb:6:in `call'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor.rb:143:in `block in run!'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor/hooks.rb:213:in `block in with_hooks'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor/hooks.rb:224:in `run_around_hooks'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor/hooks.rb:211:in `with_hooks'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor.rb:142:in `run!'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor.rb:115:in `run'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor.rb:50:in `tap'
/Users/bci20/Sites/acc-001-api/.gems/gems/interactor-3.1.0/lib/interactor.rb:50:in `call'
/Users/bci20/Sites/acc-001-api/.gems/bundler/gems/cangaroo-021d8f37df5e/lib/tasks/cangaroo_tasks.rake:3:in `block (2 levels) in <top (required)>'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/bci20/Sites/acc-001-api/.gems/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => cangaroo:poll
(See full trace by running task with --trace)
rohitnick commented 8 years ago

In app/jobs/cangaroo/job.rb you will have to change this code PerformFlow.call( source_connection: destination_connection, json_body: response.to_json, jobs: Rails.configuration.cangaroo.jobs )

to PerformFlow.call( source_connection: destination_connection, json_body: response, jobs: Rails.configuration.cangaroo.jobs )

And also make other changes as made in PR #23 , as response.to_json turns the context.json_body to string and you won't be able to do this context.json_body.delete('parameters')

As it will not change the original context.json_body string. So it needs to be a JSON. I hope I am making sense. :)

bricesanchez commented 8 years ago

Thanks @rohitnick but i've already done this in my branch : https://github.com/nebulab/cangaroo/compare/master...bisscomm:acc-001

but i thought this PR will fix my problem.