Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include/exclude endpoints? #836

Open
n1kk opened this issue Jul 18, 2024 · 1 comment
Open

How to include/exclude endpoints? #836

n1kk opened this issue Jul 18, 2024 · 1 comment

Comments

@n1kk
Copy link

n1kk commented Jul 18, 2024

Hi, I'm consuming a gigantic API, with hundreds of endpoints, but I only really need one or two. Even generating modular output and splitting endpoint into files by first tag generates quite huge classes.

Is there a way to filter what endpoints end up being generated into the http client class?

@grushikhin
Copy link

Hi!
I had a similar issue, and I resolved it by using '@apidevtools/swagger-parser'.
I split the OpenAPI file into smaller pieces before passing them to the generator.

code example:

export async function splitOpenAPIFile(inputFilePath: string, outputDir: string): Promise<void> {
    const api = await SwaggerParser.parse(inputFilePath) as OpenAPIV3.Document;

    const resources: { [key: string]: OpenAPIV3.Document } = {};

    for (const [path, methods] of Object.entries(api.paths)) {
        const resourceName = path.split('/')[1];

        if (!resources[resourceName]) {
            resources[resourceName] = {
                ...api,
                paths: {}
            };
        }

        resources[resourceName].paths[path] = methods;
    }

    await ensureDir(outputDir);

    for (const [resourceName, resourceApi] of Object.entries(resources)) {
        const resourceFilePath = path.join(outputDir, `${resourceName}.json`);
        await writeJson(resourceFilePath, resourceApi, { spaces: 2 });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants