swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

`@ApiModel(parent = Pet.class)` seems to have no affect when `subTypes` isn't set

Open roni-frantchi opened this issue 10 years ago • 7 comments

Say one has Pet.class with perhaps Cat.class I understand the approach is then to have:

@ApiModel(subTypes = {Cat.class})
public class class Pet {
...
}

@ApiModel(parent = Pet.class)
public class Dog extends Pet {
...
}

This works well for me. In fact, even this would suffice:

@ApiModel(subTypes = {Cat.class})
public class class Pet {
...
}

// Note we do not annotate Dog and specify a parent
public class Dog extends Pet {
...
}

But, the following won't work for me:

// Note this time we don't annotate Pet with its subtypes
public class class Pet {
...
}

@ApiModel(parent = Pet.class)
public class Dog extends Pet {
...
}

It seems like io.swagger.jackson.SwaggerAnnotationIntrospector only cares about the subTypes and not the parent, which is a problem because, what am I to do if say Dog.class is actually a part of some other module and is not visible to the Pet module? I cannot annotate the Pet class with its subtypes... and i'm stuck.

roni-frantchi avatar Apr 03 '16 15:04 roni-frantchi

How would you expect this to work? Looking for input on how we scan objects.

fehguy avatar Apr 06 '16 02:04 fehguy

@fehguy see my PR here: https://github.com/swagger-api/swagger-core/issues/1741

There's also a unit test included to demonstrate the behavior. Let me know if that's what you've been looking for

roni-frantchi avatar Apr 06 '16 05:04 roni-frantchi

Any news?

morpheus9999 avatar Apr 04 '17 17:04 morpheus9999

Any news?

I guess there are still no news?

rala72 avatar Apr 11 '19 15:04 rala72

I also would like to have this feature if it is possible. I am currently in a situation where i needed to have a subclass of a specific class. That class comes from an external library so I can't annotate that class with ApiModel and provide the subclass information...

Only thing what I can do is annotating the subclass and provide the property from which parent it is a subclass, but it won't reflect in the generated swagger-ui model section as @roni-frantchi mentioned

Hakky54 avatar Apr 16 '19 07:04 Hakky54

Say one has Pet.class with perhaps Cat.class I understand the approach is then to have:

@ApiModel(subTypes = {Cat.class})
public class class Pet {
...
}

@ApiModel(parent = Pet.class)
public class Dog extends Pet {
...
}

This works well for me. In fact, even this would suffice:

@ApiModel(subTypes = {Cat.class})
public class class Pet {
...
}

// Note we do not annotate Dog and specify a parent
public class Dog extends Pet {
...
}

But, the following won't work for me:

// Note this time we don't annotate Pet with its subtypes
public class class Pet {
...
}

@ApiModel(parent = Pet.class)
public class Dog extends Pet {
...
}

It seems like io.swagger.jackson.SwaggerAnnotationIntrospector only cares about the subTypes and not the parent, which is a problem because, what am I to do if say Dog.class is actually a part of some other module and is not visible to the Pet module? I cannot annotate the Pet class with its subtypes... and i'm stuck.

Any Updates on this?

shankar96 avatar Feb 21 '20 07:02 shankar96

Closing this issue as part of our backlog cleanup effort.
This issue is outdated and/or inactive for a long time, and we’re not able to revisit it meaningfully.

If this problem is still relevant, please open a new issue and reference this one for context.
Thank you for your understanding!

MichakrawSB avatar Mar 08 '26 19:03 MichakrawSB