Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Sep 22, 2024
1 parent 2b5c2d5 commit 19806cc
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public Object[][] dataProviderForFunctionBody() {
{"diagnostic_files/header_parameter.yaml", "/pets", true, false, false,
"{string resourcePath=string`/pets`;" +
"map<string|string[]>" +
"httpHeaders=getMapForHeaders(headers);return self.clientEp->" +
"httpHeaders=http:getHeaderMap(headers);return self.clientEp->" +
"get(resourcePath,httpHeaders);}"},
{"diagnostic_files/head_operation.yaml", "/{filesystem}", true, false, true,
"{string resourcePath=string`/${getEncodedUri(filesystem)}`;" +
"resourcePath = resourcePath + check getPathForQueryParam(queries);" +
"map<string|string[]> httpHeaders = getMapForHeaders(headers);" +
"map<string|string[]> httpHeaders = http:getHeaderMap(headers);" +
"return self.clientEp-> head(resourcePath, httpHeaders);}"},
{"diagnostic_files/operation_delete.yaml", "/pets/{petId}", false, false, false,
"{string resourcePath = " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public isolated client class Client {
resource isolated function get albums/[int id](GetAlbumsIdHeaders headers = {}, *GetAlbumsIdQueries queries) returns record {}|error {
string resourcePath = string `/albums/${getEncodedUri(id)}`;
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Expand Down Expand Up @@ -217,12 +217,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public isolated client class Client {
resource isolated function get albums/[string id](GetAlbumsIdHeaders headers = {}, *GetAlbumsIdQueries queries) returns Album|error {
string resourcePath = string `/albums/${getEncodedUri(id)}`;
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Expand Down Expand Up @@ -217,12 +217,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2904,12 +2904,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// AUTO-GENERATED FILE.
// This file is auto-generated by the Ballerina OpenAPI tool.

import ballerina/http;
import ballerina/url;

type SimpleBasicType string|boolean|int|float|decimal;
Expand Down Expand Up @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// AUTO-GENERATED FILE. DO NOT MODIFY.
// This file is auto-generated by the Ballerina OpenAPI tool.

import ballerina/http;
import ballerina/url;

type SimpleBasicType string|boolean|int|float|decimal;
Expand Down Expand Up @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2023 All Rights Reserved.

import ballerina/http;
import ballerina/url;

type SimpleBasicType string|boolean|int|float|decimal;
Expand Down Expand Up @@ -169,12 +170,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public isolated client class Client {
headerValues["api_key"] = self.apiKeyConfig?.api_key;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public isolated client class Client {
# + return - Invalid ID supplied
remote isolated function deletePet(int petId, DeletePetHeaders headers = {}) returns http:Response|error {
string resourcePath = string `/pet/${getEncodedUri(petId)}`;
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public isolated client class Client {
if self.apiKeyConfig is ApiKeysConfig {
headerValues["api_key"] = self.apiKeyConfig?.api_key;
}
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

Expand All @@ -186,7 +186,7 @@ public isolated client class Client {
if self.apiKeyConfig is ApiKeysConfig {
headerValues["api_key"] = self.apiKeyConfig?.api_key;
}
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public isolated client class Client {
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);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Expand Down Expand Up @@ -219,12 +219,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public isolated client class Client {
resource isolated function get albums(GetAlbumsHeaders headers = {}, *GetAlbumsQueries queries) returns AlbumNewOne[]|error {
string resourcePath = string `/albums`;
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Expand Down Expand Up @@ -219,12 +219,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
8 changes: 5 additions & 3 deletions openapi-cli/src/test/resources/expected_gen/utils.bal
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ballerina/http;
import ballerina/url;

type SimpleBasicType string|boolean|int|float|decimal;
Expand Down Expand Up @@ -170,12 +171,13 @@ isolated function getEncodedUri(anydata value) returns string {
# + encodingMap - Details on serialization mechanism
# + return - Returns generated Path or error at failure of client initialization
isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> encodingMap = {}) returns string|error {
map<anydata> queriesMap = http:getQueryMap(queryParam);
string[] param = [];
if queryParam.length() > 0 {
if queriesMap.length() > 0 {
param.push("?");
foreach var [key, value] in queryParam.entries() {
foreach var [key, value] in queriesMap.entries() {
if value is () {
_ = queryParam.remove(key);
_ = queriesMap.remove(key);
continue;
}
Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public isolated client class Client {
queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2;
}
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}

Expand All @@ -73,7 +73,7 @@ public isolated client class Client {
queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2;
}
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}

Expand All @@ -91,7 +91,7 @@ public isolated client class Client {
queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2;
}
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

Expand All @@ -108,7 +108,7 @@ public isolated client class Client {
queryParam["api-key-2"] = self.apiKeyConfig?.api\-key\-2;
}
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
return self.clientEp->post(resourcePath, request, httpHeaders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public isolated client class Client {
# + return - Status OK
remote isolated function deleteHeader(DeleteHeaderHeaders headers) returns error? {
string resourcePath = string `/header`;
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}

Expand All @@ -51,7 +51,7 @@ public isolated client class Client {
# + return - Status OK
remote isolated function deleteHeaderRequestBody(DeleteHeaderRequestBodyHeaders headers, json payload) returns error? {
string resourcePath = string `/header-with-request-body`;
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
http:Request request = new;
request.setPayload(payload, "application/json");
return self.clientEp->delete(resourcePath, request, httpHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public isolated client class Client {
string resourcePath = string `/pets`;
map<anydata> headerValues = {...headers};
headerValues["X-API-KEY"] = self.apiKeyConfig.X\-API\-KEY;
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public isolated client class Client {
map<anydata> queryParam = {...queries};
queryParam["appid"] = self.apiKeyConfig.appid;
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public isolated client class Client {
map<anydata> queryParam = {...queries};
queryParam["appid"] = self.apiKeyConfig.appid;
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
map<string|string[]> httpHeaders = getMapForHeaders(headers);
map<string|string[]> httpHeaders = http:getHeaderMap(headers);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public isolated client class Client {
string resourcePath = string `/pets`;
map<anydata> headerValues = {...headers};
headerValues["X-API-KEY"] = self.apiKeyConfig.X\-API\-KEY;
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public isolated client class Client {
string resourcePath = string `/pets`;
map<anydata> headerValues = {...headers};
headerValues["X-API-KEY"] = self.apiKeyConfig.X\-API\-KEY;
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}
}
Loading

0 comments on commit 19806cc

Please sign in to comment.