Closed lnash94 closed 6 months ago
2022/11/23 Attendees: @NipunaRanasinghe , @aneeshafedo , @lnash94 Discussion outcomes: Suggested two options and pick the best one after having a feasibility study;
As given in the issue description above, although OpenAPI specification supports having two paths which are different only by the path parameter name, in ballerina we cannot define two resource functions with same path segments but different path param names.
In the earlier design when remote functions are the recommended functions to use in client classes, this issue does not appear since we can provide unique function names.
When tried out the clients generated for the same OpenAPI in Java and Go languages both support this scenario. I think its better to figure out a way to support this if its a valid API use case.
@shafreenAnfar @TharmiganK Is this a valid scenario for you ?
After a discussion with @NipunaRanasinghe @shafreenAnfar decided to handle the scenario within the resource function since there is no support available or planned to provide for this kind of scenario in ballerina http module
The alternative approach suggested in the discussion is as follows.
public type COUNTRY string;
public type COUNTRIES string;
# Get COVID-19 totals for a specific country or Get COVID-19 totals for a specific set of countries
#
# + countryOrCountries - A country name, iso2, iso3, or country ID code or Multiple country names, iso2, iso3, or country IDs separated by commas
# + yesterday - Enter `true`(1) to receive data reported a day ago. Default is `false`(0)
# + twoDaysAgo - Enter `true`(1) to receive data reported two days ago. Default is `false`(0)
# + strict - Setting to false gives you the ability to fuzzy search countries (i.e. Oman vs. rOMANia)
# + allowNull - By default, value is 0. Enter `1` to allow nulls to be returned
# + return - COVID-19 status of the given country or COVID-19 status of the given countries
resource isolated function get v3/'covid\-19/countries/[COUNTRY|COUNTRIES countryOrCountries](string? yesterday = (), string? twoDaysAgo = (), string strict = "true", string? allowNull = ()) returns CovidCountry|CovidCountries|error {
string resourcePath = string `/v3/covid-19/countries/${getEncodedUri(countryOrCountries)}`;
map<anydata> queryParam = {"yesterday": yesterday, "twoDaysAgo": twoDaysAgo, "strict": strict, "allowNull": allowNull};
resourcePath = resourcePath + check getPathForQueryParam(queryParam);
CovidCountry|CovidCountries response = check self.clientEp->get(resourcePath);
return response;
}
The same issue can be found when generating services from the same openapi definition file.
the same issue occurred in below connectors:
Closing this issue since this behaviour is expected since the user has defined the two paths with the same semantics behaviour.
Description:
When trying to generate a client with this OpenAPI spec https://github.com/ballerina-platform/openapi-connectors/blob/main/openapi/covid19/openapi.yaml using this command
bal openapi -i <openapi.yaml> --mode client
Receive this compilation errorsReason was given openapi YAML has similar endpoints.
Therefore question with a validity of this spec.
Steps to reproduce:
Affected Versions: 2201.3.0-rc2
OS, DB, other environment details and versions:
Related Issues (optional):
Suggested Labels (optional):
Suggested Assignees (optional):