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 23, 2024
1 parent d8df945 commit fc20dcd
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 167 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 All @@ -247,23 +248,6 @@ isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> en
return restOfPath;
}

# Generate header map for given header values.
#
# + headerParam - Headers map
# + return - Returns generated map or error at failure of client initialization
isolated function getMapForHeaders(map<anydata> headerParam) returns map<string|string[]> {
map<string|string[]> headerMap = {};
foreach var [key, value] in headerParam.entries() {
if value is SimpleBasicType[] {
headerMap[key] = from SimpleBasicType data in value
select data.toString();
} else {
headerMap[key] = value.toString();
}
}
return headerMap;
}

# Provides settings related to HTTP/1.x protocol.
public type ClientHttp1Settings record {|
# Specifies whether to reuse a connection for multiple requests
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 All @@ -247,23 +248,6 @@ isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> en
return restOfPath;
}

# Generate header map for given header values.
#
# + headerParam - Headers map
# + return - Returns generated map or error at failure of client initialization
isolated function getMapForHeaders(map<anydata> headerParam) returns map<string|string[]> {
map<string|string[]> headerMap = {};
foreach var [key, value] in headerParam.entries() {
if value is SimpleBasicType[] {
headerMap[key] = from SimpleBasicType data in value
select data.toString();
} else {
headerMap[key] = value.toString();
}
}
return headerMap;
}

# Provides settings related to HTTP/1.x protocol.
public type ClientHttp1Settings record {|
# Specifies whether to reuse a connection for multiple requests
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 All @@ -249,23 +250,6 @@ isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> en
return restOfPath;
}

# Generate header map for given header values.
#
# + headerParam - Headers map
# + return - Returns generated map or error at failure of client initialization
isolated function getMapForHeaders(map<anydata> headerParam) returns map<string|string[]> {
map<string|string[]> headerMap = {};
foreach var [key, value] in headerParam.entries() {
if value is SimpleBasicType[] {
headerMap[key] = from SimpleBasicType data in value
select data.toString();
} else {
headerMap[key] = value.toString();
}
}
return headerMap;
}

# Provides settings related to HTTP/1.x protocol.
public type ClientHttp1Settings record {|
# Specifies whether to reuse a connection for multiple requests
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 All @@ -249,23 +250,6 @@ isolated function getPathForQueryParam(map<anydata> queryParam, map<Encoding> en
return restOfPath;
}

# Generate header map for given header values.
#
# + headerParam - Headers map
# + return - Returns generated map or error at failure of client initialization
isolated function getMapForHeaders(map<anydata> headerParam) returns map<string|string[]> {
map<string|string[]> headerMap = {};
foreach var [key, value] in headerParam.entries() {
if value is SimpleBasicType[] {
headerMap[key] = from SimpleBasicType data in value
select data.toString();
} else {
headerMap[key] = value.toString();
}
}
return headerMap;
}

public type AlbumNewOne record {|
# Album artist
string artist;
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
Loading

0 comments on commit fc20dcd

Please sign in to comment.