Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

ReferenceError: properties is not defined #73

Closed
fullstackwebdev opened this issue Feb 16, 2016 · 13 comments
Closed

ReferenceError: properties is not defined #73

fullstackwebdev opened this issue Feb 16, 2016 · 13 comments
Milestone

Comments

@fullstackwebdev
Copy link

running

yo swaggerize --framework hapi --apiPath ./petstore-simple.json

on the petstore-simple.json interface (https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-simple.json)

does not run on my local machine, or other servers I tried.

I get a lodash error

undefined:11
_.forEach(Object.keys(properties), function (prop) {;
                      ^

ReferenceError: properties is not defined

Upgrading lodash to version 3 doesn't fix this -- nor does updating the package Yeoman Generator to latest (0.22.5). ( I thought that might help..)

Strange?

➜  b5 wget https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-simple.json
--2016-02-15 19:54:28--  https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore-simple.json
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 23.235.47.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|23.235.47.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5189 (5.1K) [text/plain]
Saving to: 'petstore-simple.json'

100%[=========================================================================================================================>] 5,189       --.-K/s   in 0s      

2016-02-15 19:54:28 (933 MB/s) - 'petstore-simple.json' saved [5189/5189]

➜  b5 yo swaggerize --framework hapi --apiPath ./petstore-simple.json                                                
Swaggerize Generator
? What would you like to call this project: b5
? Your name: 
? Your github user name: 
? Your email: 
? Path (or URL) to swagger document: /home/fullstack/b5/petstore-simple.json
? Express, Hapi or Restify: hapi
identical .jshintrc
identical .gitignore
identical .npmignore
   create server.js
   create package.json
   create README.md
   create config/petstore-simple.json
   create handlers/pets.js
   create handlers/pets/{id}.js
undefined:11
_.forEach(Object.keys(properties), function (prop) {;
                      ^

ReferenceError: properties is not defined
    at eval (eval at template (/home/fullstack/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:11:23)
    at underscore [as _engine] (/home/fullstack/node_modules/yeoman-generator/lib/util/engines.js:32:30)
    at engine (/home/fullstack/node_modules/yeoman-generator/lib/actions/actions.js:303:10)
    at template (/home/fullstack/node_modules/yeoman-generator/lib/actions/actions.js:281:15)
    at /home/fullstack/node_modules/generator-swaggerize/app/index.js:287:18
    at Array.forEach (native)
    at yeoman.generators.Base.extend.models (/home/fullstack/node_modules/generator-swaggerize/app/index.js:276:49)
    at /home/fullstack/node_modules/yeoman-generator/lib/base.js:341:43
    at /home/fullstack/node_modules/yeoman-generator/node_modules/async/lib/async.js:551:21
    at /home/fullstack/node_modules/yeoman-generator/node_modules/async/lib/async.js:227:13
➜  b5 
@fullstackwebdev
Copy link
Author

also, suggested on #swagger to try this swagger.json: http://petstore.swagger.io/v2/swagger.json?

errors in a completely different area, but a lodash problem as well:

   create handlers/store/order/{orderId}.js
   create handlers/user.js
   create handlers/user/createWithArray.js
   create handlers/user/createWithList.js
   create handlers/user/login.js
   create handlers/user/logout.js
   create handlers/user/{username}.js
   create models/order.js
   create models/user.js
   create models/category.js
   create models/tag.js
   create models/apiresponse.js
   create models/pet.js
undefined:44
                    body = models[param.schema.$ref.slice(param.schema.$ref.lastIndexOf('/') + 1)];
                                                   ^

TypeError: Cannot read property 'slice' of undefined
    at eval (eval at template (/home/fullstack/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:44:52)
    at Function.forEach (/home/fullstack/node_modules/lodash/dist/lodash.js:3298:15)
    at eval (eval at template (/home/fullstack/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:26:15)
    at Function.forEach (/home/fullstack/node_modules/lodash/dist/lodash.js:3298:15)
    at eval (eval at template (/home/fullstack/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:13:3)
    at underscore [as _engine] (/home/fullstack/node_modules/yeoman-generator/lib/util/engines.js:32:30)
    at engine (/home/fullstack/node_modules/yeoman-generator/lib/actions/actions.js:303:10)
    at template (/home/fullstack/node_modules/yeoman-generator/lib/actions/actions.js:281:15)
    at /home/fullstack/node_modules/generator-swaggerize/app/index.js:372:18
    at Array.forEach (native)

@subeeshcbabu-zz
Copy link
Member

PR to the same issue

@dcolens
Copy link

dcolens commented Feb 22, 2016

the same stack is seen with #70 (see https://travis-ci.org/krakenjs/generator-swaggerize/jobs/110177935).

The issue happens because http://petstore.swagger.io/v2/swagger.json contains the following definition:

Pets: {
    type: "array",
    items: {
        $ref: "#/definitions/Pet"
    }
},

this model is an array of another model the properties are defined in the Petmodel while the _model template used by swaggerize expects properties to be defined.

I don't know this project well enough to fix the _model template.

@subeeshcbabu-zz
Copy link
Member

Published generator-swaggerize - v2.0.2

@nakamorichi
Copy link

@subeeshcbabu I'm still getting the aforementioned

body = models[param.schema.$ref.slice(param.schema.$ref.lastIndexOf('/') + 1)];
TypeError: Cannot read property 'slice' of undefined

error.

@subeeshcbabu-zz
Copy link
Member

@Kitanotori - Can you share the version of the generator and the api file?

@aroslov
Copy link

aroslov commented Jun 2, 2016

Its the same Petstore schema - http://petstore.swagger.io/v2/swagger.json

full stack:

$ yo swaggerize
Swaggerize Generator
? What would you like to call this project: test
? Your name: 
? Your github user name: 
? Your email: 
? Path (or URL) to swagger document: http://petstore.swagger.io/v2/swagger.json
? Express, Hapi or Restify: hapi
   create .jshintrc
   create .gitignore
   create .npmignore
   create server.js
   create package.json
   create README.md
   create config/swagger.json
   create handlers/pet.js
   create handlers/pet/findByStatus.js
   create handlers/pet/findByTags.js
   create handlers/pet/{petId}.js
   create handlers/pet/{petId}/uploadImage.js
   create handlers/store/inventory.js
   create handlers/store/order.js
   create handlers/store/order/{orderId}.js
   create handlers/user.js
   create handlers/user/createWithArray.js
   create handlers/user/createWithList.js
   create handlers/user/login.js
   create handlers/user/logout.js
   create handlers/user/{username}.js
   create models/order.js
   create models/category.js
   create models/user.js
   create models/tag.js
   create models/pet.js
   create models/apiresponse.js
undefined:44
                    body = models[param.schema.$ref.slice(param.schema.$ref.lastIndexOf('/') + 1)];
                                                   ^

TypeError: Cannot read property 'slice' of undefined
    at eval (eval at template (/usr/local/lib/node_modules/generator-swaggerize/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:44:52)
    at Function.forEach (/usr/local/lib/node_modules/generator-swaggerize/node_modules/lodash/dist/lodash.js:3298:15)
    at eval (eval at template (/usr/local/lib/node_modules/generator-swaggerize/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:26:15)
    at Function.forEach (/usr/local/lib/node_modules/generator-swaggerize/node_modules/lodash/dist/lodash.js:3298:15)
    at eval (eval at template (/usr/local/lib/node_modules/generator-swaggerize/node_modules/lodash/dist/lodash.js:6306:22), <anonymous>:13:3)
    at underscore [as _engine] (/usr/local/lib/node_modules/generator-swaggerize/node_modules/yeoman-generator/lib/util/engine

@subeeshcbabu-zz
Copy link
Member

I had to uninstall and npm cache clean my older generator-swaggerize versions and then install the 2.0.2 to get the fix for the above issue. I am wondering if that is the same case for you as well.

In my local, I am able to scaffold the project from http://petstore.swagger.io/v2/swagger.json using 2.0.2 version.

@aroslov
Copy link

aroslov commented Jun 3, 2016

I've not had any prior version installed. Reinstalling doesn't help.

Please note that express generator works, but not hapi - my stack above is for hapi.

@subeeshcbabu-zz
Copy link
Member

ah that makes sense. The automates unit tests for hapi somehow passes and that may need a fix too. The fix for express need to be copied over to other framework options as well.

@delaguilaluis
Copy link

I'm also getting this error and identified my case:
I have a Map/Dictionary definition in my swagger.yaml as follows:

Map:
    type: object
    additionalProperties:
      type: string

Since this object doesn't have "properties" it's failing. If I add "properties" it would work.
I'm trying to model a Map/Dictionary as described in the Model with Map/Dictionary Properties section of Open API Specification.
Anyway, since the error raises when generating the models, I don't even know if it would make sense to generate that model without properties. Maybe the generator could skip this cases?

@subeeshcbabu-zz
Copy link
Member

Working on the version generator version 3 release which will address all these open issues and implement missing features from Swagger 2.0 spec. - https://github.com/krakenjs/generator-swaggerize/milestones/v3.0.0.

Yes. the model generator should skip if no properties found.

Upcoming generator release is going to replace the model concept with mocks and `data.

@subeeshcbabu-zz subeeshcbabu-zz added this to the v3.0.0 milestone Jul 20, 2016
@subeeshcbabu-zz
Copy link
Member

Please check the latest version [email protected]. This should be resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants