-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@ApiModel has no way to hide properties on super classes and compile time enhanced classes #730
Comments
Can you provide with a sample models (super+inherited)? |
The compile time enhanced is my primary issue-- I included the super class property issue since a solution would likely solve both: Here is sample model for super+inherited classes: // A super class provided by third-party
public class Animal {
String uselessAnnoyingProperty;
} // A sub class whose api-model should not have uselessAnnoyingProperty
public class Dog extends Animal {
int numberOfLegs;
} swagger-ui would show: {
"numberOfLegs": 0,
"uselessAnnoyingProperty": "",
} The solution I would suggest is: @ApiModel(hideProperties = {"uselessAnnoyingProperty", ...}) |
Right, but in this specific example, it sounds like you'd want to hide the "uselessAnnoyingProperty" anyways, so why not add |
Because it is a super class provided by a third party. For me, right now I just need to hide properties, but I can see valid cases where others would want to be able to have all the options available in @ApiModelProperty. So a better solution might be: @ApiModel(properties = {@ApModelProperty(name="uselessAnnoyingProperty", hide=true), ...}) |
It's probably not a relevant solution as with the next version of swagger-core, Jackson will be responsible entirely for the de/serialization process. However, we'll look into it. |
Will swagger-core also work with Moxy? Jersey 2 now prefers Moxy, which uses different annotations than Jackson. Moxy uses jaxb annotations such as @XmlRootElement. Anyway, I'd like to be sure you read that the issue I am directly facing right now is with compile time enhancing-- (I included the super/inherited class issue since I believe any solution would likely solve both). I am fine with waiting for next version of swagger-core. I found a (yucky) workaround by adding this to my api model class: @ApiModelProperty(hidden=true)
public int _ebean_intercept; // not used, except to trick swagger-core Once ebean compile enhances, it will add a |
Jackson processes JAXB's annotations as well, so it should work fine. There's probably not going to be direct support for Moxy just like there's not going to be direct support for Gson. As for your issue, there's another workaround which won't be less ugly, so I'm not sure it's worth mentioning. |
will investiagte for m2 |
This has been fixed as of 1.5.2-M1 |
I probably missed something, but how is it fixed? Is it now possible to write something like bthule suggested:
I can't seem to find that feature. |
@aciganj use |
You mean I should add a property of the same name as the one I want to hide and then use that annotation? I guess that would work for private properties, but what about others? Is there a way to do it without adding properties or getters to subclass? |
Please reopen the issue. This is a very important issue for the documentation because otherwise, the json data and the swagger model will not match. Please reopen the issue. |
it is a very important issus for me, Please reopen the issue. |
Hi, I think the same and I tried implementing some workaround for it in this pull request #2996, but unfortunately, Swagger team does not allow open contribution, so it will never be official. But if you do not intend to use Swagger forever, maybe it will help for now. |
It is 2019 now. And this is still not supported. I'm running into the exact problem where I have multiple sub types of |
I want to second @wenyi189 , having support for this case would be exceptionally beneficial for anyone using third party libraries or who cannot access parent classes to annotate fields they would like to ignore. This definitely seems within the scope of Swagger's problem space. |
Same thing here, I have a common resource class with some endpoints that should not come out in swagger for a particular project, but it should for others. I can't currently do that without overriding the endpoint methods in the one project. I shouldn't have to do that though just for documentation purposes. |
I think the 'hide-superclass-fields' feature would be a good value add for documentation |
The year 2020 was ending ... I'm amazed at how much time has passed since this feature was designated as very important. And just as amazed that she still does not exist. We urgently need to reopen this task. For example, there is such a thing Spring HATEOAS. In which resources are sometimes superfluous are all sorts of different things. Which it would be nice not to show in the documentation for the request body. So, the swagger does not provide an opportunity to customize it. This is the answer to a six-year old question as an example. And in general, to be honest, how old is the swagger and how many problems it has. It clearly doesn't look like a java library =/ |
This is a very important feature. From 2 aspects
Case 1) Case 2) |
I tried annotating my super class bean property with |
@ApiModelProperty allows hiding properties that in my model class, but there is no way to hide properties brought in by super classes or compile time enhanced classes.
For instance, Ebean enhances its model classes, and when they are used as a response Class, swagger-ui shows them with an extra property "_ebean_intercept (EntityBeanIntercept, optional)", and all of its properties and sub-properties.
The text was updated successfully, but these errors were encountered: