Swagger CodeGen is a tool that allows you to generate a DRACOON API client in a variety of programming languages. You can download Swagger CodeGen here.
To see available programming languages, enter the following command:
java -jar swagger-codegen-cli.jar langs
Use the following command to further see available options for Java :
java -jar swagger-codegen-cli.jar config-help -l java
Example: Generating a client for Java
java -jar swagger-codegen-cli.jar generate -i https://dracoon.team/api/spec_v4/ -o Dracoon --artifact-id dracoon-swagger --group-id com.dracoon -l java --library retrofit2
When finished, Swagger CodeGen has generated a full REST client a maven project that you can use the following way:
import java.io.IOException;
import io.swagger.client.ApiClient;
import io.swagger.client.api.AuthApi;
import io.swagger.client.api.NodesApi;
import io.swagger.client.model.LoginRequest;
import io.swagger.client.model.LoginResponse;
import io.swagger.client.model.NodeList;
import retrofit2.Call;
import retrofit2.Response;
public class Main {
public static void main(String[] args) throws IOException {
// get client instace
ApiClient client = new ApiClient();
AuthApi authApi = client.createService(AuthApi.class);
// login
LoginRequest loginRequest = new LoginRequest();
loginRequest.setLogin("MY_USERNAME");
loginRequest.setPassword("MY_PASSWORD");
Call loginCall = authApi.login(loginRequest);
Response response = loginCall.execute();
if(response.isSuccessful()){
// print auth token
String token = response.body().getToken();
System.out.println(token);
}
}
}
Kommentare
0 Kommentare
Zu diesem Beitrag können keine Kommentare hinterlassen werden.