Skip to content

imbus/openapi_to_robot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAPI To Robot Framework Test Tool (openapi_to_robot)

A lightweight Node.js CLI tool that automatically converts an OpenAPI 3.x and Swagger 2.0 specification into a fully structured Robot Framework test suite.

This tool parses your OpenAPI file, extracts endpoints, parameters, request bodies, and generates Robot Framework test cases using RequestsLibrary — complete with dummy values, headers, query parameters, and JSON bodies.

Perfect for quickly bootstrapping API test automation. This tool has been tested on OpenAPI version 3.0.1.

This project uses @readme/openapi-parser for parsing and dereferencing OpenAPI specifications. It is a maintained fork of @apidevtools/swagger-parser with improved validation messages and error handling.


Table of Contents


Features

  • Converts OpenAPI v3.x and Swagger 2.0 specs into Robot Framework .robot test file
  • Automatically generates:
    • Test case names
    • URLs (including path params and query params)
    • JSON bodies
    • Form‑encoded bodies
  • Supports oneOf, allOf, nested objects, arrays, and enums
  • Support Content-Type detection
  • CLI interface
  • Final robot file with dummy data

Requirements

  • Node.js >=22.19.0
  • NPM >=10.9.3

Installation

Clone the repository:

git clone https://github.com/imbus/openapi_to_robot.git
cd openapi_to_robot

Install dependencies:

npm install

Copy .env.example to .env file

cp .env.example .env

Usage

node ./parser.js --input ./examples/swagger.json --output ./robot_tests.robot

Output Example

The tool openapi_to_robot will generate a robot_tests.robot file containing the following testcases:

*** Settings ***
Library    Collections
Library    RequestsLibrary

*** Variables ***
${HTTP_PROXY}     ${None}
${HTTPS_PROXY}    ${None}
${verify}         ${False}
${URL}            https://localhost/OpenApiRest

*** Test Cases ***
POST__submit
    ${headers}    Create Dictionary    Content-Type=application/json
    ${body}    Create Dictionary
    ${body_user}    Create Dictionary
    Set To Dictionary    ${body_user}    username=dummy
    Set To Dictionary    ${body_user}    email=dummy
    ${body_user_address}    Create Dictionary
    Set To Dictionary    ${body_user_address}    street=dummy
    Set To Dictionary    ${body_user_address}    city=dummy
    Set To Dictionary    ${body_user_address}    postalCode=dummy
    Set To Dictionary    ${body_user}    address=${body_user_address}
    ${body_user_preferences}    Create List
    Append To List    ${body_user_preferences}    dummy
    Set To Dictionary    ${body_user}    preferences=${body_user_preferences}
    Set To Dictionary    ${body}    user=${body_user}
    &{proxies}    Create Dictionary    http=${HTTP_PROXY}    https=${HTTPS_PROXY}
    ${response}    POST    url=${URL}/submit    headers=${headers}    json=${body}    proxies=${proxies}    verify=${verify}

POST__submit_form
    ${headers}    Create Dictionary    Content-Type=application/x-www-form-urlencoded
    ${body}    Set Variable    username=dummy&email=dummy&street=dummy&city=dummy&postalCode=dummy&preferences=dummy
    &{proxies}    Create Dictionary    http=${HTTP_PROXY}    https=${HTTPS_PROXY}
    ${response}    POST    url=${URL}/submit-form    headers=${headers}    data=${body}    proxies=${proxies}    verify=${verify}

After executing the Robot Framework test case, the captured HTTP request appears as follows:

Testcase: POST__submit:

POST /submit HTTP/1.1
Host: localhost
User-Agent: python-requests/2.32.3
Accept-Encoding: gzip, deflate, br
Accept: */*
Connection: keep-alive
Content-Type: application/json
Content-Length: 147

{"user": {"username": "dummy", "email": "dummy", "address": {"street": "dummy", "city": "dummy", "postalCode":"dummy"}, "preferences": ["dummy"]}}

Testcase: POST__submit_form:

POST /submit-form HTTP/2
Host: localhost
User-Agent: python-requests/2.32.3
Accept-Encoding: gzip, deflate, br
Accept: */*
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 85

username=dummy&email=dummy&street=dummy&city=dummy&postalCode=dummy&preferences=dummy

CLI Options

-i, --input 	Path to OpenAPI file	./example/openapi_v3.json
-o, --output 	Output Robot Framework file	./robot_tests.robot
-h, --help	    Show help menu

Security Notes

  • The tool sets NODE_TLS_REJECT_UNAUTHORIZED=0 to allow parsing specs from self‑signed HTTPS sources. If you don’t need this, remove or override it.

  • .env is intentionally excluded from Git for safety.

License

This project is licensed under the Apache License Version 2.0. See the LICENSE file for details.

Contributors

About

Tool to convert OpenAPI to Robot Framework Testcases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published