openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[Question][Typescript] Allow for direct import of api call functions

Open FrenchGithubUser opened this issue 1 month ago • 0 comments

I'm trying to find a way to directly import the generated api calls with minimal boilerplate.

Currently, that's the most minimal I found:

import { Configuration, Post, PostsApi } from "./generated-sources/openapi";
const configuration = new Configuration({
  basePath: window.location.origin,
});
const postsApi = new PostsApi(configuration);
const loadedPosts = await postsApi.getPosts();

Which is way too much boilerplate imo (since it needs to be done manually for each new api resource)

I found a way to import an existing axios instance (with the base url already there, as well as interceptors) but the api call functions (like getPosts()) isn't something we can import right away as it still needs some sort of initialization.

My goal:

import { getPosts } from "./generated-sources/openapi";
const loadedPosts = await postsApi.getPosts();

Is there a way to do that (maybe with a template)?

FrenchGithubUser avatar Dec 07 '25 11:12 FrenchGithubUser