Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation: fixing api_doc to generate meaningful example #9

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

arnaudgeiser
Copy link
Contributor

@arnaudgeiser arnaudgeiser commented Sep 11, 2024

Fixing the api_doc.mustache to generate a more meaningful example, below is a code snippet of the generated examples for different kinds of HTTP methods:

getInstance

Instance getInstance(id)

Retrieve Compute instance details

Example

// Import classes:
import com.exoscale.sdk.client.ApiException;
import com.exoscale.sdk.client.*;
import com.exoscale.sdk.client.models.*;
import com.exoscale.sdk.api.ExoscaleApi;

public class Example {
    public static void main(String[] args) throws ApiException, InterruptedException{
        // Initialize the client with credentials
        Client client = new Client(new Credentials(System.getenv("EXOSCALE_API_KEY"), System.getenv("EXOSCALE_API_SECRET")));
        UUID id = UUID.randomUUID(); // UUID | 

        try {
            // Invoke the API method
            Instance result = client.getInstance(id);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling ExoscaleApi#getInstance");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

createInstance

Operation createInstance(createInstanceRequest)

Create a Compute instance

Example

// Import classes:
import com.exoscale.sdk.client.ApiException;
import com.exoscale.sdk.client.*;
import com.exoscale.sdk.client.models.*;
import com.exoscale.sdk.api.ExoscaleApi;

public class Example {
    public static void main(String[] args) throws ApiException, InterruptedException{
        // Initialize the client with credentials
        Client client = new Client(new Credentials(System.getenv("EXOSCALE_API_KEY"), System.getenv("EXOSCALE_API_SECRET")));
        CreateInstanceRequest createInstanceRequest = new CreateInstanceRequest(); // CreateInstanceRequest |  please add at least all the required fields

        try {
            // Invoke the API method
            Operation result = client.createInstance(createInstanceRequest);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling ExoscaleApi#createInstance");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

deleteInstance

Operation deleteInstance(id)

Delete a Compute instance

Example

// Import classes:
import com.exoscale.sdk.client.ApiException;
import com.exoscale.sdk.client.*;
import com.exoscale.sdk.client.models.*;
import com.exoscale.sdk.api.ExoscaleApi;

public class Example {
    public static void main(String[] args) throws ApiException, InterruptedException{
        // Initialize the client with credentials
        Client client = new Client(new Credentials(System.getenv("EXOSCALE_API_KEY"), System.getenv("EXOSCALE_API_SECRET")));
        UUID id = UUID.randomUUID(); // UUID | 

        try {
            // Invoke the API method
            Operation result = client.deleteInstance(id);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling ExoscaleApi#deleteInstance");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

updateInstance

Operation updateInstance(id, updateInstanceRequest)

Update a Compute instance

Example

// Import classes:
import com.exoscale.sdk.client.ApiException;
import com.exoscale.sdk.client.*;
import com.exoscale.sdk.client.models.*;
import com.exoscale.sdk.api.ExoscaleApi;

public class Example {
    public static void main(String[] args) throws ApiException, InterruptedException{
        // Initialize the client with credentials
        Client client = new Client(new Credentials(System.getenv("EXOSCALE_API_KEY"), System.getenv("EXOSCALE_API_SECRET")));
        UUID id = UUID.randomUUID(); // UUID | 
        UpdateInstanceRequest updateInstanceRequest = new UpdateInstanceRequest(); // UpdateInstanceRequest |  please add at least all the required fields

        try {
            // Invoke the API method
            Operation result = client.updateInstance(id, updateInstanceRequest);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling ExoscaleApi#updateInstance");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Some insight on templates have been taken from DefaultCodegen.java

@elkezza elkezza self-requested a review September 12, 2024 09:23
@elkezza elkezza changed the title API doc with Exoscale client documentation: fixing api_doc to generate meaningful example Sep 12, 2024
@elkezza elkezza merged commit 97cd6f8 into main Sep 12, 2024
2 checks passed
@elkezza elkezza deleted the api-doc branch September 12, 2024 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants