swagger-api / swagger-api/swagger-codegen
[JAVA][HYSTRIXCOMMAND][JAVA8] Incorrect Code when generating java8 client code with hystrixcommand response wrapper
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
when generating a java client using:
language = java
and options:
dateLibrary = java8
responseWrapper = HystrixCommand
interfaceOnly = true
the result won't compile. It generates a default implementation of the api interface methods that return a ResponseEntity although the method signature says it should return a HystrixCommand<ResponseEntity>
e.g. that's what is generated on my interface:
default com.netflix.hystrix.HystrixCommand<ResponseEntity<StoreResponse>> v1SessionPost(@ApiParam(value = "Transaction Identifier" ,required=true) @RequestHeader(value="transactionId", required=true) String transactionId,@ApiParam(value = "Client Identifier" ,required=true) @RequestHeader(value="clientId", required=true) String clientId,@ApiParam(value = "store_request" ,required=true ) @Valid @RequestBody StoreRequest body) {
if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
if (getAcceptHeader().get().contains("application/json")) {
try {
return new ResponseEntity<>(getObjectMapper().get().readValue("{ \"payload\" : { }, \"lifespan\" : 3000, \"expiry_date\" : \"2018-10-05 18:21:16.096\", \"ack\" : 1, \"session_id\" : \"507f191e810c19729de860ea\"}", StoreResponse.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
} else {
log.warn("ObjectMapper or HttpServletRequest not configured in default MethodsApi interface so no example is generated");
}
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
Swagger-codegen version
I've tried 2.3.1, 2.3.2 and 2.4.8 they all have the bug
Swagger declaration file content or url
you can use any yaml even PetStore
Command line used for generation
I used the maven plugin with this configuration:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.2-assist-patch</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/session-manager.yaml</inputSpec>
<language>spring</language>
<modelPackage>it.vodafone.dxl.session.model</modelPackage
<apiPackage>it.vodafone.dxl.session.api</apiPackage>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<dateLibrary>java8</dateLibrary>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<library>spring-cloud</library>
<interfaceOnly>true</interfaceOnly>
<responseWrapper>HystrixCommand</responseWrapper>
<components>
<component>models</component>
<component>apis</component>
</components>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Related issues/PRs
none that i know of
Suggest a fix/enhancement
The HystrixCommand wrapper should be added to the inners of the default interface methods implementation so code would compile
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 with the swagger-codegen Maven plugin configuration using language=spring, dateLibrary=java8, interfaceOnly=true, and responseWrapper=HystrixCommand, then inspect the generated Java API interface and its default methods. Reproduce the compilation failure and update the relevant generation template so the default implementation return values match the HystrixCommand-wrapped signatures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100