Does Swagger UI supports #ModelAttribute? - swagger-ui

I have configured Swagger for REST web services, it works well and fetches my Request, Response parameters with clean documentation but it fails to display the Model Schema when using #ModelAttribute annotation
Is it something that I have to do to make Swagger accept such annotation as it is with #RequestBody?

I ran into a similar problem in using #ModelAttribute on a method parameter and it turned out that the object was not a proper POJO and could not be serialized. My first step to figuring this out was to enable trace level logging of the Swagger/Spring classes with the following XML block added to my log4j2.xml:
<Logger name="com.mangofactory" level="trace"></Logger>
This caused the following logged events to be output:
13:15:43.954 [localhost-startStop-1] DEBUG com.mangofactory.swagger.readers.operation.parameter.ModelAttributeParameterExpander - Expanding parameter type: class org.joda.time.DateTime
13:15:43.955 [localhost-startStop-1] DEBUG com.mangofactory.swagger.readers.operation.parameter.ModelAttributeParameterExpander - Attempting to expanding field: private static final long org.joda.time.DateTime.serialVersionUID
13:15:43.956 [localhost-startStop-1] DEBUG com.mangofactory.swagger.readers.operation.parameter.ModelAttributeParameterExpander - Skipping expansion of field: private static final long org.joda.time.DateTime.serialVersionUID, not a valid bean property
Depending on your object and its needs, you may need to define a mapping using the SwaggerSpringMvcPlugin.directModelSubstitute or make sure your object has matching getters/setters. Another option is to use the Jackson Data Binding library.

Related

Laravel Nova: Query params empty for /nova-api/installations/relate-authorization in hasMany relationship

I have defined a HasMany relationsship in my Nova resource. Nova fires two requests when trying to load the children in the parent detail view:
1. GET /nova-api/childResources?viaResource=parentResources&viaResourceId=4711&viaRelationship=childResources&relationshipType=hasMany
-> This correctly returns the related records.
2. GET /nova-api/childResources/relate-authorization?viaResource=parentResources&viaResourceId=4711&viaRelationship=childResources&relationshipType=hasMany
-> This fails with a HTTP 500 returning Class name must be a valid object or a string.
Digging deeper into the underlying NovaRequest, I found out that all query params are gone inside the request. This is why viaResource cannot be used to instantiate a class and to above error occurs.
I have no idea, what could cause this.
Turned out, the problem originated from an incomplete nginx configuration. I wasn’t passing the query string to PHP.

Breeze with second controller

I need to get some data from a different database (different server, actually), so I've created a second datacontext pointing to a second Breeze controller, repository, and edmx. I also created second model and entityManagerFactory since data I'll need to be getting is substantial and wanted to separate it from the base functionality. In my new EntityManagerFactory, if I have:
breeze.NamingConvention.none.setAsDefault();
all works well, but I don't get camel casing. If I have:
breeze.NamingConvention.camelCase.setAsDefault();
or if I don't call it at all (since it's just setting the app-wide default which is already set) I get this error:
[myDatacontext] [HT Error] Error retrieving dataMetadata query failed for: breeze/Vsp/Metadata. Unable to either parse or import metadata: NamingConvention for this server property name does not roundtrip properly:name-->Name; [object Object]Error: Metadata query failed for: breeze/Vsp/Metadata. Unable to either parse or import metadata: NamingConvention for this server property name does not roundtrip properly:name-->Name; [object Object]
There's not even a "name" or "Name" property on class I'm getting.
What am I missing?
By the way, I do get the metadata from the server. The client just doesn't like it.
I suppose that since you've posted this you found a solution.
But I also had this problem, it is because I use Entity-Framework ADO .Net 6.0, it takes into account stored procedure, views or tables that are not camelcase, so you have to unselect them before generating the model / context.

smart gwt save list as attribute

