Closed MrWako closed 9 years ago
petInput
is missing the type
attribute (which should be object
).
I'll also add that the generated acceptance tests do not include the body parser for multipart, nor do they post as multipart. This would be a manual step if you'd like to use multipart.
Thanks. I'm making good progress with the generator and its proving very useful. I'm quite happy with having to manually add the additional additional express code to handle multipart,
Closing this issue.
There's an (incorrect) assumption in the code (e.g. app/templates/_test_hapi.js
)
var body;
...
if (param.in === 'body') {
body = models[param.schema.$ref.slice(param.schema.$ref.lastIndexOf('/') + 1)];
}
...
if (operation.method.toLowerCase() === 'post' || operation.method.toLowerCase() === 'put') {%>
var body = {<%_.forEach(Object.keys(body).filter(function (k) { return !!body[k]; }), function (k, i) {%>
that the body
key must be present when the type of operation is post
or put
Even if you don't support code generation for this kind of use cases, the generator should not just crash...
Was there any resolution to this issue? i'm getting the same error when trying to create the test express templates using the example swagger document.
https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/samples/PetStore.yaml
undefined:54
_.forEach(Object.keys(body).filter(function (k) { return !!body[k]; }), functi
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at eval (eval at template (swaggertest/node_modules/yeoman-generator/node_modules/lodash/dist/lodash.js:6306:22),
Should be resolved in latest. Sorry for the delay.
I think this is how you should include multipart/form-data post operations in swagger. To reproduce take https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/json/petstore-simple.json and save to file. Replace the definition for petInput with the following
this should give a spec file with which the generator works. Now replace the /pets post consumes and parameters specifications with:
which I understand to be correct for post'ing multpart/form-data. If I run the generator I then get:
Swaggerize Generator ? What would you like to call this project: gg ? Your name: ? Your github user name: ? Your email: ? Path (or URL) to swagger document: ./schemas/issue/petstore-simple-fail.json ? Express or Hapi: express create .jshintrc create .gitignore create .npmignore create index.js create package.json create README.md create config/petstore-simple-fail.json create handlers/pets.js create handlers/pets/{id}.js create models/pet.js create models/petinput.js create models/errormodel.js
undefined:53 _.forEach(Object.keys(body).filter(function (k) { return !!body[k]; }), functi ^ TypeError: Object.keys called on non-object at Function.keys (native) at eval (eval at template (/node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/node_modules/yeoman-generator/node_modules/lodash/dist/lodash.js:6305:22),:53:18)
at Function.forEach (/node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/node_modules/yeoman-generator/node_modules/lodash/dist/lodash.js:3297:15)
at eval (eval at template (/node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/node_modules/yeoman-generator/node_modules/lodash/dist/lodash.js:6305:22), :16:3)
at underscore as _engine
at engine (/node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/node_modules/yeoman-generator/lib/actions/actions.js:303:10)
at template (/node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/node_modules/yeoman-generator/lib/actions/actions.js:281:15)
at /node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/app/index.js:345:18
at Array.forEach (native)
at yeoman.generators.Base.extend.tests (/node-v0.10.33-linux-x64/lib/node_modules/generator-swaggerize/app/index.js:321:32)
node version v0.10.33, yeoman version 1.3.3. Latest version of generator-swaggerize.
Thanks.