-
Notifications
You must be signed in to change notification settings - Fork 126
fix(customer): Fix array parameters in GET /api/v1/customers
#3862
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
While testing the `GET /api/v1/customers` endpoint, I noticed that [the documentation](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/customers.yaml#L36-L58) mentions `account_type` and `billing_entity_codes` parameters as arrays, but document them without the trailing `[]` brackets. This was different from other endpoints such as [the subscription one](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/subscriptions.yaml#L54-L68). So I tested the endpoint with `?billing_entity_codes=hooli&billing_entity_codes=gan` and `?billing_entity_codes=hooli,gan` and it returned a 500 error. Using `?billing_entity_codes[]=hooli&billing_entity_codes[]=gan` did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. I fixed the sanitization on the `billing_entity_codes` parameter and then added a test to ensure it does not return a 500 error without the trailing `[]` brackets. When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test. Below are the outputs of the tests without the fixes: ``` 1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count ArgumentError: wrong number of arguments (given 0, expected 1+) 2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity Got 1 failure and 1 other error: 2.1) Failure/Error: expect(response).to have_http_status(:ok) expected the response to have status code :ok (200) but it was :not_found (404) # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>' # ... # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>' 2.2) Failure/Error: expect(json[:customers].count).to eq(1) NoMethodError: undefined method 'count' for nil # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>' # .... # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>' 51/51 |================================================ 100 ================================================>| Time: 00:00:02 Finished in 2.7 seconds (files took 2.47 seconds to load) 51 examples, 2 failures Failed examples: rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity ```
vincent-pochet
approved these changes
Jun 24, 2025
annvelents
approved these changes
Jun 24, 2025
diegocharles
pushed a commit
that referenced
this pull request
Jun 30, 2025
## Context While testing the `GET /api/v1/customers` endpoint, I noticed that [the documentation](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/customers.yaml#L36-L58) mentions `account_type` and `billing_entity_codes` parameters as arrays, but document them without the trailing `[]` brackets. This was different from other endpoints such as [the subscription one](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/subscriptions.yaml#L54-L68). So I tested the endpoint with `?billing_entity_codes=hooli&billing_entity_codes=gan` and `?billing_entity_codes=hooli,gan` and it returned a 500 error. Using `?billing_entity_codes[]=hooli&billing_entity_codes[]=gan` did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. The fix for the doc can be found here: getlago/lago-openapi#388. ## Description I fixed the sanitization on the `billing_entity_codes` parameter and then added a test to ensure it does not return a 500 error without the trailing `[]` brackets. When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test. Below are the outputs of the tests without the fixes: ``` 1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count ArgumentError: wrong number of arguments (given 0, expected 1+) 2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity Got 1 failure and 1 other error: 2.1) Failure/Error: expect(response).to have_http_status(:ok) expected the response to have status code :ok (200) but it was :not_found (404) # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>' # ... # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>' 2.2) Failure/Error: expect(json[:customers].count).to eq(1) NoMethodError: undefined method 'count' for nil # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>' # .... # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>' Finished in 2.7 seconds (files took 2.47 seconds to load) 51 examples, 2 failures Failed examples: rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity ```
diegocharles
pushed a commit
that referenced
this pull request
Jul 11, 2025
## Context While testing the `GET /api/v1/customers` endpoint, I noticed that [the documentation](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/customers.yaml#L36-L58) mentions `account_type` and `billing_entity_codes` parameters as arrays, but document them without the trailing `[]` brackets. This was different from other endpoints such as [the subscription one](https://github.com/getlago/lago-openapi/blob/11d325bf076e6381c00674ca3b03de3c4eca845c/src/resources/subscriptions.yaml#L54-L68). So I tested the endpoint with `?billing_entity_codes=hooli&billing_entity_codes=gan` and `?billing_entity_codes=hooli,gan` and it returned a 500 error. Using `?billing_entity_codes[]=hooli&billing_entity_codes[]=gan` did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. The fix for the doc can be found here: getlago/lago-openapi#388. ## Description I fixed the sanitization on the `billing_entity_codes` parameter and then added a test to ensure it does not return a 500 error without the trailing `[]` brackets. When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test. Below are the outputs of the tests without the fixes: ``` 1) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter Failure/Error: return not_found_error(resource: "billing_entity") if params[:billing_entity_codes].present? && billing_entities.count != params[:billing_entity_codes].count ArgumentError: wrong number of arguments (given 0, expected 1+) 2) Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity Got 1 failure and 1 other error: 2.1) Failure/Error: expect(response).to have_http_status(:ok) expected the response to have status code :ok (200) but it was :not_found (404) # ./spec/requests/api/v1/customers_controller_spec.rb:434:in 'block (5 levels) in <top (required)>' # ... # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>' 2.2) Failure/Error: expect(json[:customers].count).to eq(1) NoMethodError: undefined method 'count' for nil # ./spec/requests/api/v1/customers_controller_spec.rb:435:in 'block (5 levels) in <top (required)>' # .... # /usr/local/bundle/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>' Finished in 2.7 seconds (files took 2.47 seconds to load) 51 examples, 2 failures Failed examples: rspec ./spec/requests/api/v1/customers_controller_spec.rb:419 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with invalid billing entity codes ignores the parameter rspec ./spec/requests/api/v1/customers_controller_spec.rb:431 # Api::V1::CustomersController GET /api/v1/customers when filtering by billing_entity_code with two identical billing entity codes returns customers for the specified billing entity ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
While testing the
GET /api/v1/customers
endpoint, I noticed that the documentation mentionsaccount_type
andbilling_entity_codes
parameters as arrays, but document them without the trailing[]
brackets. This was different from other endpoints such as the subscription one.So I tested the endpoint with
?billing_entity_codes=hooli&billing_entity_codes=gan
and?billing_entity_codes=hooli,gan
and it returned a 500 error.Using
?billing_entity_codes[]=hooli&billing_entity_codes[]=gan
did work though. So it turned out to be a documentation issue, along with a missing sanitization on the parameter. The fix for the doc can be found here: getlago/lago-openapi#388.Description
I fixed the sanitization on the
billing_entity_codes
parameter and then added a test to ensure it does not return a 500 error without the trailing[]
brackets.When doing so, I noticed that passing multiple identical billing entity codes did return a 404 error instead of a 200 one. So I fixed this as well along with a test.
Below are the outputs of the tests without the fixes: