swagger-api / swagger-api/swagger-codegen
[JAVA] Would be nice if StreamingOutput/Media type APPLICATION_OCTET_STREAM gives an Inputstream at the generated JAVA code.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If the media type is APPLICATION_OCTET_STREAM and the response is a javax.ws.rs.core.StreamingOutput, it would be nice to get an InputStream of bytes at the client side.
Currently the behaviour is, swagger generates its own StreamingOutput model which is apparently useless to do anything.
Swagger-codegen version
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.1</version>
Swagger declaration file content or url
Relevant portion of swagger json spec
"get": {
"vendorExtensions": {},
"operationId": "downloadResults",
"produces": [
"application/octet-stream"
],
"parameters": [],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "ref",
"required": false,
"vendorExtensions": {},
"$ref": "#/definitions/StreamingOutput",
"refFormat": "INTERNAL",
"simpleRef": "StreamingOutput"
},
"headers": {},
"vendorExtensions": {}
}
}
}
Command line used for generation
I am generating the spec myself as a part of maven goal through this
Swagger swagger = new Swagger();
final BeanConfig beanConfig = new BeanConfig();
beanConfig.setResourcePackage(ar[0]);
Info info = new Info();
beanConfig.setInfo(info);
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setBasePath("/");
final Scanner scanner = beanConfig;
swagger.info(info);
Set<Class<?>> classes = scanner.classes();
Reader reader = new Reader(swagger, null);
swagger = reader.read(classes);
swagger = ((SwaggerConfig) scanner).configure(swagger);
SwaggerConfigLocator.getInstance().putSwagger("swagger.config.id.default", swagger);
final ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
FileUtils.writeStringToFile(new File(ar[1]), mapper.writeValueAsString(swagger));
Used the following maven plugin artifact to generate code from spec
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.1</version>
Steps to reproduce
Return a javax.ws.rs.core.StreamingOutput with media type as APPLICATION_OCTET_STREAM.
Jersey streams the data to the client. We need to have client side models that can provide an input stream to consume this.
Suggest a Fix
We can probably return the InputStream from OkHttp if the PRODUCES is APPLICATION_OCTET_STREAM
InputStream is = response.body().byteStream();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the Java client generation path and the generated response handling for application/octet-stream, focusing on the OkHttp response body mentioned in the issue. Confirm how StreamingOutput is currently modeled, then verify that the generated client exposes a consumable byte stream for this media type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100