Skip to content

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

@FrenchGithubUser

Description

@FrenchGithubUser

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions