How to hide ApiModel class in Swagger?
I see hidden field in ApiModelProperty.
My client needs a models section, but doesn’t want to see one of the models in there.
Any pointers is appreciated, here!
Related
The environment is JSF 2, GlassFish, PrimeFaces.
I am working on an application for editing the data in a very complex model.
All classes in the model have relations to other classes, which in turn have relations to other classes, and so on. In many cases, for a given class, the "cluster" of relations (the whole expanded tree for the class) contains the same class at many places in the tree.
For example :
Class A has relations to class B, C and D.
Class B has no relations.
Class C has relations to class B.
Class D has relations to class E.
Class E has relations to class B.
Now that I have summarized the context, here's what troubles me.
A design decision has been made to put all the data of a given instance of a class in the same page. The current architecture for doing this is the following for a given "root" class :
The "root" class is displayed in a PrimeFaces TabView. The tabs are :
"Main" : contains the simple attributes (String, Integer, ...) of the class.
There is one tab for each relation.
In each tab, there is an include pointing to the appropriate XHTML file.
If the relation points to a single class, the XHTML file pointed to is similar to the "root" form described here. The adequate object is passed as a parameter to the XHTML file in the include directive. There are at most 3 nested TabViews.
If the relation points to a list, the XHTML file pointed to displays a list, with "add", "edit" and "delete" buttons. The adequate list is passed as a parameter to the XHTML file in the include directive.
There are additional complexities concerning lists, but I won't go there for the moment. Just with the single elements, we can see that there is a problem.
At first, I used the same parameter name for all XHTML files to be included. This does not work, because the parameter is "global" to the view. It seems to work for the initial display, but as soon as there is an update in one tab, I get an javax.el.PropertyNotFoundException because the form points to another object.
To mitigate the problem, I changed the parameter name to be unique for each class. Before, all parameters were called "element". After the modification, the parameter for class A is called "aElement", for class B it's "bElement", etc.
This works if all classes in a cluster are different. If a collision occurs, we are back to the same problem as before : in two different inclusions, we use the same parameter names, with different values.
I have thought about a very convoluted way to do it, but it uses Javascript :
I pass an additional parameter to the XHTML forms, which is a unique identifier for the passed object.
I get the identifier in the XHTML form, and put it in a hidden field, which is separated from the rest of the form.
I make sure that the hidden field is never updated, read its value when the form gets focus, and retrieve the right object by an AJAX request using the value.
So my question is : is there a "pure" Java/JSF way to handle this ?
TL;DR : Thanks for reading !
For very complex natures CDI has a lot more to offer then plain JSF2. You could use producers and during runtime you can evaluate and modify objects freely.
You can keep track on what's already been produced and adapt the naming accordingly. For example save every occupied name in a map. Good luck.
I'm trying to implement a more customisable version of using ViewModel attributes and a Model Enricher to populate viewmodels lists like in this this question and associated blog post.
I would like to be able to specify the method on my select list interface from the Attribute.
Each Select List service I have returns an IEnumerable that I use to make a select list and presently exposes an All interface as the sample does. I can easily use the All method because all interfaces provide that. However I often wish to able to use other methods like the AllTradingCompanies() AllManafacturingCompanies() methods of my select list class to get filtered lists.
It is presently looking like I may have to implement a Custom attribute to map to specific e.g. [AllCompanyList] attributes but that moves me away from the nice generic method that the existing version gives me. I guess I could use it to complement it but then its starting to lose some of the charm. I also am implementing IModelEnrichers which can do custom per view model logic.
Any thoughts on a nice way to implement this?
I implemented the solution using pairs of Attributes to define a requirement for data on a ViewModel and a provider of data a repository or a service within my domain. See my follow up question asking whether this is a good idea.
I'm working a feature in the application where model will be dynamic in the sense that any settings data could be displayed and the view will get the model based on what tab they clicked on. I use Hidden field to store what the settings name was because they are same as model name. for ex., if tab1-> Settings1 then Model is Settings1[already exists in the Model].So I used # model dynamic in View and used #Html.EditotForModel() to draw the required UI based off the model. My problem is when I do HttpPost on Edit currently I'm using FormCollection to read the data on that page when I declare the model name in the param it will get it for me but I don't know which model is coming back other than by the Hidden variable and I need it because the Model validation is broken because of this issue. Any help or feedback is appreciated? I can give more details if required? Has anybody crossed this issue before??
Dynamics can be a good thing and a bad thing. Using them on models that have a common interface in a controlled manor is best.
There are different options that you can look at:
1)
Have you tried making the action method accept a dynamic type? That might be the easiest way.
You might have to set up a casting helper to cast the object to the correct type based on the hidden field.
2)
I have a similar idea in some code, but I created a viewmetamodel class that contained all my types as nullable properties. My action method accepts this viewmetamodel type and validates the properties that are not null.
In line with this, if your data is not too large, then you could load all the settings tabs and use Jquery apply the tab with on click.
3)
You could also create #sections or use EditorFor(c=>c.settings) for each tab. That way each tab will load a type safe object. You would need to create controllers for each.
I would say pick the easiest method for you. I hope that this at least gives you some ideas.
I'm trying to create a custom multiple choice checkbox widget, that displays all items of a model.
My model is named 'Tag', which is a list of tags in my DB table.
I have copied the sfWidgetFormSelectCheckbox code and pasted it into my new widget class, but I'm unsure what to do next
Could someone help me?
Thanks
If your issue is working with tags. Best to look at sfDoctrineActAsTaggable. It should have all the behaviour you require, hence you should be able to dissect it to achieve what you are after.
I managed to get this working using some custom code, i.e. getters and setters and overriding the doUpdateObject() and updateDefaultsFromObject methods in my form class
I am looking to have an attribute "show" on certain properties in my class and give the user the option to show other properties in the view.
Can I change a custom attribute from the front end?
Are you talking about the Filter attributes? If you are, you cannot change properties as they are statically defined, unless the code within the attribute happens to reference a static class or within the context at execution time, and then you pretty much can access within the attribute anything from that static or the context...
If I'm on the wrong track, please let me know.
HTH.
I am not sure attributes are the best approach for dynamically attaching metadata. Normally attributes are attached at code generation time.