z0mt3c / hapi-swaggered-ui

An easy swagger-ui drop-in plugin for hapi (to be used with hapi-swaggered).
39 stars 31 forks source link

Nested array breaks UI #7

Closed Bondza closed 9 years ago

Bondza commented 9 years ago

I am trying out swaggered with swaggered UI. And I have a nested array because I want to input Geo JSON data into a Geo Shape in Elasticsearch. See configuration http://pastebin.com/NfDJaUUu.

The code yields an error when loading /docs. The result is that the UI displays a message, fetching resource list: http://localhost:5000/swagger. Which is the result of a script error when parsing the data from /swagger.

An error is thrown from /lib/types/model.jsat line 223. model.js:223Uncaught TypeError: Cannot read property '$ref' of undefined. I do not know if this is because the returned data is invalid or if it is the UI which is at fault.

I am running: Node 0.10.38 hapi-swaggered 2.0.2 hapi-swaggered-ui 1.3.1

z0mt3c commented 9 years ago

Thanks for your report. I will have to take a look whats missing for nested array support. I'm kind of surprised that i missed that :-)

But in the meantime: swagger-ui itself does not (yet) support complex path parameters - so as a workaround for now (and maybe later) i would suggest to overwrite the exposed type of foo by "string" like this:

params: {
        foo: Joi.string().required().description('test'),
        bar: Joi.object({
         ...
        }).meta({ swaggerType: 'string' }).required()
      }

Doing this will at least give you control (through swagger-ui) over "bar" (and work around the error).

Nevertheless the error should not occur - i will have a look.

Bondza commented 9 years ago

Of course, I am glad I could contribute in some way. Aside from the bug this is pure awesomeness! :-)

I was looking into it my self but could not find the source for model.js. Where can I find it?

Thanks for the tip! I'll do that as a workaround for now. And then I can add the information about the actual type as some note or description?

On Fri, May 8, 2015, 15:30 Timo Behrmann notifications@github.com wrote:

Thanks for your report. I will have to take a look whats missing for nested array support. I'm kind of surprised that i missed that :-)

But in the meantime: swagger-ui itself does not (yet) support complex path parameters - so as a workaround for now (and maybe later) i would suggest to overwrite the exposed type of foo by "string" like this:

params: { foo: Joi.string().required().description('test'), bar: Joi.object({ ... }).meta({ swaggerType: 'string' }).required() }

Doing this will at least give you control (through swagger-ui) over "bar" (and work around the error).

Nevertheless the error should not occur - i will have a look.

— Reply to this email directly or view it on GitHub https://github.com/z0mt3c/hapi-swaggered-ui/issues/7#issuecomment-100234811 .

z0mt3c commented 9 years ago

Sure - just add your description:

...}).meta({swaggerType: 'string'}).description('Lorem...').required()

model.js is part of the swagger-ui (specificly: swagger-js) project... but actually hapi-swaggered should be able to express a schema containing a nested array :-) so its not an issue on swagger-ui side.

z0mt3c commented 9 years ago

Bug / Improvement to be fix / integrated within z0mt3c/hapi-swaggered#27

Bondza commented 9 years ago

Thanks! Yeah, I wasn't sure where the actual issue was so I just opened an issue here :-)