Tutorial: OpenAPI / Swagger Importer
Instead of writing test definitions by hand, RouteCase can convert any OpenAPI 3.x or Swagger 2.x specification into an executable .rcase suite in seconds.
How It Works
Section titled “How It Works”RouteCase includes a zero-dependency specification parser (src/importer/openApiImporter.ts) that extracts:
- Title & Base URL: Derived from
info.titleandservers[0].url(orhost+basePathin Swagger 2.0). - Endpoints: Each path + HTTP method combination becomes an
EndpointDefinition. - Parameters:
- Path parameters (
in: path) populateparamswith example values or types. - Query parameters (
in: query) populatequery.
- Path parameters (
- Request Bodies: Extracted from
requestBody.content['application/json'].schema.exampleor sample objects. - Starter Assertions: Generates a
successcase asserting status200(or201) and anerrorscase asserting400or422.
Step-by-Step Instructions
Section titled “Step-by-Step Instructions”- Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P). - Run:
RouteCase: Import OpenAPI / Swagger
- Choose an input method:
- Local File: Pick a
swagger.jsonoropenapi.jsonfile on your disk. - Remote URL: Enter a live specification URL (e.g.
http://localhost:3000/api-jsonorhttps://petstore.swagger.io/v2/swagger.json).
- Local File: Pick a
- RouteCase generates
api.rcasein your workspace root and opens it immediately. - Click
▶ Run All Casesto begin testing your routes right away!
::: tip Converting YAML Specs
RouteCase currently parses JSON specifications natively. If your specification is in YAML (openapi.yaml), convert it to JSON using an online tool like json2yaml.com or via CLI (npx yamljs input.yaml > openapi.json) before importing.
:::
