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

Change the client method's signature to be consistent with the HTTP client #1698

Merged
merged 35 commits into from
May 2, 2024

Conversation

TharmiganK
Copy link
Contributor

@TharmiganK TharmiganK commented Apr 29, 2024

Purpose

$Subject

Fixes: ballerina-platform/ballerina-library#6475

Example

The new generated client:

public isolated client class Client {
    ...

    # + headers - Headers to be sent with the request 
    # + queries - Queries to be sent with the request 
    # + return - Ok 
    resource isolated function get albums(GetAlbumsHeaders headers, *GetAlbumsQueries queries) returns Album[]|error {
        string resourcePath = string `/albums`;
        resourcePath = resourcePath + check getPathForQueryParam(queries);
        map<string|string[]> httpHeaders = getMapForHeaders(headers);
        return self.clientEp->get(resourcePath, httpHeaders);
    }

    # + headers - Headers to be sent with the request 
    # + queries - Queries to be sent with the request 
    # + return - Created 
    resource isolated function post albums(PostAlbumsHeaders headers, Album payload, *PostAlbumsQueries queries) returns Album|error {
        string resourcePath = string `/albums`;
        resourcePath = resourcePath + check getPathForQueryParam(queries);
        map<string|string[]> httpHeaders = getMapForHeaders(headers);
        http:Request request = new;
        json jsonBody = payload.toJson();
        request.setPayload(jsonBody, "application/json");
        return self.clientEp->post(resourcePath, request, httpHeaders);
    }
}

The new header and query records:

# Represents the Headers record for the operation: postAlbums
public type PostAlbumsHeaders record {
    string user\-id;
    Version version;
};

# Represents the Headers record for the operation: getAlbums
public type GetAlbumsHeaders record {
    string user\-id;
    Version version;
};

public type Version "V2"|"V1";

# Represents the Queries record for the operation: postAlbums
public type PostAlbumsQueries record {
    string? directory?;
};

# Represents the Queries record for the operation: getAlbums
public type GetAlbumsQueries record {
    # The genre
    string? genre?;
};

@TharmiganK TharmiganK force-pushed the fix-client-method-signature branch from 901a6e9 to aaf916a Compare April 29, 2024 16:32
@TharmiganK TharmiganK force-pushed the fix-client-method-signature branch from aaf916a to 7e4eeef Compare April 29, 2024 16:55
TharmiganK and others added 26 commits April 30, 2024 10:19
…ignature

# Conflicts:
#	openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/FunctionBodyGeneratorImp.java
#	openapi-core/src/main/java/io/ballerina/openapi/core/generators/client/parameter/RequestBodyHeaderParameter.java
#	openapi-core/src/main/java/io/ballerina/openapi/core/generators/document/TypesDocCommentGenerator.java
@TharmiganK TharmiganK force-pushed the fix-client-method-signature branch from ac9f7df to a3d10ff Compare May 2, 2024 11:47
Copy link

sonarqubecloud bot commented May 2, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
20.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link
Member

@lnash94 lnash94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, rest of the code review and suggestions we will address via separate PR

@TharmiganK TharmiganK marked this pull request as ready for review May 2, 2024 12:31
@TharmiganK TharmiganK merged commit 42e56c7 into master May 2, 2024
3 of 4 checks passed
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.

Improve the OpenAPI generated client's method signature to match the HTTP client's method signature
2 participants