OpenAPITools / OpenAPITools/openapi-generator
[Question][Typescript] Allow for direct import of api call functions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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)?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the generated-sources/openapi TypeScript client structure, especially Configuration and PostsApi, and then inspect the available generator templates. Determine whether a template can expose functions such as getPosts while preserving the existing Axios configuration; done means a supported approach or a clearly scoped template change is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100