question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[NodeJS] [CSharp] - CSV / Arrays / Lists in URL's are not replaced correctly

See original GitHub issue

Hello everybody,

having a Java EE REST-Endpoint annotated like:

  @com.my-domain.ess.interceptor.binding.ServiceOperation("query")
  @javax.ws.rs.GET
  @javax.ws.rs.Path("{parentId}/query")         
  @javax.ws.rs.Produces({javax.ws.rs.core.MediaType.APPLICATION_XML, javax.ws.rs.core.MediaType.APPLICATION_JSON})
  @io.swagger.annotations.ApiOperation(value="Wer suchet, der findet", nickname="MischtabellenQuery",
      authorizations = {
      @io.swagger.annotations.Authorization(
          value="oauth", 
          scopes = { @io.swagger.annotations.AuthorizationScope(scope = "ess", description = "OAuth-Authentifizierung f. ESS") }
          )
    }
  )

  @io.swagger.annotations.ApiResponses(value = 
  {
    @io.swagger.annotations.ApiResponse(code = 200, message = "OK", response=com.gfi.eva.serviceschicht.zentral.SchluesseltabellenEintragQueryResponse.class), 
  })                                  
  public javax.ws.rs.core.Response query(@javax.ws.rs.PathParam("parentId") java.util.List<String> parentIds) throws Exception

I’m getting this swagger:

"/Services/Mischtabellen/{parentId}/query" : {
      "get" : {
        "tags" : [ "MischtabellenRessource" ],
        "summary" : "Wer suchet, der findet",
        "description" : "",
        "operationId" : "MischtabellenQuery",
        "produces" : [ "application/xml", "application/json" ],
        "parameters" : [ {
          "name" : "parentId",
          "in" : "path",
          "required" : true,
          "type" : "array",
          "items" : {
            "type" : "string"
          },
          "collectionFormat" : "csv"
        } ],
        "responses" : {
          "200" : {
            "description" : "OK",
            "schema" : {
              "$ref" : "#/definitions/SchluesseltabellenEintragQueryResponse"
            }
          }
        },
        "security" : [ {
          "oauth" : [ "ess" ]
        } ]
      }
    }

The relevant part of the generated client is this:

ESS.prototype.query = function (parentId, options, callback) {
  var client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  ...
  // Construct URL
  var requestUrl = this.baseUri +
                   '//Services/Mischtabellen/{parentId:commaSeparated}/query';
  requestUrl = requestUrl.replace('{parentId}', encodeURIComponent(parentId.toString()));

The parameter parentId is an array and got validated correctly. In the requestUrl the {parentId:commaSeparated} should be replaced by the array in parentId. But the call requestUrl.replace() tries to replace {parentId} instead of {parentId:commaSeparated}. Hence the replacement never happenes and the called URL is wrong.

Fixing the replacement to {parentId:commaSeparated} works as expected.

The problem occurs in the NodeJS and CSharp client in the same way.

Thanks! Alex

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aschuacommented, Apr 5, 2016

@amarzavery - I tried the nightly build and the problem is fixed. Thank you very much for the quick replies and the fix!

1reaction
amarzaverycommented, Apr 5, 2016

@aschua - You can try tonight’s nightly build 0.16.0-Nightly20160404 from this feed or generate after building from the master branch of this repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Easy way to turn JavaScript array into comma-separated list?
This is the perfect answer. To get CSV of an array we can just use console.log(arr) or like you said, casting it as...
Read more >
Data Loading in D3.js - TutorialsTeacher
d3.csv(), Sends http request to the specified url to load .csv file or data and executes ... JSON data can be a single...
Read more >
csvtojson - npm
A tool concentrating on converting csv data to JSON with customised parser supporting. Latest version: 2.0.10, last published: 3 years ago.
Read more >
A complete guide to CSV files in Node.js - LogRocket Blog
While there isn't a universal standard, this guide covers the differences and helpful packages for working with CSVs in Node.js.
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found