Open M-Landwehr opened 3 years ago
hey @M-Landwehr, did you find a way to work around this? we're facing the exact same issue, also tried a couple of other generators but didn't get lucky so far...btw still present in 5.1.0 :-/
Any news on the issue, I am facing the same issue. Any work-around ?
Same for me :(
Same for me. Tried to use a custom ParamConverter
I "solved" it by modifying the mustache template files.
In api.mustache
I added the following two imports:
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
In apiInterface.mustache
I replaced the last line with
{{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{>returnTypeInterface}}{{/returnResponse}}{{/supportAsync}} {{nickname}}({{#isMultipart}}@MultipartForm MultipartFormDataInput multipartFormDataInput{{#allParams}}{{^isFormParam}}, {{/isFormParam}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{/allParams}}{{/isMultipart}}{{^isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}{{/isMultipart}});
And in apiMethod.mustache
I replaced the third line from the bottom with
public {{#supportAsync}}CompletionStage<{{/supportAsync}}Response{{#supportAsync}}>{{/supportAsync}} {{nickname}}({{#isMultipart}}@MultipartForm MultipartFormDataInput multipartFormDataInput{{#allParams}}{{^isFormParam}}, {{/isFormParam}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{/allParams}}{{/isMultipart}}{{^isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}{{/isMultipart}}) {
@fsiegrist It works with the link you provided. But you need to implement both classes:
package example
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.nio.charset.StandardCharsets
import javax.ws.rs.ext.ParamConverter
import javax.ws.rs.ext.Provider
@Provider
class FileConverterProvider: ParamConverter<InputStream> {
override fun toString(value: InputStream): String {
return String(value.readAllBytes(), StandardCharsets.UTF_8)
}
override fun fromString(value: String): InputStream {
return ByteArrayInputStream(value.toByteArray())
}
}
package example
import java.io.InputStream
import java.lang.reflect.Type
import javax.ws.rs.ext.ParamConverter
import javax.ws.rs.ext.ParamConverterProvider
import javax.ws.rs.ext.Provider
@Provider
class FileParamConverterProvider: ParamConverterProvider {
override fun <T : Any?> getConverter(
rawType: Class<T>?,
genericType: Type?,
annotations: Array<out Annotation>?
): ParamConverter<T>? {
return if (rawType!!.isAssignableFrom(InputStream::class.java)) {
(FileConverterProvider() as ParamConverter<T>?)!!
} else null
}
}
@fsiegrist thanks for suggesting custom converter, it worked for me below is the java code
@Provider
public class InstantParamConverter implements ParamConverter<InputStream> {
public InputStream fromString(String value){
try {
return IOUtils.toInputStream(value);
} catch (Exception e) {
}
return null;
}
public String toString(InputStream value){
return value.toString();
}
}
@Provider
public class InstantParamConverterProvider implements ParamConverterProvider
{
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations)
{
if (rawType.isAssignableFrom(InputStream.class)) {
return (ParamConverter<T>) new InstantParamConverter();
}
return null;
}
}
Description
When creating Java code from a openapi.yml for quakus, the resulting code does not work:
RESTEASY003875: Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.FormParam("file") on public abstract void org.openapitools.api.UploadApi.uploadPost(java.io.InputStream,java.lang.String) for basetype: java.io.InputStream
Quarkus cannot handle the geneated method signature of the Rest-resource-class:
(Additionally, no validation annotations are created!)
openapi-generator version
OpenAPI declaration file content or url
Command line used for generation
Quarkus-Version: 1.9.2.Final
Steps to reproduce
mvnw package quarkus:dev
mvnw package quarkus:dev
Alternatively simply generate java code from the openapi.yml above using the jaxrs-spec generator and the quarkus library
Related issues/PRs
Suggest a fix/enhancement
The model-class is created but is not used in this case. (althogh is has
@JsonProperty
annotations insteadod the@FormParam
annotationsA possible fix would be to
multipart/form-data
request:@FormParam
public void uploadPost(@MultipartForm @Valid MultipartData data) {}
(see https://quarkus.io/guides/rest-client-multipart)