From 57a5399eb82550dcef1f0377c88afc293ae05a10 Mon Sep 17 00:00:00 2001 From: prakanth <50439067+prakanth97@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:21:24 +0530 Subject: [PATCH 1/8] Add BBE for xml to record using xmldata library --- .../bin/test/openapi/expected/client.bal | 69 ++++++++++++++ .../test/openapi/expected/filtered_tags.bal | 16 ++++ .../bin/test/openapi/expected/types.bal | 89 +++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 ballerina-test/bin/test/openapi/expected/client.bal create mode 100644 ballerina-test/bin/test/openapi/expected/filtered_tags.bal create mode 100644 ballerina-test/bin/test/openapi/expected/types.bal diff --git a/ballerina-test/bin/test/openapi/expected/client.bal b/ballerina-test/bin/test/openapi/expected/client.bal new file mode 100644 index 0000000000..ecd6433a87 --- /dev/null +++ b/ballerina-test/bin/test/openapi/expected/client.bal @@ -0,0 +1,69 @@ +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; + +# The Stripe REST API. Please see https://stripe.com/docs/api for more details. +public isolated client class Client { + final http:Client clientEp; + # Gets invoked to initialize the `connector`. + # + # + config - The configurations to be used when initializing the `connector` + # + serviceUrl - URL of the target service + # + return - An error if connector initialization failed + public isolated function init(ConnectionConfig config, string serviceUrl) returns error? { + http:ClientConfiguration httpClientConfig = {auth: config.auth, httpVersion: config.httpVersion, timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation}; + do { + if config.http1Settings is ClientHttp1Settings { + ClientHttp1Settings settings = check config.http1Settings.ensureType(ClientHttp1Settings); + httpClientConfig.http1Settings = {...settings}; + } + if config.http2Settings is http:ClientHttp2Settings { + httpClientConfig.http2Settings = check config.http2Settings.ensureType(http:ClientHttp2Settings); + } + if config.cache is http:CacheConfig { + httpClientConfig.cache = check config.cache.ensureType(http:CacheConfig); + } + if config.responseLimits is http:ResponseLimitConfigs { + httpClientConfig.responseLimits = check config.responseLimits.ensureType(http:ResponseLimitConfigs); + } + if config.secureSocket is http:ClientSecureSocket { + httpClientConfig.secureSocket = check config.secureSocket.ensureType(http:ClientSecureSocket); + } + if config.proxy is http:ProxyConfig { + httpClientConfig.proxy = check config.proxy.ensureType(http:ProxyConfig); + } + } + http:Client httpEp = check new (serviceUrl, httpClientConfig); + self.clientEp = httpEp; + return; + } + + # Retrieves a PaymentMethod object. + # + # + payment_method - Payment Method + # + paymentMethodName - Payment Method + # + xLimit - limit of the payment + # + return - Successful response. + remote isolated function getPaymentMethodsPaymentMethod(string payment_method, string paymentMethodName, string xLimit) returns json|error { + string resourcePath = string `/v1/payment_methods/${getEncodedUri(payment_method)}`; + map queryParam = {"payment method name": paymentMethodName}; + resourcePath = resourcePath + check getPathForQueryParam(queryParam); + map headerValues = {"X-LIMIT": xLimit}; + map httpHeaders = getMapForHeaders(headerValues); + return self.clientEp->get(resourcePath, httpHeaders); + } + + # Creates a new customer object. + # + # + customer - Customer ID + # + payload - Customer Details + # + return - Successful response. + remote isolated function postCustomers(string customer, Customer_customer_body payload) returns Customer|error { + string resourcePath = string `/v1/customer/${getEncodedUri(customer)}`; + http:Request request = new; + map requestBodyEncoding = {"address": {style: DEEPOBJECT, explode: true}}; + string encodedRequestBody = createFormURLEncodedRequestBody(payload, requestBodyEncoding); + request.setPayload(encodedRequestBody, "application/x-www-form-urlencoded"); + return self.clientEp->post(resourcePath, request); + } +} diff --git a/ballerina-test/bin/test/openapi/expected/filtered_tags.bal b/ballerina-test/bin/test/openapi/expected/filtered_tags.bal new file mode 100644 index 0000000000..f8bda7b4bb --- /dev/null +++ b/ballerina-test/bin/test/openapi/expected/filtered_tags.bal @@ -0,0 +1,16 @@ +// AUTO-GENERATED FILE. +// This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/http; + +listener http:Listener ep0 = new (80, config = {host: "petstore.openapi.io"}); + +service /v1 on ep0 { + # List all pets + # + # + 'limit - How many items to return at one time (max 100) + # + return - returns can be any of following types + # http:Ok (An paged array of pets) + # http:Response (unexpected error) + resource function get pets(int:Signed32? 'limit) returns Pets|http:Response { + } +} diff --git a/ballerina-test/bin/test/openapi/expected/types.bal b/ballerina-test/bin/test/openapi/expected/types.bal new file mode 100644 index 0000000000..c0f5bab44a --- /dev/null +++ b/ballerina-test/bin/test/openapi/expected/types.bal @@ -0,0 +1,89 @@ +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. +import ballerina/constraint; +import ballerina/http; + +public type Customer_customer_body record { + Customer_address address?; + # An integer amount in %s that represents the customer's current balance, which affect the customer's future invoices. A negative amount represents a credit that decreases the amount due on an invoice; a positive amount increases the amount due on an invoice. + int balance?; +}; + +public type Customer_address record { + @constraint:String {maxLength: 5000} + string city?; + @constraint:String {maxLength: 5000} + string country?; + @constraint:String {maxLength: 5000} + string line1?; + @constraint:String {maxLength: 5000} + string line2?; + @constraint:String {maxLength: 5000} + string postal_code?; + @constraint:String {maxLength: 5000} + string state?; +}; + +public type Customer record { + # The customer's address. + Customer_address? address?; + string name?; +}; + +# Provides settings related to HTTP/1.x protocol. +public type ClientHttp1Settings record {| + # Specifies whether to reuse a connection for multiple requests + http:KeepAlive keepAlive = http:KEEPALIVE_AUTO; + # The chunking behaviour of the request + http:Chunking chunking = http:CHUNKING_AUTO; + # Proxy server related options + ProxyConfig proxy?; +|}; + +# Proxy server configurations to be used with the HTTP client endpoint. +public type ProxyConfig record {| + # Host name of the proxy server + string host = ""; + # Proxy server port + int port = 0; + # Proxy server username + string userName = ""; + # Proxy server password + @display {label: "", kind: "password"} + string password = ""; +|}; + +# Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint. +@display {label: "Connection Config"} +public type ConnectionConfig record {| + # Configurations related to client authentication + http:CredentialsConfig auth; + # The HTTP version understood by the client + http:HttpVersion httpVersion = http:HTTP_2_0; + # Configurations related to HTTP/1.x protocol + ClientHttp1Settings http1Settings?; + # Configurations related to HTTP/2 protocol + http:ClientHttp2Settings http2Settings?; + # The maximum time to wait (in seconds) for a response before closing the connection + decimal timeout = 60; + # The choice of setting `forwarded`/`x-forwarded` header + string forwarded = "disable"; + # Configurations associated with request pooling + http:PoolConfiguration poolConfig?; + # HTTP caching related configurations + http:CacheConfig cache?; + # Specifies the way of handling compression (`accept-encoding`) header + http:Compression compression = http:COMPRESSION_AUTO; + # Configurations associated with the behaviour of the Circuit Breaker + http:CircuitBreakerConfig circuitBreaker?; + # Configurations associated with retrying + http:RetryConfig retryConfig?; + # Configurations associated with inbound response size limits + http:ResponseLimitConfigs responseLimits?; + # SSL/TLS-related options + http:ClientSecureSocket secureSocket?; + # Proxy server related options + http:ProxyConfig proxy?; + # Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default + boolean validation = true; +|}; From f846c877b011de88e1df249c03dee1c5e781b4cb Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 4 Apr 2024 14:26:50 +0530 Subject: [PATCH 2/8] Add BBE for jsonpath expressions --- examples/index.json | 14 +++++++ .../jsonpath_expressions.bal | 38 +++++++++++++++++++ .../jsonpath_expressions.md | 11 ++++++ .../jsonpath_expressions.metatags | 2 + .../jsonpath_expressions.out | 4 ++ 5 files changed, 69 insertions(+) create mode 100644 examples/jsonpath-expressions/jsonpath_expressions.bal create mode 100644 examples/jsonpath-expressions/jsonpath_expressions.md create mode 100644 examples/jsonpath-expressions/jsonpath_expressions.metatags create mode 100644 examples/jsonpath-expressions/jsonpath_expressions.out diff --git a/examples/index.json b/examples/index.json index 21136a2842..848c9944ff 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4522,6 +4522,20 @@ } ] }, + { + "title": "Json data library", + "column": 3, + "category": "Common libraries", + "samples": [ + { + "name": "Jsonpath expressions", + "url": "jsonpath-expressions", + "verifyBuild": true, + "verifyOutput": true, + "isLearnByExample": true + } + ] + }, { "title": "Constraint", "column": 3, diff --git a/examples/jsonpath-expressions/jsonpath_expressions.bal b/examples/jsonpath-expressions/jsonpath_expressions.bal new file mode 100644 index 0000000000..3694044d75 --- /dev/null +++ b/examples/jsonpath-expressions/jsonpath_expressions.bal @@ -0,0 +1,38 @@ +import ballerina/data.jsondata; +import ballerina/io; + +json books = [ + { + title: "The Great Gatsby", + author: "F. Scott Fitzgerald", + price: 100, + year: 1925 + }, + { + title: "To Kill a Mockingbird", + author: "Harper Lee", + price: 72.5, + year: 1960 + }, + { + title: "1984", + author: "George Orwell", + price: 90, + year: 1949 + } +]; + +public function main() returns error? { + // JSON path expression to get the list of titles in the books array. + json titles = check jsondata:read(books, `$..title`); + io:println(titles); + + // JSON path expression to get the list of publised years for the + // books that have price value more than 80. + json years = check jsondata:read(books, `$..[?(@.price > 80)].year`); + io:println(years); + + // JSON path expression to get the total summation of the books. + json totalSum = check jsondata:read(books, `$..price.sum()`); + io:println(totalSum); +} diff --git a/examples/jsonpath-expressions/jsonpath_expressions.md b/examples/jsonpath-expressions/jsonpath_expressions.md new file mode 100644 index 0000000000..691bbd4bd3 --- /dev/null +++ b/examples/jsonpath-expressions/jsonpath_expressions.md @@ -0,0 +1,11 @@ +# JsonPath expressions + +JSON Path expressions provide a straightforward method for navigating the structure of JSON data + +::: code jsonpath_expressions.bal ::: + +::: out jsonpath_expressions.out ::: + +## Related links +- [Json type](/learn/by-example/json-type/) +- [Access Json elements](/learn/by-example/access-json-elements/) \ No newline at end of file diff --git a/examples/jsonpath-expressions/jsonpath_expressions.metatags b/examples/jsonpath-expressions/jsonpath_expressions.metatags new file mode 100644 index 0000000000..447c461e86 --- /dev/null +++ b/examples/jsonpath-expressions/jsonpath_expressions.metatags @@ -0,0 +1,2 @@ +description: This BBE demonstrates JSON path expressions with Ballerina +keywords: ballerina, ballerina by example, bbe, json, jsonpath, jsonpath expressions \ No newline at end of file diff --git a/examples/jsonpath-expressions/jsonpath_expressions.out b/examples/jsonpath-expressions/jsonpath_expressions.out new file mode 100644 index 0000000000..af204eff18 --- /dev/null +++ b/examples/jsonpath-expressions/jsonpath_expressions.out @@ -0,0 +1,4 @@ +$ bal run jsonpath_expressions.bal +["The Great Gatsby","To Kill a Mockingbird","1984"] +[1925,1949] +262.5 \ No newline at end of file From 06c84eb215929898674f9fc4e39d437728a24f7c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 4 Apr 2024 14:47:12 +0530 Subject: [PATCH 3/8] Fix formatting in jsonpath expressions bbe --- examples/jsonpath-expressions/jsonpath_expressions.metatags | 2 +- examples/jsonpath-expressions/jsonpath_expressions.out | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/jsonpath-expressions/jsonpath_expressions.metatags b/examples/jsonpath-expressions/jsonpath_expressions.metatags index 447c461e86..3d1c024406 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.metatags +++ b/examples/jsonpath-expressions/jsonpath_expressions.metatags @@ -1,2 +1,2 @@ description: This BBE demonstrates JSON path expressions with Ballerina -keywords: ballerina, ballerina by example, bbe, json, jsonpath, jsonpath expressions \ No newline at end of file +keywords: ballerina, ballerina by example, bbe, json, jsonpath, jsonpath expressions diff --git a/examples/jsonpath-expressions/jsonpath_expressions.out b/examples/jsonpath-expressions/jsonpath_expressions.out index af204eff18..0768e3f99c 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.out +++ b/examples/jsonpath-expressions/jsonpath_expressions.out @@ -1,4 +1,4 @@ $ bal run jsonpath_expressions.bal ["The Great Gatsby","To Kill a Mockingbird","1984"] [1925,1949] -262.5 \ No newline at end of file +262.5 From fe9c2b8af025eab10ba927898021bf8e178e2eb3 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 8 Apr 2024 09:35:05 +0530 Subject: [PATCH 4/8] Update doc & comments in JSONPath expression bbe --- examples/index.json | 4 ++-- examples/jsonpath-expressions/jsonpath_expressions.bal | 8 ++++---- examples/jsonpath-expressions/jsonpath_expressions.md | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/index.json b/examples/index.json index 848c9944ff..35290a59f8 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4523,12 +4523,12 @@ ] }, { - "title": "Json data library", + "title": "JSON data library", "column": 3, "category": "Common libraries", "samples": [ { - "name": "Jsonpath expressions", + "name": "JSONPath expressions", "url": "jsonpath-expressions", "verifyBuild": true, "verifyOutput": true, diff --git a/examples/jsonpath-expressions/jsonpath_expressions.bal b/examples/jsonpath-expressions/jsonpath_expressions.bal index 3694044d75..68f0ed0231 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.bal +++ b/examples/jsonpath-expressions/jsonpath_expressions.bal @@ -23,16 +23,16 @@ json books = [ ]; public function main() returns error? { - // JSON path expression to get the list of titles in the books array. + // JSONPath expression to get the list of titles in the books array. json titles = check jsondata:read(books, `$..title`); io:println(titles); - // JSON path expression to get the list of publised years for the - // books that have price value more than 80. + // JSONPath expression to get the list of published years for the + // books that have a price value of more than 80. json years = check jsondata:read(books, `$..[?(@.price > 80)].year`); io:println(years); - // JSON path expression to get the total summation of the books. + // JSONPath expression to get the total summation of the books. json totalSum = check jsondata:read(books, `$..price.sum()`); io:println(totalSum); } diff --git a/examples/jsonpath-expressions/jsonpath_expressions.md b/examples/jsonpath-expressions/jsonpath_expressions.md index 691bbd4bd3..3ddad2f8ab 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.md +++ b/examples/jsonpath-expressions/jsonpath_expressions.md @@ -1,11 +1,11 @@ -# JsonPath expressions +# JSONPath expressions -JSON Path expressions provide a straightforward method for navigating the structure of JSON data +JSONPath expressions provide a straightforward method for navigating the structure of JSON data. ::: code jsonpath_expressions.bal ::: ::: out jsonpath_expressions.out ::: ## Related links -- [Json type](/learn/by-example/json-type/) -- [Access Json elements](/learn/by-example/access-json-elements/) \ No newline at end of file +- [JSON type](/learn/by-example/json-type/) +- [Access JSON elements](/learn/by-example/access-json-elements/) \ No newline at end of file From b060b93fe91d93952d96b2f05117f60cae4393eb Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 9 Apr 2024 17:07:04 +0530 Subject: [PATCH 5/8] Update jsonpath bbe samples --- examples/index.json | 21 +++----- .../jsonpath_expressions.bal | 48 +++++++++---------- .../jsonpath_expressions.md | 5 +- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/examples/index.json b/examples/index.json index 35290a59f8..5efb7e47f8 100644 --- a/examples/index.json +++ b/examples/index.json @@ -1045,6 +1045,13 @@ "verifyBuild": true, "verifyOutput": true, "isLearnByExample": true + }, + { + "name": "JSONPath expressions", + "url": "jsonpath-expressions", + "verifyBuild": true, + "verifyOutput": true, + "isLearnByExample": true } ] }, @@ -4522,20 +4529,6 @@ } ] }, - { - "title": "JSON data library", - "column": 3, - "category": "Common libraries", - "samples": [ - { - "name": "JSONPath expressions", - "url": "jsonpath-expressions", - "verifyBuild": true, - "verifyOutput": true, - "isLearnByExample": true - } - ] - }, { "title": "Constraint", "column": 3, diff --git a/examples/jsonpath-expressions/jsonpath_expressions.bal b/examples/jsonpath-expressions/jsonpath_expressions.bal index 68f0ed0231..e795f51c95 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.bal +++ b/examples/jsonpath-expressions/jsonpath_expressions.bal @@ -1,28 +1,28 @@ import ballerina/data.jsondata; import ballerina/io; -json books = [ - { - title: "The Great Gatsby", - author: "F. Scott Fitzgerald", - price: 100, - year: 1925 - }, - { - title: "To Kill a Mockingbird", - author: "Harper Lee", - price: 72.5, - year: 1960 - }, - { - title: "1984", - author: "George Orwell", - price: 90, - year: 1949 - } -]; - public function main() returns error? { + json books = [ + { + title: "The Great Gatsby", + author: "F. Scott Fitzgerald", + price: 100, + year: 1925 + }, + { + title: "To Kill a Mockingbird", + author: "Harper Lee", + price: 72.5, + year: 1960 + }, + { + title: "1984", + author: "George Orwell", + price: 90, + year: 1949 + } + ]; + // JSONPath expression to get the list of titles in the books array. json titles = check jsondata:read(books, `$..title`); io:println(titles); @@ -32,7 +32,7 @@ public function main() returns error? { json years = check jsondata:read(books, `$..[?(@.price > 80)].year`); io:println(years); - // JSONPath expression to get the total summation of the books. - json totalSum = check jsondata:read(books, `$..price.sum()`); - io:println(totalSum); + // JSONPath expression to get the total sum of the prices of the books. + json sum = check jsondata:read(books, `$..price.sum()`); + io:println(sum); } diff --git a/examples/jsonpath-expressions/jsonpath_expressions.md b/examples/jsonpath-expressions/jsonpath_expressions.md index 3ddad2f8ab..a43a41fd6b 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.md +++ b/examples/jsonpath-expressions/jsonpath_expressions.md @@ -1,6 +1,9 @@ # JSONPath expressions -JSONPath expressions provide a straightforward method for navigating the structure of JSON data. +Ballerina supports JSONPath expressions against JSON data through +`ballerina/data.jsondata` module to provide a straightforward method +for navigating the structure of JSON data. +Alternatively, Ballerina supports type based access to JSON data by language itself ::: code jsonpath_expressions.bal ::: From 95d59ef6d0b05c39392129247376a8624561e7d8 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 11 Apr 2024 11:17:45 +0530 Subject: [PATCH 6/8] Update json path bbe md docs --- examples/jsonpath-expressions/jsonpath_expressions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsonpath-expressions/jsonpath_expressions.md b/examples/jsonpath-expressions/jsonpath_expressions.md index a43a41fd6b..ebc7e25d64 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.md +++ b/examples/jsonpath-expressions/jsonpath_expressions.md @@ -3,7 +3,7 @@ Ballerina supports JSONPath expressions against JSON data through `ballerina/data.jsondata` module to provide a straightforward method for navigating the structure of JSON data. -Alternatively, Ballerina supports type based access to JSON data by language itself +Alternatively, Ballerina supports type based access to JSON data by language itself. ::: code jsonpath_expressions.bal ::: From 9f5fd74f7dc1febab7e0e621352b164ff26388d0 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 11 Apr 2024 11:25:02 +0530 Subject: [PATCH 7/8] Update md description for json path bbe --- examples/jsonpath-expressions/jsonpath_expressions.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/jsonpath-expressions/jsonpath_expressions.md b/examples/jsonpath-expressions/jsonpath_expressions.md index ebc7e25d64..b901c86341 100644 --- a/examples/jsonpath-expressions/jsonpath_expressions.md +++ b/examples/jsonpath-expressions/jsonpath_expressions.md @@ -1,7 +1,6 @@ # JSONPath expressions -Ballerina supports JSONPath expressions against JSON data through -`ballerina/data.jsondata` module to provide a straightforward method +Ballerina supports JSONPath expressions against JSON data through [`ballerina/data.jsondata` module](https://lib.ballerina.io/ballerina/data.jsondata/latest/) module to provide a straightforward method for navigating the structure of JSON data. Alternatively, Ballerina supports type based access to JSON data by language itself. From 90786a84033ef2e6063af9c0dc1690b99d282483 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 11 Apr 2024 11:35:47 +0530 Subject: [PATCH 8/8] Remove test/openapi bin related file changes --- .../bin/test/openapi/expected/client.bal | 69 -------------- .../test/openapi/expected/filtered_tags.bal | 16 ---- .../bin/test/openapi/expected/types.bal | 89 ------------------- 3 files changed, 174 deletions(-) delete mode 100644 ballerina-test/bin/test/openapi/expected/client.bal delete mode 100644 ballerina-test/bin/test/openapi/expected/filtered_tags.bal delete mode 100644 ballerina-test/bin/test/openapi/expected/types.bal diff --git a/ballerina-test/bin/test/openapi/expected/client.bal b/ballerina-test/bin/test/openapi/expected/client.bal deleted file mode 100644 index ecd6433a87..0000000000 --- a/ballerina-test/bin/test/openapi/expected/client.bal +++ /dev/null @@ -1,69 +0,0 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. -import ballerina/http; - -# The Stripe REST API. Please see https://stripe.com/docs/api for more details. -public isolated client class Client { - final http:Client clientEp; - # Gets invoked to initialize the `connector`. - # - # + config - The configurations to be used when initializing the `connector` - # + serviceUrl - URL of the target service - # + return - An error if connector initialization failed - public isolated function init(ConnectionConfig config, string serviceUrl) returns error? { - http:ClientConfiguration httpClientConfig = {auth: config.auth, httpVersion: config.httpVersion, timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation}; - do { - if config.http1Settings is ClientHttp1Settings { - ClientHttp1Settings settings = check config.http1Settings.ensureType(ClientHttp1Settings); - httpClientConfig.http1Settings = {...settings}; - } - if config.http2Settings is http:ClientHttp2Settings { - httpClientConfig.http2Settings = check config.http2Settings.ensureType(http:ClientHttp2Settings); - } - if config.cache is http:CacheConfig { - httpClientConfig.cache = check config.cache.ensureType(http:CacheConfig); - } - if config.responseLimits is http:ResponseLimitConfigs { - httpClientConfig.responseLimits = check config.responseLimits.ensureType(http:ResponseLimitConfigs); - } - if config.secureSocket is http:ClientSecureSocket { - httpClientConfig.secureSocket = check config.secureSocket.ensureType(http:ClientSecureSocket); - } - if config.proxy is http:ProxyConfig { - httpClientConfig.proxy = check config.proxy.ensureType(http:ProxyConfig); - } - } - http:Client httpEp = check new (serviceUrl, httpClientConfig); - self.clientEp = httpEp; - return; - } - - # Retrieves a PaymentMethod object. - # - # + payment_method - Payment Method - # + paymentMethodName - Payment Method - # + xLimit - limit of the payment - # + return - Successful response. - remote isolated function getPaymentMethodsPaymentMethod(string payment_method, string paymentMethodName, string xLimit) returns json|error { - string resourcePath = string `/v1/payment_methods/${getEncodedUri(payment_method)}`; - map queryParam = {"payment method name": paymentMethodName}; - resourcePath = resourcePath + check getPathForQueryParam(queryParam); - map headerValues = {"X-LIMIT": xLimit}; - map httpHeaders = getMapForHeaders(headerValues); - return self.clientEp->get(resourcePath, httpHeaders); - } - - # Creates a new customer object. - # - # + customer - Customer ID - # + payload - Customer Details - # + return - Successful response. - remote isolated function postCustomers(string customer, Customer_customer_body payload) returns Customer|error { - string resourcePath = string `/v1/customer/${getEncodedUri(customer)}`; - http:Request request = new; - map requestBodyEncoding = {"address": {style: DEEPOBJECT, explode: true}}; - string encodedRequestBody = createFormURLEncodedRequestBody(payload, requestBodyEncoding); - request.setPayload(encodedRequestBody, "application/x-www-form-urlencoded"); - return self.clientEp->post(resourcePath, request); - } -} diff --git a/ballerina-test/bin/test/openapi/expected/filtered_tags.bal b/ballerina-test/bin/test/openapi/expected/filtered_tags.bal deleted file mode 100644 index f8bda7b4bb..0000000000 --- a/ballerina-test/bin/test/openapi/expected/filtered_tags.bal +++ /dev/null @@ -1,16 +0,0 @@ -// AUTO-GENERATED FILE. -// This file is auto-generated by the Ballerina OpenAPI tool. -import ballerina/http; - -listener http:Listener ep0 = new (80, config = {host: "petstore.openapi.io"}); - -service /v1 on ep0 { - # List all pets - # - # + 'limit - How many items to return at one time (max 100) - # + return - returns can be any of following types - # http:Ok (An paged array of pets) - # http:Response (unexpected error) - resource function get pets(int:Signed32? 'limit) returns Pets|http:Response { - } -} diff --git a/ballerina-test/bin/test/openapi/expected/types.bal b/ballerina-test/bin/test/openapi/expected/types.bal deleted file mode 100644 index c0f5bab44a..0000000000 --- a/ballerina-test/bin/test/openapi/expected/types.bal +++ /dev/null @@ -1,89 +0,0 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. -import ballerina/constraint; -import ballerina/http; - -public type Customer_customer_body record { - Customer_address address?; - # An integer amount in %s that represents the customer's current balance, which affect the customer's future invoices. A negative amount represents a credit that decreases the amount due on an invoice; a positive amount increases the amount due on an invoice. - int balance?; -}; - -public type Customer_address record { - @constraint:String {maxLength: 5000} - string city?; - @constraint:String {maxLength: 5000} - string country?; - @constraint:String {maxLength: 5000} - string line1?; - @constraint:String {maxLength: 5000} - string line2?; - @constraint:String {maxLength: 5000} - string postal_code?; - @constraint:String {maxLength: 5000} - string state?; -}; - -public type Customer record { - # The customer's address. - Customer_address? address?; - string name?; -}; - -# Provides settings related to HTTP/1.x protocol. -public type ClientHttp1Settings record {| - # Specifies whether to reuse a connection for multiple requests - http:KeepAlive keepAlive = http:KEEPALIVE_AUTO; - # The chunking behaviour of the request - http:Chunking chunking = http:CHUNKING_AUTO; - # Proxy server related options - ProxyConfig proxy?; -|}; - -# Proxy server configurations to be used with the HTTP client endpoint. -public type ProxyConfig record {| - # Host name of the proxy server - string host = ""; - # Proxy server port - int port = 0; - # Proxy server username - string userName = ""; - # Proxy server password - @display {label: "", kind: "password"} - string password = ""; -|}; - -# Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint. -@display {label: "Connection Config"} -public type ConnectionConfig record {| - # Configurations related to client authentication - http:CredentialsConfig auth; - # The HTTP version understood by the client - http:HttpVersion httpVersion = http:HTTP_2_0; - # Configurations related to HTTP/1.x protocol - ClientHttp1Settings http1Settings?; - # Configurations related to HTTP/2 protocol - http:ClientHttp2Settings http2Settings?; - # The maximum time to wait (in seconds) for a response before closing the connection - decimal timeout = 60; - # The choice of setting `forwarded`/`x-forwarded` header - string forwarded = "disable"; - # Configurations associated with request pooling - http:PoolConfiguration poolConfig?; - # HTTP caching related configurations - http:CacheConfig cache?; - # Specifies the way of handling compression (`accept-encoding`) header - http:Compression compression = http:COMPRESSION_AUTO; - # Configurations associated with the behaviour of the Circuit Breaker - http:CircuitBreakerConfig circuitBreaker?; - # Configurations associated with retrying - http:RetryConfig retryConfig?; - # Configurations associated with inbound response size limits - http:ResponseLimitConfigs responseLimits?; - # SSL/TLS-related options - http:ClientSecureSocket secureSocket?; - # Proxy server related options - http:ProxyConfig proxy?; - # Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default - boolean validation = true; -|};