Skip to content

JS client has hard-coded service URL #2026

Closed
@delenius

Description

@delenius

My swagger spec has something like

basePath: "/foo/bar"

Based on this, the JS client generator produces this code in ApiClient.js

this.basePath = 'http://localhost/foo/bar'.replace(/\/+$/, '');

It would be much nicer if the service URL was not hard-coded into the generated client code, especially since it happens to be wrong in this case: My service also needs a port number. I don't think the server URL is normally part of the swagger spec. And for good reason: During the lifecycle of a service, it may run in different places (for development/testing/production, etc).

Note that swagger-js allows you to pass the URL as a parameter:

var Swagger = require('swagger-client');

var client = new Swagger({
  url: 'http://petstore.swagger.io/v2/swagger.json',
  success: function() {
    client.pet.getPetById({petId:7},{responseContentType: 'application/json'},function(pet){
      console.log('pet', pet);
    });
  }
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions