Importing an older Swagger 2.0 spec

Swagger 2.0 is ten years old and still everywhere: older Spring Boot services, API gateways, vendor docs. Requestarium imports it the same way as OpenAPI 3, from the app, the IDEs or the CLI. A few Swagger-specific fields map differently, and knowing how saves a round of fixing.

Import it

In the app: Import and pick the swagger.json or .yaml file, or paste its URL. From a terminal:

Terminal
requestarium import https://petstore.swagger.io/v2/swagger.json --environments

Operations become requests in a folder per tag, named after their summary, as described in OpenAPI to a working collection.

Base URL and environments

Swagger 2.0 has no servers list. Instead:

YAML
schemes: [https, http]
host: api.example.com
basePath: /v2

That gives {{baseUrl}} = https://api.example.com/v2, and with --environments, one environment per scheme: HTTPS and HTTP. With a single scheme, the environment is named after the host.

Specs without host (common in generated ones, meaning "same host as the docs") get only basePath as the base URL. Add the host to baseUrl in your environments: http://localhost:8080/v2 for Local, the staging host for Staging. See environments for local, staging and production.

Auth

securityDefinitions map the same way as OpenAPI 3's security schemes:

  • type: basic → basic auth with {{username}} and {{password}},
  • type: apiKey → {{apiKey}} in the named header or query parameter,
  • type: oauth2 with password, application or accessCode flows → OAuth 2.0 with the token URL and scopes; implicit only → a bearer token, with a note.

Fill in the empty secret variables the import creates, and the requests are ready.

Bodies and form data

  • in: body parameters become the JSON body, from the parameter's example, its schema's example, or a placeholder shaped like the schema.
  • in: formData parameters become a form body; with consumes: multipart/form-data, a multipart one. For file fields, pick a file in the app before sending; the CLI doesn't send file uploads.

Response examples

Swagger 2.0 keeps response examples per media type under examples. They're imported as saved examples on each request: 2xx responses always, other statuses when the spec gives an example.

Convert to OpenAPI 3 first?

You don't need to for importing. Consider it when you also want to:

  • keep the collection linked to the spec while the spec evolves (works with both, but OpenAPI 3 lets you list several named servers),
  • describe several environments properly (servers with descriptions become named environments),
  • use oneOf/anyOf bodies, which Swagger 2.0 can't express.

And back again

If another tool needs Swagger 2.0, export it: requestarium export "Petstore" --format swagger2 --out swagger.json. See turn an API collection into an OpenAPI spec.