Hello i am new in smart gwt and now we are migrate from smartgwt 2.1 to smart gwt 3.1p
and i have got problem :
java.lang.UnsupportedOperationException: Can not convert element 0 of
the array to a JavaScriptObject. Instances of class
`com.test.ListDTO'
can not automatically be converted. Please see the SmartClient
documentation of RPCRequest.data for a table of Java types that can be
converted automatically.
someone write :
treeNode.setAttribute(TODO, listDTO.getLis());
how i can fix that code ?
The setAttribute method of the TreeNode tries to convert the list elements internally. That fails with your own domain objects. You can try to set the list with this helper method:
com.smartgwt.client.util.JSOHelper.setObjectAttribute(treeNode.getJsObj(), TODO, listDTO.getLis());
Now the Java object is set on the JavaScriptObject. To get this object back you can call:
treeNode.getAttributeAsObject(TODO);

Grails domain custom error messages

I am working in a grails application, I have many domains in the applications, more than 50! The error message generated are default, I have the following in my message.properties file
default.blank.message=Field "{0}" cannot be blank.
An example of my one of the domain class is as follows:
class Person {
String firstName;
String lastName;
String middleName;
Date dob;
String gender;
String religion;
String nationality;
String maritalStatus;
Zone permAddZone;
District permAddDistrict;
String permAddVDC;
}
And so on, so when I leave a field, for example 'maritalStatus' the following error message shows up, 'Field "maritialStatus" cannot be blank.'. I also added the following to my message.properties file
person.maritialStatus=Maritial Status
But still I am getting the 'Field "maritialStatus" cannot be blank.' message. I also tried using I18n Templates Plugin, but as I have a lot of domain classes, modifying error message for all of them would be time consuming. So, what choices do I have or what am I doing wrong. Any help is appreciated.
The appropriate message key to override is specified on the reference page for each constraint type. In the case of blank it's
com.example.Person.maritalStatus.blank=Marital status must not be blank
However this will be very time consuming and repetitive if you have many domains and many properties.
What you are asking for is instead a way to process the domain class property names in some way before they are inserted into the default messages. This isn't something Grails supports out of the box but I like a challenge... and I've found a surprisingly elegant way to implement it. My approach is the grails plugin available at https://github.com/ianroberts/recursive-messages and it works by extending the format string syntax to support placeholders of the form
default.blank.message=Field "{0,message,field.name.}" cannot be blank.
A placeholder {N,message,prefix} is resolved by prepending the given prefix to the usual placeholder replacement value and then treating the resulting string (field.name.maritalStatus in this example) as a no-argument message key, and looking that up in the usual way. Thus you could have different representations for different languages.
It has to be a plugin because it relies on a trick that works in a plugin's doWithSpring but doesn't work in an application's resources.groovy, to modify the definition of the default messageSource Spring bean.
Disclaimer: this was a quick fix, it hasn't been fully tested and could probably be implemented more efficiently.
In order to override the field label you need to override the key:
<package>.<domainclass>.<fieldname>.label
So in your case, try:
<package>.Person.martialStatus.label=Label

graphicimage not rendering streamedcontent in Primefaces

I'm using streamedcontent to render a byte sent from JSF then send it back as a streamed content as following:
<p:graphicImage value="#{manage.bytesToStreamedContent(car.image)}"/>
where image is the byte array of the image stored in the database
backing bean:
public StreamedContent bytesToStreamedContent(byte[] bytes)
{
InputStream is = new ByteArrayInputStream(bytes);
StreamedContent image = new DefaultStreamedContent (is, "image/jpeg");
return image;
}
But I'm not getting the image in the JSF page. I got this message appearing in the server log:
WARNING: JSF1091: No mime type could be found for file dynamiccontent. To resolve this, add a mime-type mapping to the applications web.xml.
and:
SEVERE: Error in streaming dynamic resource.
can you please help me out here, I cant find any useful info regarding this issue
PS:
Im using the following libraries:
Mojarra 2.1.3
PrimeFaces 3.1.1
Glassfish 3.1
Found where the problem was. The problem wasn't in the graphicimage. It was because the graphicimage tag is being loaded dynamically (similar issue when trying loading from datatable). Dynamic images cannot be rendered directly in datatable or datagrid. (Workaround is to assign a param and bring the images from the id).
However, the solution is here
This is an odd problem and I don't think that adding the mime-type to web.xml will fix it. It is listed as both a bug in PrimeFaces with a target for 3.2
http://code.google.com/p/primefaces/issues/detail?id=3546
And it is also listed as an open bug in Mojarra 2.1.1. There is a patch submitted for this bug however it looks like you will have to manually apply the code to the Mojarra 2.1.1 source and build it. One would think that this would be fixed in 2.1.3 however, Glassfish may have its own prebundled Mojarra implementation that is still at an earler version and your application may be using this instead.
http://java.net/jira/browse/JAVASERVERFACES-2103
EDIT:
You can just pass the byte[] directly as an argument to the method like that. What you can do though is pass the id of the car as a param and then retrieve that car and fetch the bytes from the Car entity. The reason for this is because the graphicImage actually renders as an HTML img tag and this occurs in a separate HTTP request from the request for the JSF page. Download and install the Firebug plugin for Firefox and you will see this occur, the page is requested, then subsequent requests occur for the images after the page is retrieved. Because of this ViewScoped and RequestScoped beans cannot be accessed in this way, however a request parameter can still be passed with the necessary information needed to retrieve the Car bytes for the image.
<p:graphicImage value="#{manage.bytesToStreamedContent}">
<f:param name="item_id" value="#{car.id}" />
</p:graphicImage>
Now in your managed bean property you can get the car id, and after you get the car id you should be able to get the right car.
public StreamedContent getBytesToStreamedContent() {
String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("item_id");
//Now get the car with the id
}
In general, it's not a great idea to create the StreamedContent in the getter for graphicimage. The image will be fetched in a separate request from the rest of the content, meaning variables depending on iterators will not work. This means that in the relevant call to bytesToStreamedContent the bytes array will be null/empty. If you put breakpoints inside the method you will probably see that in the last call there is no data in bytes.
You need to make sure the image is generated while you still have access to all the needed content and then store it in a way that you get retrieve it again in bytesToStreamedContent. Whether or not this will fix the problem and actually work for you is hard to say without seeing the rest of the code. I would start by trying to remove the byte array argument and returning a static image to confirm that this is the problem.

Resources