-
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
Map default error status code in Ballerina to OpenAPI spec generation #4924
Comments
Task 01: Updating the error code when the resource has nil return. import ballerina/http;
service / on new http:Listener(9090) {
//with query parameter
resource function delete name(string id) {
};
// with path parameter
resource function post name/[string id]() {
};
//with header parameter
resource function get name(@http:Header string header) {
};
//with requestBody
resource function put name(@http:Payload string payload) {
}; Expected generated yaml paths:
/name:
get:
operationId: getName
parameters:
- name: header
in: header
required: true
schema:
type: string
responses:
"202":
description: Accepted
"400":
description: BadRequest
put:
operationId: putName
requestBody:
content:
text/plain:
schema:
type: string
responses:
"202":
description: Accepted
"400":
description: BadRequest
delete:
operationId: deleteName
parameters:
- name: id
in: query
required: true
schema:
type: string
responses:
"202":
description: Accepted
"400":
description: BadRequest
/name/{id}:
post:
operationId: postNameId
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"202":
description: Accepted
"400":
description: BadRequest
components: {} Note: Fix should include for all GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS @shafreenAnfar , @TharmiganK appreciate input regarding this. |
nil
type in Ballerina to OpenAPI spec generation
Task 02: Updating status code details when the resource has a specific return type with nil type service /payloadV on new http:Listener(9090) {
resource function get path() returns http:NotFound? {
}
resource function get path_with_query(string id) returns http:NotFound? {
};
...
} expected response mapping paths:
/path:
get:
operationId: getPath
responses:
"202":
description: Accepted
"404":
description: NotFound
/path_with_query:
get:
operationId: getPathWithQuery
parameters:
- name: id
in: query
required: true
schema:
type: string
responses:
"202":
description: Accepted
"400":
description: BadRequest
"404":
description: NotFound |
Both mappings are correct here. What about this scenario when we return a data type with service on new http:Listener(9090) {
resource function get path1() returns string? {}
resource function get path2(string id) returns Student|http:NotFound? {}
} I do not think this is a practical case, but a possible scenario |
Another most common scenario to have a
service on new http:Listener(9090) {
resource function get path(http:Caller caller) returns error? {}
}
|
Currently, the tool doesn't map details regarding the |
@TharmiganK For the mentioned scenarios, it will take a status code relevant to the string payload. /path1:
get:
operationId: getPath
responses:
"200":
description: Ok
content:
text/plain:
schema:
type: string
"202":
description: Accepted
/path2:
get:
operationId: operation2
parameters:
- name: id
in: query
required: true
schema:
type: string
responses:
"200":
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/Student"
"202":
description: Accepted
"400":
description: BadRequest
"404":
description: NotFound If the given type is When the given sample with service on new http:Listener(9090) {
resource function post path1() returns string? {}
resource function post path2(string id) returns Student|http:NotFound? {}
} expected yaml code /path1:
post:
operationId: postPath
responses:
"201":
description: Created
content:
text/plain:
schema:
type: string
"202":
description: Accepted
/path2:
post:
operationId: operation2
parameters:
- name: id
in: query
required: true
schema:
type: string
responses:
"201":
description: Created
content:
application/json:
schema:
$ref: "#/components/schemas/Student"
"202":
description: Accepted
"400":
description: BadRequest
"404":
description: NotFound |
nil
type in Ballerina to OpenAPI spec generation
Description:
The purpose is to map default error code details when the user doesn't provide a specific return type in the resource.
Task 01: Updating the error code when the resource has nil return.
Task 02: Updating status code details when the resource has a specific return type with nil type
example for task 02:
The text was updated successfully, but these errors were encountered: