api-to-bruno
API to Bruno
Turn an API source into a classic Bruno .bru collection. The leading word is inventory: build a route inventory first, then generate files from that inventory.
Inputs
Require one API source: a Git URL, an OpenAPI/WSDL URL, or a local path relative to the current working directory. If no source is provided, ask for it.
If the user gives an output path, use it. Otherwise use <api-root>/bruno/<collection-slug> for a local source and <cwd>/bruno/<collection-slug> for a remote source. If that directory already exists and is non-empty, ask before overwriting or merging.
Process
-
Resolve the source. For a local path, resolve it against the current working directory and verify it exists. For a Git URL, clone a shallow copy into the session temp area and keep generated output outside the clone unless the user asked otherwise. For a direct spec URL, keep it as the source. Completion: exactly one source and one safe output directory are known.
-
Search for a contract before reading application code. Look for OpenAPI or Swagger files (
openapi.*,swagger.*,api-docs.*) and WSDL files in docs, spec, api, public, resources, generated, and root folders. Confirm candidates by reading them foropenapi,swagger, or WSDL markers. If several plausible contracts conflict, ask which to use. Completion: choosecontractmode with one contract, orsource-inventorymode because no contract was found. -
In
contractmode, readBRUNO.md, then import with Bruno CLI using classic--collection-format=bru. Prefer an already installedbrubinary. Ifbruis missing, do not runnpx, install packages, or execute Docker automatically; ask for explicit approval with the exact pinned command, risk note, working directory, and reason it is needed, or generate.brufiles manually if approval is denied. Completion: the output containsbruno.jsonand every contract operation is represented by a request file, or any importer gap is listed explicitly. -
In
source-inventorymode, inventory every route-defining file before generating. Search framework route cues: Express/Koa/Fastify routers, NestJS decorators, FastAPI/Flask decorators, Django URL patterns and DRF routers, Spring mappings, ASP.NET route attributes and minimal APIs, Laravel routes, Railsroutes.rb, Go Gin/Echo/chi/http handlers, and GraphQL schemas or resolvers. Completion: the inventory includes every discovered method, path, source file, handler name, path params, query params, body shape, auth hint, and tags/folder grouping; unknown fields are markedunknown, not omitted.