apidash icon indicating copy to clipboard operation
apidash copied to clipboard

support for params having multiple values

Open badnikhil opened this issue 9 months ago • 13 comments

PR Description

The request parameters were previously handled as a Map<String, String>. I have updated this to Map<String, List<string> to support multiple values

Additionally, I have modified the relevant implementations to accommodate this change.

Related Issues

  • Closes #268

Checklist

  • [x] I have reviewed the contributing guide.
  • [x] My branch is up to date and synced with the project's main branch before creating this PR.
  • [x] I am using the latest stable Flutter version (flutter upgrade verified).
  • [x] I have run all tests (flutter test), and they pass successfully.

Added/Updated Tests?

We encourage contributors to add relevant test cases.

  • [x] Yes
  • [ ] No

Development & Testing Environment

  • [ ] Windows
  • [ ] Android
  • [x] Linux

badnikhil avatar Mar 20 '25 03:03 badnikhil

@ashitaprasad I am familiar with the codebase; however, I need to explore the test files further before making the necessary updates. I plan to work on that after updating codegen for all languages. In the meantime, please review the implementation and share your feedback.

badnikhil avatar Mar 20 '25 03:03 badnikhil

@animator I request you to take a look(Feedback on the major changes is enough) . I've updated the code generation for all supported languages to handle parameters with multiple values. Before I move on to writing/updating tests, I just want to ensure that all changes are aligned with expectations .

badnikhil avatar Apr 04 '25 23:04 badnikhil

@badnikhil do not conversations as resolved. You have to comment if you have fixed it, then the reviewer verifies the fix and marks it is resolved.

animator avatar Apr 06 '25 22:04 animator

@badnikhil do not conversations as resolved. You have to comment if you have fixed it, then the reviewer verifies the fix and marks it is resolved.

Sorry about that, I’ll keep it in mind from now on.

badnikhil avatar Apr 06 '25 23:04 badnikhil

@animator i have resolved the datatypes.. Also updated a widget test. rows are now List instead of map you can Ignore the codegen related warnings for now.. it will be updated after finalising the changes.

badnikhil avatar Apr 10 '25 22:04 badnikhil

+796 ~1 -431: Some tests failed.

431 tests failed

ashitaprasad avatar May 09 '25 18:05 ashitaprasad

+796 ~1 -431: Some tests failed.

431 tests failed

Tests for Codegen are not updated yet(as mentioned earlier )..

01:13 +383 ~1 -1: Some tests failed. (this does not include codegen folder) All other are passing except #646 and

00:13 +174 ~1 -1: /home/badnikhil/Desktop/apidash/test/models/http_request_model_test.dart: Testing getters [E]                                                                                
  Expected: {'size': '2', 'len': '3'}
    Actual: {'size': ['2'], 'len': ['3']}
     Which: at location ['size'] is ['2'] instead of '2'
  
  package:matcher                                expect
  test/models/http_request_model_test.dart 36:5  main.<fn>
  

Updated it to List,adding commit .

badnikhil avatar May 10 '25 10:05 badnikhil

The approach has been reviewed. Please fix all the codegen tests so that the PR can be merged.

animator avatar May 10 '25 14:05 animator

The approach has been reviewed. Please fix all the codegen tests so that the PR can be merged.

Updating as soon as possible

badnikhil avatar May 10 '25 14:05 badnikhil

Also, why major code changes have been made to codegens?

animator avatar May 10 '25 14:05 animator

Also, why major code changes have been made to codegens?

image

URL inside the swift code ->"https://postman-echo.com/get?param2=value4&param1=v2"

Explanation -> The params are added to the URL using var rec = getValidRequestUri(requestModel.url, requestModel.enabledParams); -> uri_utils in apidash_core Here the value of key(param) is replaced inside the function .. and then query params are added to the uri..

So, an issue when we have multiple values for same key... codegen needs to be updated for the enhancement intended in this PR this was one thing.. Second is that in some codegen logics the params are directly added to the URL.. everything works well and get a short code but its hard to find param/values in the URL.. instead the params are handled seperately outside the URL for a convenience in editing the code manually..


var urlComponents = URLComponents(string: "https://postman-echo.com/get")!
var queryItems = [URLQueryItem]()


queryItems.append(URLQueryItem(name: "param1", value: "value1"))
queryItems.append(URLQueryItem(name: "param1", value: "value2"))
queryItems.append(URLQueryItem(name: "param2", value: "value3"))
queryItems.append(URLQueryItem(name: "param2", value: "value4"))

urlComponents.queryItems = queryItems
let requestUrl = urlComponents.url!
var request = URLRequest(url: requestUrl)
request.httpMethod = "GET"
request.addValue("asda", forHTTPHeaderField: "asd")


let semaphore = DispatchSemaphore(value: 0) 

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
    defer { semaphore.signal() }  

    if let error = error {
        print("Error: \(error.localizedDescription)")
        return
    }
    guard let data = data else {
        print("No data received")
        return
    }
    if let responseString = String(data: data, encoding: .utf8) {
        print("Response: \(responseString)")
    }
}

task.resume()

semaphore.wait()

Here the changes can be made more easily

If you want params directly added to URL instead of handling seperately inside code Then the changes can be significantly reduced..

badnikhil avatar May 11 '25 20:05 badnikhil

Thanks for the explanation. As mentioned earlier please update the tests for all the codegens.

animator avatar May 15 '25 18:05 animator

@animator! Would appreciate a quick review whenever you're free —to move on to the next issue.

badnikhil avatar Aug 01 '25 10:08 badnikhil