Model Schema displayed in Swagger UI is Incomplete

143 views
Skip to first unread message

Ashwini Sharma

unread,
Feb 25, 2015, 1:16:32 AM2/25/15
to swagger-sw...@googlegroups.com
Hi,

I am using the latest version of Swagger v2.1.8-M1
My Schema definitions in the swagger file looks like this: 

definitions {
Customer
{
  • properties
    {
    • FirstName
      {
      • type"string"
      },
    • LastName
      {
      • type"string"
      },
    • CustomerID
      {
      • type"string"
      },
    • phoneNumber
      {
      • type"string"
      },
    • age
      {
      • type"integer",
      • minimum1,
      • maximum120
      },
    • Address
      {
      • properties
        {
        • HouseNumber
          {
          • type"string"
          },
        • Street
          {
          • type"string"
          },
        • City
          {
          • type"string"
          },
        • State
          {
          • type"string",
          • enum
            [
            • "CA",
            • "NY",
            • "NJ",
            • "MN"
            ]
          }
        },
      • required
        [
        • "HouseNumber",
        • "Street",
        • "City",
        • "State"
        ]
      }
    }
  • }
When this schema is displayed in the Swagger UI it looks like this: 
{
  "FirstName": "string",
  "LastName": "string",
  "CustomerID": "string",
  "phoneNumber": "string",
  "age": 0,
  "Address": {}
}

I tried to drill down into swagger-ui.js and swagger-client.js and found that the  problem is because whenever swagger UI encounters a schema object, it will only display the model for the top level objects. For any nested objects, the representation returned is " { } " without further drilling down the objects. 

The problem that i am referring to is present here in this file "swagger-client.js"
Property.prototype.sampleValue = function(isArray, ignoredModels, representations) {
...
output =' { }'
}


Is there any work around for this? 

Thanks

tony tam

unread,
Feb 25, 2015, 1:37:49 AM2/25/15
to swagger-sw...@googlegroups.com
Swagger JS does not support inline schema definitions right now.  In your example, you have Address defined inline.  Right now, you need to support Address by defining it as such:

"address": {
 
"$ref": "Address"
}

and you then define Address "flat" in the "definitions" section.

This will be supported soon (track https://github.com/swagger-api/swagger-js/issues/189) for the update.
Reply all
Reply to author
Forward
0 new messages