mulesoft / api-console

An interactive REST console based on RAML/OAS files
Other
911 stars 236 forks source link

Bug in RAML 1.0 parsing #423

Closed Jabher closed 6 years ago

Jabher commented 7 years ago

What happens

Some RAML 1.0 files causes console to not load and crashes with following error in devtools. Error description, reasons, fix are provided below; I can implement a PR if this fix correct from RAML spec position, and is sane and sound.

api-console-vendor.js:49681 TypeError: Cannot read property 'type' of undefined
    at extractArrayType (./scripts/api-console.js:2862:27)
    at Object.<anonymous> (./scripts/api-console.js:2873:24)
    at walker (./scripts/api-console-vendor.js:72309:26)
    at ./scripts/api-console-vendor.js:72327:33
    at Array.forEach (native)
    at forEach (./scripts/api-console-vendor.js:72417:35)
    at walker (./scripts/api-console-vendor.js:72322:17)
    at ./scripts/api-console-vendor.js:72327:33
    at Array.forEach (native)
    at forEach (./scripts/api-console-vendor.js:72417:35)

Stages to reproduce

Load RAML doc of that kind in console:

#%RAML 1.0
title: Bug example
version: 1.0

/foo:
  post:
    body:
      application/json:
        type: array

Error

This happens due to this line: https://github.com/mulesoft/api-console/blob/c15b4b11154335af7ae02270dd984020b6a2d3de/src/app/factories/raml-expander.js#L46

if(arrayNode.items.type) { return arrayNode.items.type[0]; }

which is executed if arrayNode.type === 'array' However, arrayNode do not contain items, this line will cause the crash.

Fix

This can be easily fixed with line quoted above to be changed in the following way:

if(arrayNode.items && arrayNode.items.type) { return arrayNode.items.type[0]; }
carowright commented 6 years ago

Hi @Jabher ! Thanks for reporting. This will be fixed in next version 3.0.27.

mannuiitd commented 6 years ago

Hi I have this in my RAML file creating in Design Center body: application/json: type: array

Api Console gives this error.

api-console-vendor.min.js:77 TypeError: Cannot read property 'type' of undefined at extractArrayType (api-console.min.js:3) at Object. (api-console.min.js:3) at walker (api-console-vendor.min.js:87) at api-console-vendor.min.js:87 at Array.forEach () at forEach (api-console-vendor.min.js:87) at walker (api-console-vendor.min.js:87) at api-console-vendor.min.js:87 at Array.forEach () at forEach (api-console-vendor.min.js:87)

carowright commented 6 years ago

Hi @mannuiitd! Are you using the latest version?