ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Finalized the OpenAPI Client Validator Spec #5162

Open lnash94 opened 2 years ago

lnash94 commented 2 years ago

Description: This issue is created to track the subtask of openAPI client generator implementation.

Describe your task(s)

Related Issues (optional): Core issue: https://github.com/ballerina-platform/ballerina-standard-library/issues/5388

Suggested Labels (optional):

Suggested Assignees (optional):

lnash94 commented 2 years ago

Please find attached [2] for the initial proposal and some blockers we met during the effort of identifying the validation scenarios.

We have some limitations in resolving [client endpoint path](https://docs.google.com/document/d/19u5uzbcA1TCFLmEWG6m9yB11EkRGsIwUcjUAS_5DEo4/edit#heading=h.jsp3ot6p0seq), Since there is no type concept for URLs, we need to check the value itself against a URL template to uniquely identify resources and thereby validate requests and responses.

However, when validating the request and response all we need to do is get the type of the associate variable/argument and make sure its type is in line with the schema type in the OAS.

We envision the ballerina client as below way to validate.

type Person record {
   int age;
   string name;
};
public function main() returns error? {
   http:Client c = check new ("http://localhost:9090");

   int id;
    // 01. With string template
   json response = check c->post(string `/user/${id}`,
   {
       age: 18,
       name: "Harry"
   });
   // 02 With string value
   json response = check c2->post(“/user/1”,
   {
       age: 18,
       name: "Harry"
   });
}

Therefore we need to finalize our approach before starting our implementation