Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
stubby4node comma separated query string implementation issue

I have a URL (GET REQUEST) of the following pattern

  • ^/testpath/1/test?pathid=1
  • ^/testpath/1/test?pathid=1,2
  • ^/testpath/1/test?pathid=1,2,5

where pathid query string parameters are comma separated

I have the following stubby mappings to match these url patterns

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-1.json

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1,2'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-2.json

- request:
    url: ^/testpath/(.*)/test
    query:
      pathid: '1,2,5'
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-3.json

but I can't get this URL mapping to properly deliver different payloads based on different parameter combinations.

  • 1 -> payload1
  • 1,2 -> payload2
  • 1,2,5 -> payload3

how can this be done?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

@Sanath, short answer - yes, stubby4j matches on different stubbed query parameters combinations.

Few questions:

  1. What version of stubby4j are you running?
  2. Also, are you running stubby4j as a standalone JAR or as one of the pre-built stubby4j Docker containers?

I wrote a test to validate the YAML configuration you provided in your question: https://github.com/azagniotov/stubby4j/pull/434/files (do note, I did change the url a little, but it is still a regex similar to your posted YAML).

The requests that test makes do match the stubs. (I did try without $ and with a $, like @code suggested). In addition, I also tested with cURL against a running standalone JAR:

curl -X GET  http://localhost:8882/stackoverflow/70417269/1/test?pathid=1,2,5

and

curl -X GET  http://localhost:8882/stackoverflow/70417269/1/test?pathid=1,2

Again, I got the expected responses from the server.

If the above does not help you, please feel free to raise a bug report https://github.com/azagniotov/stubby4j/issues/new/choose

about 4 years ago · Juan Pablo Isaza Relatório

0

The trick here is to change the order of request/response mappings in the yaml file.

- request:
    url: ^/testpath/(.*)/test
    query:
      **pathid: '1,2,5'**
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-3.json

- request:
    url: ^/testpath/(.*)/test
    query:
      **pathid: '1,2'**
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-2.json

- request:
    url: ^/testpath/(.*)/test
    query:
      **pathid: '1'**
    method: GET
  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/path-1.json

note the path ids added in the descending order, so that more deeper matches will be executed first.

This way I was able to achieve this following requirement, of passing different path ids separated by a comma

  • 1 -> payload1
  • 1,2 -> payload2
  • 1,2,5 -> payload3
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda