swagger-ui: subTypes not displayed in model

Hi!

I have service and model definition: SERVICE:

"path" : "/process/start",
    "operations" : [ {
      "method" : "POST",
      "nickname" : "startProcess",
      "type" : "void",
      "parameters" : [ {
        "type" : "array",
        "items" : {
          "$ref" : "ProcessTaskDTO"
        },
        "paramType" : "body",
        "name" : "tasks",
        "required" : true
      }, {
        "type" : "string",
        "paramType" : "query",
        "name" : "token"
      } ],
      "consumes" : [ "application/json" ],
      "produces" : [ "application/json" ]
    } ]

MODEL:

"ProcessTaskDTO" : {
      "id" : "ProcessTaskDTO",
      "properties" : {
        "id" : {
          "type" : "string"
        },
        "type" : {
          "type" : "string"
        },
        "name" : {
          "type" : "string"
        }
      }, 
      "subTypes" : ["ProcessTaskDTO1", "ProcessTaskDTO2"],
      "discriminator": "type"
    },
    "ProcessTaskDTO1" : {
      "id" : "ProcessTaskDTO1",
      "properties" : {
        "name1" : {
          "type" : "string"
        }
      }
    },
    "ProcessTaskDTO2" : {
      "id" : "ProcessTaskDTO2",
      "properties" : {
        "name2" : {
          "type" : "string"
        }
      }
    },

But model is not displayed in UI:

image

Found issue https://github.com/swagger-api/swagger-ui/issues/300 that’s closed and it’s related to response class. Is request model still an issue?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 11
  • Comments: 35 (11 by maintainers)

Most upvoted comments

+1 polymorphism is fairly important to show otherwise it’s effectively incomplete documentation

Same for me. Subtypes or not shown.

Some news about when it will be implemented?

Are there any plan’s timeline to support this feature also in swagger ui?

Its been 6 years, kids born when this issue was first raised are soon old enough to fix it themselves.

I cannot create accurate API documentation without this feature!

currently facing the same issue

In my project I tried version 2.2.5 of swagger-ui. As I see it this issue is still present and relevant. If you reference a super type that uses the discriminator, swagger ui will not tell the viewer anything about the possible sub types. Without consulting the the swagger document itself the viewer sees an incomplete documentation. The choices in a project then are: not use discriminator or not not use swagger ui. If the feature was present in a branch that merged into master, what happened to it? Maybe the feature can be included without much work if it wasn’t removed on purpose. I could try to look for it myself. I’m not the most qualified person to do so though. I will when I find the spare time. Anybody more qualified looking for a potential quick win?

@zhimoda do you have an example of a project that doesn’t use a discriminator that renders properly with the swagger-ui? I’m having trouble getting subtypes working without discriminators in the swagger-ui as well.

The issue is still exist in the newer version 3.0.2

@geggvarona I use a custom built version of that branch when it was still around. The implementation displayed the type of the superclass as the merged properties of the subclasses (all optional)

To set everyone’s expectations - we’re currently not actively working on resolving this one. We’re focused on adding support for the next version of the spec where additional JSON Schema constructs are added (anyOf, oneOf, not). We’re hoping to resolve such rendering issues in that cycle, however, it won’t be simple.

I see the same issue with swagger-ui 2.2.6, I only see the definitions from the $ref in allOf

I’m no six year old 😄, but I can consolidate this issue with #2438. Closing in favour of that one. Pull requests and thoughts on UI are still welcome!