swagger-api / swagger-api/swagger-codegen

[JAVA] Swagger api client methods return void

Open
#6,326 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Swagger api client, generated by codegen tool, only creates tests methods with return type void. How can I test my rest api ?

Swagger-codegen version

2.2.3

Swagger declaration file content or url

This is my service code specification:

 @Api(value = "Authentication Recovery")
 @Path("/authenticationRecovery")

public class AuthenticationRecoveryResource implements Authentication{

@ApiOperation(
		value = "Recover access token"
		, notes = "Recover access token assigned to the user (once it has been authenticated)"
		, response = TokenJAXB.class
		//, responseContainer = "List"
)
@ApiResponses(value = { 
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Authorized access") ,
		@ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized access") 
})
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response authenticate(
		@ApiParam(value="Username", required=true) @FormParam("username") String username,
		@ApiParam(value="Password", required=true) @FormParam("password") String password) 
{..}

And this is my generated swagger code for testing:

/**
  * API tests for AuthenticationRecoveryApi
*/
@Ignore

public class AuthenticationRecoveryApiTest {

private final AuthenticationRecoveryApi api = new AuthenticationRecoveryApi();

/**
 * Recover access token
 *
 * Recover access token assigned to the user (once it has been authenticated)
 *
 * @throws ApiException
 *             if the Api call fails
 */
@Test
public void authenticateTest() throws ApiException {
	String username = null;
	String password = null;
	api.authenticate(username, password);

	// TODO: test validations
}}
Command line used for generation

I have generate a swagger client api with:

java -jar swagger-codegen-2.2.3/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://localhost:8080/myproject/services/service0/swagger.json -l java -o client/myproject/java

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing generation with swagger-codegen 2.2.3 using the supplied Swagger declaration and command, then inspect the generated AuthenticationRecoveryApiTest and its AuthenticationRecoveryApi client method. Compare the declared TokenJAXB response with the generated method signature and test behavior; done means the generated Java client test can observe the endpoint result rather than only invoke a void method.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.