apiaryio / matter_compiler

API Blueprint AST to API Blueprint Conversion Tool [adhd]
MIT License
16 stars 3 forks source link

no implicit conversion of Symbol into Integer (TypeError) #10

Open tu1ly opened 10 years ago

tu1ly commented 10 years ago

/app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:79:in `[]': no implicit conversion of Symbol into Integer (TypeError)

caused by headers in blueprints 1.0

"headers": {"Authorization": "RAPI ****token****"},

input ast:

{
    "_version": "2.0",
    "metadata": [],
    "name": "****apiname****",
    "description": "",
    "resourceGroups": [
        {
            "name": "****apiname****",
            "description": "",
            "resources": [
                {
                    "name": "Details",
                    "description": "",
                    "uriTemplate": "/****clientname****/rapi/learner/asset/{id}/details",
                    "model": {},
                    "parameters": [
                        {
                            "name": "id",
                            "description": "",
                            "type": "string",
                            "required": false,
                            "default": "",
                            "example": "",
                            "values": []
                        }
                    ],
                    "actions": [
                        {
                            "name": "Details",
                            "description": "",
                            "method": "GET",
                            "parameters": [],
                            "examples": [
                                {
                                    "name": "Examples",
                                    "description": "Examples created from requests in SoapUI",
                                    "requests": [
                                        {
                                            "name": "Request 1",
                                            "description": "",
                                            "headers": {
                                                "Authorization": "RAPI ****token****"
                                            },
                                            "body": "",
                                            "schema": ""
                                        }
                                    ],
                                    "responses": []
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}
honzajavorek commented 10 years ago

Occured again today, the same problem I guess.

Stacktrace

/app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:79:in `[]': no implicit conversion of Symbol into Integer (TypeError)
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:79:in `block in load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:78:in `each'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:78:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:282:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:282:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `block in load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `each'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `block in load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `each'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `block in load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `each'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `block in load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `each'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `block in load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `each'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `load_ast!'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/composer.rb:113:in `new'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/composer.rb:113:in `compose'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/cli.rb:32:in `runCommand'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/cli.rb:14:in `start'
    from /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/bin/matter_compiler:3:in `<top (required)>'
    from /app/vendor/bundle/bin/matter_compiler:16:in `load'
    from /app/vendor/bundle/bin/matter_compiler:16:in `<main>'

AST

{
  "_version": "2.0",
  "metadata": [],
  "name": "User - https://****subdomain****.qa.skillport.com",
  "description": "",
  "resourceGroups": [
    {
      "name": "https://****subdomain****.qa.skillport.com",
      "description": "",
      "resources": [
        {
          "name": "User",
          "description": "",
          "uriTemplate": "/****clientname****/rapi/learner/user",
          "model": {},
          "parameters": [],
          "actions": [
            {
              "name": "User",
              "description": "",
              "method": "GET",
              "parameters": [],
              "examples": [
                {
                  "name": "Examples",
                  "description": "Examples created from requests in SoapUI",
                  "requests": [
                    {
                      "name": "Request 1",
                      "description": "",
                      "headers": {
                        "Authorization": "****token****"
                      },
                      "body": "",
                      "schema": ""
                    }
                  ],
                  "responses": []
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
zdne commented 9 years ago

if

{
  "headers": {
    "Authorization": "RAPI ****token****"
  }
}

is in the input AST then it is not the API Blueprint AST – my question is, where is this "AST" coming from ?

zdne commented 9 years ago

You can see what the header hash should look like here https://github.com/apiaryio/matter_compiler/blob/master/features/compose.feature#L91

honzajavorek commented 9 years ago

If I remember correctly, this issue is related to API Blueprint API. Thus, I suppose, this AST came from Apiary partners. It can be, of course, invalid (although it could be interesting to see how did they managed to create an invalid AST) and it seems that this is exactly the case. From your comments and from the fact where this issue comes from we can say that someone sent us invalid AST and matter_compiler failed with exception.

Then the correct behavior should be matter_compiler failing with regular error message saying at least something like "sorry, you gave me invalid AST" instead of crashing.

zdne commented 9 years ago

Yup, matter compiler should recognize invalid ASTs and fail gracefully.

honzajavorek commented 9 years ago

If it could say what exactly was wrong (which node in the tree), that would be awesome, but still, at least saying that the AST was invalid would be nicer.

honzajavorek commented 9 years ago

Ocurred again:

MATTER_COMPILER_FAILED: /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:79:in `[]': no implicit conversion of Symbol into Integer (TypeError)
 { message: '/app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:79:in `[]\': no implicit conversion of Symbol into Integer (TypeError)\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:79:in `block in load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:78:in `each\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:78:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:282:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:282:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `block in load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `each\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:401:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `block in load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `each\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:438:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `block in load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `each\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:489:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `block in load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `each\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:525:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `block in load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `each\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:565:in `load_ast!\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/blueprint.rb:19:in `initialize\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/composer.rb:113:in `new\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/composer.rb:113:in `compose\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/cli.rb:32:in `runCommand\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/lib/matter_compiler/cli.rb:14:in `start\'\n\tfrom /app/vendor/bundle/ruby/2.1.0/gems/matter_compiler-0.5.1/bin/matter_compiler:3:in `<top (required)>\'\n\tfrom /app/vendor/bundle/bin/matter_compiler:16:in `load\'\n\tfrom /app/vendor/bundle/bin/matter_compiler:16:in `<main>\'',
name: 'MatterCompilerError',
ast: '{"_version":"2.0","metadata":[],"name":"getFitnessActivitySwaggerExample - http://localhost:8080","description":"","resourceGroups":[{"name":"http://localhost:8080","description":"","resources":[{"name":"","description":"","uriTemplate":"/exerciser-api/exerciser-account/id/113/fitness-activity{?local-start-date,local-end-date}","model":{},"parameters":[{"name":"local-start-date","description":"","type":"string","required":false,"default":"","example":"","values":[]},{"name":"local-end-date","description":"","type":"string","required":false,"default":"","example":"","values":[]}],"actions":[{"name":"","description":"","method":"GET","parameters":[],"examples":[{"name":"Examples","description":"Examples created from requests in SoapUI","requests":[{"name":"Request 1","description":"","headers":{"Authorization":"bearer ..."},"body":"","schema":""}],"responses":[]}]}]}]}]}' }

Note: I've cleaned up the bearer token and replaced it with three dots.