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

Question: Return all operations #47

Open
jonasgroendahl opened this issue Sep 29, 2022 · 1 comment
Open

Question: Return all operations #47

jonasgroendahl opened this issue Sep 29, 2022 · 1 comment

Comments

@jonasgroendahl
Copy link

jonasgroendahl commented Sep 29, 2022

Hi!

I'm trying to create some code that will generate all the available operations based on the paths automatically, so you don't need to create another fetch.path("route").method("method").create() every time you add another path in your api spec.

Anyone who had any luck with this?

I tried something like the below and couldn't really think it to the end

import { ApiPaths, paths } from "./schema"

const fetch = Fetcher.for<paths>();

const createAll = () => {
  const allPaths = Object.keys(ApiPaths);

  const all = {};

  for (const route of allPaths) {
    all[route] = fetch.path(route).method("get").create();
  }

  return all;
};

@duncanbeevers
Copy link

I ended up creating a tool that parses the generated types with the typescript compiler itself and walks the AST to generate all the APIs fetchers.

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