Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9179
Closed
Open
Issue created Apr 05, 2021 by Administrator@rootContributor

Struggling to find good documentation describing how to use javascript ApiClient with a basePath override

Created by: davesargrad

I generate my client code in this fashion: openapi-generator-cli generate -i ../api/api_v1.json -g javascript -o .

I've successfully been able to exercise my API on a dev server. However the ApiClient uses a hard-coded basePath

class ApiClient {
    constructor() {
        /**
         * The base URL against which to resolve every API call's (relative) path.
         * @type {String}
         * @default http://192.168.56.101:8080
         */
        this.basePath = 'http://192.168.56.101:8080'.replace(/\/+$/, '');

I currently invoke my API as follows:

let apiInstance = new VideoDescriptorApi();
export function requestPostVideoDescriptor(videoDescriptor) {
	let p = new Promise((resolve, reject) => {
		apiInstance.addVideoDescriptor(

where addVideoDescriptor is inside the generated code. It in turn uses ApiClient. That method, invokes the ApiClient as follows:

    return this.apiClient.callApi(
        '/video_descriptor', 'POST',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType, null, callback
      );

Its not clear to me how to override the ApiClient hardcoded basePath (http://192.168.56.101:8080). Ultimately my service will run in kubernetes and I dont know the URL apriori.

How can I change the basepath, without having to regenerate client code?

How would I modify the following code to use an alternative base URL (e.g. replace the hard-coded http://192.168.56.101:8080 with https://example.com:3000)?

import {ApiClient, VideoDescriptorApi} from "api/learning_center/v2";
let defaultClient = ApiClient.instance;
// Configure API key authorization: api_key
let api_key = defaultClient.authentications["api_key"];
api_key.apiKey = "YOUR API KEY";
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key.apiKeyPrefix = 'Token';
let apiInstance = new VideoDescriptorApi();
export function requestPostVideoDescriptor(videoDescriptor) {
	let p = new Promise((resolve, reject) => {
		apiInstance.addVideoDescriptor(
			videoDescriptor,
			(error, data, response) => {
				if (error) {
					console.error("requestPostVideoDescriptor error", error);
					reject(error);
				} else {
					resolve({ data: data, response: response });
				}
			}
		);
	});
	return p;
}

I've searched for a while online. I certainly have found related issues (where other developers were looking for the same answer), but no clear example.

I doubt that this is a code bug (please forgive my posting it as a bug- git really did not provide an alternative, since I dont view it as a feature request either). However I definitely view it as a "documentation bug", or at least a documentation shortcoming.

I am sure that there must be an easy way to do this in my client code.

Please help me with a tweak to the code snippet above, that illustrates how I'd configure the ApiClient and the VideoDescriptorApi to use an alternative basePath (https://example.com:3000).

Assignee
Assign to
Time tracking