{"id":27863344,"url":"https://github.com/denosaurs/typefetch","last_synced_at":"2025-06-21T12:35:46.114Z","repository":{"id":222335706,"uuid":"756275279","full_name":"denosaurs/typefetch","owner":"denosaurs","description":"📤 Magically generate `fetch` types from OpenAPI schemas for zero-cost browser-native api clients","archived":false,"fork":false,"pushed_at":"2025-04-17T20:09:09.000Z","size":140,"stargazers_count":17,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-15T12:26:06.850Z","etag":null,"topics":["fetch","openapi","swagger","typescript"],"latest_commit_sha":null,"homepage":"https://jsr.io/@denosaurs/typefetch","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denosaurs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"denosaurs","github":"denosaurs"}},"created_at":"2024-02-12T10:43:54.000Z","updated_at":"2025-06-03T07:54:46.000Z","dependencies_parsed_at":"2024-03-19T07:22:20.315Z","dependency_job_id":"47d8b2db-6450-4783-933d-3655f1f4e65c","html_url":"https://github.com/denosaurs/typefetch","commit_stats":null,"previous_names":["denosaurs/typefetch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/denosaurs/typefetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Ftypefetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Ftypefetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Ftypefetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Ftypefetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denosaurs","download_url":"https://codeload.github.com/denosaurs/typefetch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Ftypefetch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260840766,"owners_count":23071004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fetch","openapi","swagger","typescript"],"created_at":"2025-05-04T20:49:54.582Z","updated_at":"2025-06-21T12:35:41.102Z","avatar_url":"https://github.com/denosaurs.png","language":"TypeScript","funding_links":["https://opencollective.com/denosaurs","https://github.com/sponsors/denosaurs"],"categories":[],"sub_categories":[],"readme":"# TypeFetch\n\nI dream of proper meta-programming in the wild west of ECMAScript. A parallel\nuniverse where ECMAScript had types, macros, and a proper module system. Where\nmodules work regardless of environment and runtime. Where interfacing with the\nsystem is standardized, and code from server runtimes work in the browser. But\nalas, we are stuck in this bad joke of a universe where TypeScript is the next\nbest thing. So, I present to you, TypeFetch, a tool for generating zero-cost\ntype-safe `fetch` clients from OpenAPI schemas. It works everywhere you can call\n`fetch`, and anywhere you can use TypeScript.\n\n## Usage\n\nTo use TypeFetch, you need to have an OpenAPI schema. You can either provide a\nlocal file path or a URL to the schema (which can be either json or yaml), then\nall you need to do is run the cli using deno, node, or any other JavaScript\nruntime supported by the [jsr](https://jsr.io) registry.\n\n```sh\ndeno run -A jsr:@denosaurs/typefetch\n```\n\n```\nUsage: typefetch [OPTIONS] \u003cPATH\u003e\n\nOptions:\n  -h, --help                           Print this help message\n  -V, --version                        Print the version of TypeFetch\n  -o, --output    \u003cPATH\u003e               Output file path                                                   (default: typefetch.d.ts)\n      --config    \u003cPATH\u003e               File path to the tsconfig.json file\n      --import    \u003cPATH\u003e               Import path for TypeFetch                                          (default: https://raw.githubusercontent.com/denosaurs/typefetch/main)\n      --base-urls \u003cURLS\u003e               A comma separated list of custom base urls for paths to start with\n      --include-server-urls            Include server URLs from the schema in the generated paths         (default: true)\n      --include-absolute-url           Include absolute URLs in the generated paths                       (default: false)\n      --include-relative-url           Include relative URLs in the generated paths                       (default: false)\n      --experimental-urlsearchparams   Enable the experimental fully typed URLSearchParams type           (default: false)\n```\n\n## Example\n\n```sh\ndeno run -A jsr:@denosaurs/typefetch https://api.jsr.io/.well-known/openapi\n```\n\nThis will generate a `typefetch.d.ts` file in the current directory, which will\nmodify the global scope and the type definitions for the `fetch` function and\nall types defined within the schema. For example:\n\n```ts\ndeclare global {\n  ...\n  /**\n   * Returns a list of packages\n   * @summary List packages\n   */\n  function fetch(\n    input: `https://api.jsr.io/packages` | `/packages`,\n    init?: Omit\u003cRequestInit, \"method\" | \"body\" | \"headers\"\u003e \u0026 {\n      method: \"GET\";\n    },\n  ): Promise\u003c\n    \u0026 Omit\u003c\n      Response,\n      \"ok\" | \"status\" | \"arrayBuffer\" | \"blob\" | \"formData\" | \"json\" | \"text\"\n    \u003e\n    \u0026 (\n      | ({\n        ok: true;\n        status: 200;\n        json(): Promise\u003c{ items: Package[]; total: number }\u003e;\n        text(): Promise\u003cJSONString\u003c{ items: Package[]; total: number }\u003e\u003e;\n      })\n      | ({\n        ok: false;\n        status: 400;\n        json(): Promise\u003cError\u003e;\n        text(): Promise\u003cJSONString\u003cError\u003e\u003e;\n      })\n    )\n  \u003e;\n  ...\n}\n```\n\nWhich now allows you to use the `fetch` function with the\n`https://api.jsr.io/packages` endpoint as following:\n\n```ts\nconst response = await fetch(\"https://api.jsr.io/packages\");\n\n// The ok and status properties work as discriminators here to narrow the\n// types of the response. That way the json and text methods are made\n// type-safe.\nif (response.ok) {\n  console.assert(response.status === 200);\n\n  const { items, total } = await response.json();\n  // even this works because we augment the global JSON object!\n  const { items, total } = JSON.parse(await response.text());\n} else {\n  console.assert(response.status === 400);\n\n  const error = await response.json();\n  // or\n  const error = JSON.parse(await response.text());\n}\n```\n\n## Maintainers\n\n- Elias Sjögreen ([@eliassjogreen](https://github.com/eliassjogreen))\n\n## Contributing\n\nPull request, issues and feedback are very welcome. Code style is formatted with\n`deno fmt` and commit messages are done following Conventional Commits spec.\n\nPlease use it! And let us know if you have any issues, feedback or requests.\n\n## Licence\n\nCopyright 2024, the Denosaurs team. All rights reserved. MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenosaurs%2Ftypefetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenosaurs%2Ftypefetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenosaurs%2Ftypefetch/lists"}