Skip to content

detect OAS format error - #318

Merged
eguzki merged 1 commit into
mainfrom
detect-oas-format-error
Aug 5, 2021
Merged

detect OAS format error#318
eguzki merged 1 commit into
mainfrom
detect-oas-format-error

Conversation

@eguzki

@eguzki eguzki commented Aug 4, 2021

Copy link
Copy Markdown
Member

The '3scale import openapi command did not check parsed format when YAML.safe_load returned a string (which is a valid yaml doc, but not for OAS docs)

3scale import openapi -d supertest - <<EOF
>  <!DOCTYPE html>
> <html>
> <body>
> 
> <h1>My First Heading</h1>
> <p>My first paragraph.</p>
> 
> </body>
> </html> 
> EOF
{
  "code": "E_UNKNOWN",
  "message": "undefined method `key?' for #<String:0x000055bb120097b8>",
  "class": "NoMethodError",
  "stacktrace": [
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/commands/import_command/openapi.rb:111:in `openapi_parser'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/commands/import_command/openapi.rb:78:in `create_context'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/commands/import_command/openapi.rb:72:in `context'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/commands/import_command/openapi.rb:52:in `run'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/gems/cri-2.15.11/lib/cri/command_runner.rb:34:in `call'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/gems/cri-2.15.11/lib/cri/command_dsl.rb:294:in `block in runner'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/gems/cri-2.15.11/lib/cri/command.rb:362:in `run_this'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/gems/cri-2.15.11/lib/cri/command.rb:298:in `run'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/gems/cri-2.15.11/lib/cri/command.rb:316:in `run'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/gems/cri-2.15.11/lib/cri/command.rb:316:in `run'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/cli.rb:47:in `block in run'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/cli/error_handler.rb:5:in `block in error_watchdog'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/cli/error_handler.rb:11:in `error_watchdog'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/cli/error_handler.rb:5:in `error_watchdog'",
    "/home/eguzki/git/3scale_toolbox/lib/3scale_toolbox/cli.rb:44:in `run'",
    "/home/eguzki/git/3scale_toolbox/exe/3scale:15:in `<top (required)>'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/bin/3scale:23:in `load'",
    "/home/eguzki/git/3scale_toolbox/vendor/bundle/ruby/2.7.0/bin/3scale:23:in `<main>'"
  ]
}

With the fix, the error is meaninful

3scale import openapi -d supertest - <<EOF
<!DOCTYPE html>
<html>
EOF
{
  "code": "E_3SCALE",
  "message": "only JSON/YAML format is supported",
  "class": "ThreeScaleToolbox::Error"
}

This use case is when OAS passed as URL is not a real OAS but some HTML or something else.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #318 (485f5c4) into main (75025eb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 485f5c4 differs from pull request most recent head e78f9d5. Consider uploading reports for the commit e78f9d5 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main     #318   +/-   ##
=======================================
  Coverage   96.22%   96.23%           
=======================================
  Files         298      298           
  Lines       14567    14570    +3     
=======================================
+ Hits        14017    14021    +4     
+ Misses        550      549    -1     
Impacted Files Coverage Δ
.../3scale_toolbox/commands/import_command/openapi.rb 98.59% <100.00%> (+0.02%) ⬆️
spec/unit/commands/import_command/openapi_spec.rb 100.00% <100.00%> (ø)
...t_command/openapi/update_service_oidc_conf_step.rb 94.73% <0.00%> (-0.27%) ⬇️
spec/unit/entities/service_spec.rb 100.00% <0.00%> (ø)
spec/unit/crds/product_parser_spec.rb 100.00% <0.00%> (ø)
...mmand/copy_command/copy_service_proxy_task_spec.rb 97.29% <0.00%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75025eb...e78f9d5. Read the comment docs.

@eguzki
eguzki merged commit 7f1f9ce into main Aug 5, 2021
@eguzki
eguzki deleted the detect-oas-format-error branch August 5, 2021 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants