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:
requestarium import https://petstore.swagger.io/v2/swagger.json --environmentsOperations 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:
schemes: [https, http]
host: api.example.com
basePath: /v2That 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: oauth2withpassword,applicationoraccessCodeflows → OAuth 2.0 with the token URL and scopes;implicitonly → 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: bodyparameters become the JSON body, from the parameter'sexample, its schema's example, or a placeholder shaped like the schema.in: formDataparameters become a form body; withconsumes: 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 (
serverswith descriptions become named environments), - use
oneOf/anyOfbodies, 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.