{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-js/issues/699","labels_url":"https://api.github.com/repos/swagger-api/swagger-js/issues/699/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-js/issues/699/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-js/issues/699/events","html_url":"https://github.com/swagger-api/swagger-js/issues/699","id":128212108,"number":699,"title":"Trouble with 1.2 API conversion to 2.0","user":{"login":"brianfife","id":16841405,"avatar_url":"https://avatars.githubusercontent.com/u/16841405?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfife","html_url":"https://github.com/brianfife","followers_url":"https://api.github.com/users/brianfife/followers","following_url":"https://api.github.com/users/brianfife/following{/other_user}","gists_url":"https://api.github.com/users/brianfife/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfife/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfife/subscriptions","organizations_url":"https://api.github.com/users/brianfife/orgs","repos_url":"https://api.github.com/users/brianfife/repos","events_url":"https://api.github.com/users/brianfife/events{/privacy}","received_events_url":"https://api.github.com/users/brianfife/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-22T18:14:15Z","updated_at":"2016-01-25T15:38:14Z","closed_at":null,"body":"Hello,\r\n\r\nI'm encountering a unique issue when creating a SwaggerClient with the following json snippet (paired down from a larger API):\r\n\r\n```json\r\n{\r\n  \"apiVersion\": \"1.0\",\r\n  \"consumes\": [\r\n    \"application/json\"\r\n  ],\r\n  \"apis\": [\r\n    {\r\n      \"description\": \"create\",\r\n      \"operations\": [\r\n        {\r\n          \"method\": \"POST\",\r\n          \"summary\": \"Create a user\",\r\n          \"notes\": \"Create a user\",\r\n          \"nickname\": \"create\",\r\n          \"produces\": [\r\n            \"application/json\"\r\n          ],\r\n          \"consumes\": [\r\n            \"application/json\"\r\n          ],\r\n          \"parameters\": [\r\n            {\r\n              \"allowMultiple\": false,\r\n              \"defaultValue\": \"\",\r\n              \"description\": \"The information required to create a user\",\r\n              \"name\": \"body\",\r\n              \"paramType\": \"body\",\r\n              \"type\": \"RequestUserInfo\",\r\n              \"required\": false\r\n            }\r\n          ],\r\n          \"deprecated\": \"false\",\r\n          \"type\":\"UserInfo\"\r\n        }\r\n      ],\r\n      \"path\": \"/api/users\"\r\n    }\r\n  ],\r\n  \"models\": {\r\n    \"RequestUserInfo\": {\r\n      \"description\": \"\",\r\n      \"id\": \"RequestUserInfo\",\r\n      \"properties\": {\r\n        \"data\": {\r\n          \"required\": false,\r\n          \"type\": \"UserInfo\"\r\n        }\r\n      }\r\n    },\r\n    \"UserInfo\": {\r\n      \"description\": \"The information required to create a user\",\r\n      \"id\": \"UserInfo\",\r\n      \"properties\": {\r\n        \"password\": {\r\n          \"description\": \"The password for the user\",\r\n          \"required\": true,\r\n          \"type\": \"string\"\r\n        },\r\n        \"userName\": {\r\n          \"description\": \"The user name\",\r\n          \"required\": true,\r\n          \"type\": \"string\"\r\n        }\r\n      }\r\n    }\r\n  },\r\n  \"basePath\": \"/obj\",\r\n  \"resourcePath\": \"/api/users\",\r\n  \"info\": {\r\n      \"contact\": \"\",\r\n      \"description\": \"\",\r\n      \"license\": \"\",\r\n      \"licenseUrl\": \"\",\r\n      \"termsOfServiceUrl\": \"\",\r\n      \"title\": \"\"\r\n  },\r\n  \"swaggerVersion\": \"1.2\"\r\n}\r\n```\r\n\r\nWhat I am running:\r\n\r\n```javascript\r\n    new SwaggerClient({\r\n      url: \"http://localhost/spec.json\",\r\n      usePromise: true,\r\n      progress: function(m) {console.log(m);}\r\n    }).then(function(client) {\r\n      console.log(client['api/users'].apis.create.parameters[0].sampleJSON);\r\n    });\r\n```\r\n\r\nWhat I am trying to do is extract the sampleJSON used in the create request (post data).  \r\n\r\nMy (incorrect) output is:\r\n\r\n```json\r\n{\r\n  \"data\": \"password\"\r\n}\r\n```\r\n\r\nWhat I am expecting to see is:\r\n\r\n```json\r\n{\r\n  \"data\": {\r\n    \"password\": \"string\",\r\n    \"userName\": \"string\"\r\n  }\r\n}\r\n```\r\n\r\nI spent far too much time learning what swagger-client is doing, and discovered that the reason this is occurring comes from https://github.com/swagger-api/swagger-js/blob/master/lib/spec-converter.js#L150.  When converting the 1.2 spec to 2.0, properties[enum] is created using the names found in UserInfo.properties{}.\r\n\r\nSince there is now a UserInfo.properties.enum present, schemaToJSON will return enum[0]  https://github.com/swagger-api/swagger-js/blob/master/lib/schema-markup.js#L119 as the JSON sample for the UserInfo definition.\r\n\r\nclient.definitions.UserInfo\r\n```json\r\n{ properties: \r\n   { password: { type: 'string', description: 'The password for the user' },\r\n     userName: { type: 'string', description: 'The user name' } },\r\n  enum: [ 'password', 'userName' ],\r\n  required: undefined }\r\n```\r\n\r\nI have no idea what the right solution is.  Should the UserInfo.properties.enum[] be created in the first place?  I used swagger-codegen to create a nodejs server (which converts the spec to 2.0), and it didn't add the enum[] to UserInfo.properties.  \r\n\r\nShould the schema-markup code not short-circuit to setting output = properties.enum[0], which would let it iterate through all the UserInfo.properties{} to build the JSON sample ?"},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-js/issues/comments/174546449","html_url":"https://github.com/swagger-api/swagger-js/issues/699#issuecomment-174546449","issue_url":"https://api.github.com/repos/swagger-api/swagger-js/issues/699","id":174546449,"user":{"login":"brianfife","id":16841405,"avatar_url":"https://avatars.githubusercontent.com/u/16841405?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfife","html_url":"https://github.com/brianfife","followers_url":"https://api.github.com/users/brianfife/followers","following_url":"https://api.github.com/users/brianfife/following{/other_user}","gists_url":"https://api.github.com/users/brianfife/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfife/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfife/subscriptions","organizations_url":"https://api.github.com/users/brianfife/orgs","repos_url":"https://api.github.com/users/brianfife/repos","events_url":"https://api.github.com/users/brianfife/events{/privacy}","received_events_url":"https://api.github.com/users/brianfife/received_events","type":"User","site_admin":false},"created_at":"2016-01-25T15:38:13Z","updated_at":"2016-01-25T15:38:13Z","body":"The swagger-client used for swagger-ui doesn't seem to have trouble rendering the sampleJSON on the webpages, likely due to using buildFrom1_2Spec.\r\n\r\n```\r\n/**\r\n * swagger-client - swagger.js is a javascript client for use with swaggering APIs.\r\n * @version v2.1.9-M1\r\n * @link http://swagger.io\r\n * @license apache 2.0\r\n */\r\n```\r\n"}}