-
Notifications
You must be signed in to change notification settings - Fork 65
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
HTTP compiler plugin rewrite #4152
Comments
Change 1: Ballerina type Address [string, string, string];
type User record {|
string name;
Address address;
|};
type UserWithId [int, User];
class Organization {};
type UserNew record {|
*User;
Organization org;
|};
service on new http:Listener(9090) {
resource function get address() returns [string, string, string] {
return ["221B", "Baker Street", "London"];
}
resource function post address(@http:Payload Address address) {}
resource function get User() returns User {
return {name: "Sherlock Holmes", address: ["221B", "Baker Street", "London"]};
}
resource function post User(@http:Payload User user) {}
resource function get UserWithId() returns UserWithId {
return [1, {name: "Sherlock Holmes", address: ["221B", "Baker Street", "London"]}];
}
// Error : HTTP_107 - invalid payload parameter type
resource function post UserNew(@http:Payload UserNew user) {}
} |
Change 2: Error code class Family {}
type Person record {
string name;
int age;
Family family?;
};
service on new http:Listener(9090) {
// Previously: incompatible record field type: Family in payload parameter: person(HTTP_145)
// Now: invalid payload parameter type: Person(HTTP_107)
resource function post person(@http:Payload Person person) {}
} |
Change 3: Nested records are not allowed incase of header parameters. (This is a bug fix. Seems like this bug is somehow introduced while fixing some other bugs) type RateLimitHeaders record {|
string x\-rate\-limit\-id;
int? x\-rate\-limit\-remaining;
string[]? x\-rate\-limit\-types;
|};
type NestedRecord record {|
RateLimitHeaders xRate;
|};
service on new http:Listener(9090) {
// Previously: not a compiler error, but runtime will fail with header not found for `xRate`
// Now: invalid type of header param: xRate(HTTP_109)
resource function get hello(@http:Header NestedRecord headers) {}
} |
Change 4: The error for nilable unsupported singleton types will be reported as type RateLimitHeaders record {|
string x\-rate\-limit\-id;
|};
service on new http:Listener(9090) {
// Prevoiusly: HTTP_110 - invalid union type of header param headers
// Now: HTTP_109 - invalid type of header param headers
resource function get greeting(@http:Header RateLimitHeaders[]? headers, xml? query) returns string {
return "Hello, World!";
}
// HTTP_109 - invalid type of header param headers
resource function get hello(@http:Header RateLimitHeaders|string headers, string|int query) returns string {
return "Hello!";
}
} |
Change 5:
// This closed record will be always a subtype of `map<json>`
type User record {|
string name;
int age;
|};
type UserNew record {|
*User;
xml data;
|};
service on new http:Listener(9090) {
resource function get greeting(User user) returns string {
return "Hello, World!";
}
// Error: invalid type of query param: user(HTTP_112)
resource function get hello(UserNew user) returns string {
return "Hello!";
}
}
// This closed record will be always a subtype of `map<json>`
type User record {|
string name;
int age;
|};
type UserOpen record {
*User;
};
service on new http:Listener(9090) {
resource function get greeting(map<User> user) returns string {
return "Hello, World!";
}
resource function get bye(map<string|int?> user) returns string {
return "Bye, World!";
}
// Error - invalid query param type: user(HTTP_112)
resource function get greetingUser(map<UserOpen> user) returns string {
return "Hello, User!";
}
} |
Checked the runtime for this support, currently this is not supported by runtime since we only cast the value to |
Description:
Currently the HTTP compiler plugin validations are depends on the
TypeDescriptor
of theTypeSymbol
. This logic creates some unexpected bugs due to some missing cases.Some of the bugs are :
TypeReference
kind return types gives compile time error in resource functions #4043There is a compiler plugin
types
API which can be used to check whether aTypeSymbol
is a subtype of givenTypeSymbol
. This can be used to simplify our validation logics. For example, the payload validation can be simplified by just checking whether the payload type is a subtype ofanydata
type symbol. Thisanydata
type symbol can be retrieved from theAnalysisContext
.Describe your task(s)
The text was updated successfully, but these errors were encountered: