nastassiar
nastassiar

Reputation: 1621

Swagger/ Swashbuckle nested responses not showing up correctly

I'm trying to upgrade from Swashbuckle 4 to 5 and swagger 1.2 to 2.

The issue I'm having is the response schema isn't showing up correctly if the response has another object within it.

While using Swagger 1.2 my Model Schema looked like this:

{
  "Id": "",
  "FirstName": "",
  "LastName": "",
  "Address": {
    "StreetNumber": "",
    "City": "",
    "PostalCode": ""
  },
  "Preferences": [
    {
      "Name": "",
      "Brand": "",
      "MarketingName": ""
    }
  ]
}

And the model was:

Customer {
Id (string, optional),
FirstName (string, optional),
LastName (string, optional),
Address(Address, optional),
Preferences(array[Preference], optional)
}
Address {
StreetNumber (string, optional),
City (string, optional),
PostalCode (string, optional)
}
Preference{
Name (string, optional),
Brand (string, optional),
MarketingName (string, optional),
    }

Now the model schema is:

{
  "Id": "",
  "FirstName": "",
  "LastName": "",
  "Preferences": [
    null,
  ]
}

And the model is:

Customer {
Id (string, optional),
FirstName (string, optional),
LastName (string, optional),
Address(#/definitions/Address, optional),
Preferences(Array[#/definitions/Preference, optional)
}

The JSON hasn't really changed. From swagger 1.2 to 2.0 the response type has moved from type to responses ref but the JSON appears to be correct and if Preferences or address isn't nested within Customer it appears correctly in the UI.

How can I get the models for Address and preference to appear in the Customers model?

Upvotes: 0

Views: 1580

Answers (1)

Ron
Ron

Reputation: 14830

That actually has nothing to do with Swashbuckle but rather swagger-ui. By the looks of it, it's a possible bug. What you can do to test it is get the latest version of swagger-ui directly from its repository, and try running it against the Swagger definition that's produced from Swashbuckle. The URL is described at the getting started section - https://github.com/domaindrivendev/Swashbuckle#getting-started.

If the problem is solved, you can ask the Swashbuckle's author to upgrade the UI version. If not, I'd recommend opening a ticket directly on swagger-ui and it will be addressed.

Upvotes: 1

Related Questions