Skip to content
GitLab
    • Explore Projects Groups Snippets
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
Something went wrong while setting issue due date.
Closed
Open
Issue created 4 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

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

Closed

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).

  1. Oh no!

    You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico.

    Incoming!

    Drop your designs to start your upload.
Tasks
0
server returned results with length 1, expected length of 9

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
No estimate or time spent
Confidentiality
Not confidential
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
0
0 participants
Reference:

Menu

Explore Projects Groups Snippets