Skip to content

noiv import

Import and convert test collections from various sources including Postman, OpenAPI, and other formats.

Syntax

bash
noiv import <source> [OPTIONS]

Description

The import command converts existing API test collections into NOIV format, enabling:

  • Postman migration - Import Postman collections seamlessly
  • OpenAPI conversion - Generate tests from OpenAPI/Swagger specs
  • Multi-format support - Convert from various testing tools
  • Intelligent mapping - Automatic test structure optimization
  • Environment preservation - Maintain existing configurations

Arguments

<source> (required)

Path to the source file or URL to import.

bash
noiv import postman_collection.json
noiv import swagger.yaml
noiv import https://api.example.com/swagger.json

Options

--format, -f

Source format: postman, openapi, swagger, insomnia, or auto (default).

bash
noiv import collection.json --format postman
noiv import api.yaml -f openapi

--output, -o

Output file for converted tests (default: imported_tests.yaml).

bash
noiv import collection.json --output user_tests.yaml
noiv import swagger.yaml -o api_tests.yaml

--environment, -e

Include environment configurations from source.

bash
noiv import collection.json --environment
noiv import collection.json -e

--filter, -F

Import only requests matching the pattern.

bash
noiv import collection.json --filter "user.*"
noiv import collection.json -F "auth|login"

--exclude, -x

Exclude requests matching the pattern.

bash
noiv import collection.json --exclude ".*test.*"
noiv import collection.json -x "debug|temp"

--base-url, -u

Override base URL in imported tests.

bash
noiv import collection.json --base-url https://api.example.com
noiv import swagger.yaml -u http://localhost:3000

--generate-tests

Generate additional test scenarios beyond basic requests.

bash
noiv import swagger.yaml --generate-tests

--include-examples

Include example data from source documentation.

bash
noiv import openapi.yaml --include-examples

--preserve-structure

Maintain original folder/group structure.

bash
noiv import collection.json --preserve-structure

--interactive, -i

Enable interactive import with customization options.

bash
noiv import collection.json --interactive

Source Formats

Postman Collections

bash
noiv import postman_collection.json

Supported Features:

  • Request/response examples
  • Environment variables
  • Pre-request scripts (converted to variables)
  • Test assertions (converted to expectations)
  • Folder organization
  • Authentication configurations

Example Import:

json
// postman_collection.json
{
  "info": {
    "name": "User API Collection",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api.example.com"
    }
  ],
  "item": [
    {
      "name": "Create User",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"name\": \"John Doe\",\n  \"email\": \"john@example.com\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/users",
          "host": ["{{baseUrl}}"],
          "path": ["users"]
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "pm.test('Status code is 201', function () {",
              "    pm.response.to.have.status(201);",
              "});"
            ]
          }
        }
      ]
    }
  ]
}

Converted Output:

yaml
name: User API Collection
base_url: https://api.example.com
variables:
  baseUrl: "https://api.example.com"

tests:
  - name: Create User
    request:
      method: POST
      path: /users
      headers:
        Content-Type: application/json
      body:
        name: "John Doe"
        email: "john@example.com"
    expect:
      status: 201

OpenAPI/Swagger Specifications

bash
noiv import openapi.yaml --generate-tests

Supported Features:

  • Path definitions
  • HTTP methods
  • Request/response schemas
  • Authentication schemes
  • Parameter definitions
  • Example values

Example Import:

yaml
# openapi.yaml
openapi: 3.0.0
info:
  title: User API
  version: 1.0.0
servers:
  - url: https://api.example.com
paths:
  /users:
    post:
      summary: Create a new user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - email
              properties:
                name:
                  type: string
                  example: "John Doe"
                email:
                  type: string
                  format: email
                  example: "john@example.com"
      responses:
        '201':
          description: User created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  name:
                    type: string
                  email:
                    type: string

Converted Output:

yaml
name: User API Tests
base_url: https://api.example.com

tests:
  - name: Create User - Valid Data
    request:
      method: POST
      path: /users
      headers:
        Content-Type: application/json
      body:
        name: "John Doe"
        email: "john@example.com"
    expect:
      status: 201
      body:
        id: "{{user_id}}"
        name: "John Doe"
        email: "john@example.com"
    extract:
      user_id: "$.id"
  
  # Generated additional test scenarios
  - name: Create User - Missing Required Fields
    request:
      method: POST
      path: /users
      headers:
        Content-Type: application/json
      body:
        name: "John Doe"
        # email intentionally missing
    expect:
      status: 400
  
  - name: Create User - Invalid Email Format
    request:
      method: POST
      path: /users
      headers:
        Content-Type: application/json
      body:
        name: "John Doe"
        email: "invalid-email"
    expect:
      status: 400

Insomnia Collections

bash
noiv import insomnia_export.json --format insomnia

Supported Features:

  • Request definitions
  • Environment variables
  • Authentication
  • Request grouping

HAR Files

bash
noiv import network_trace.har --format har

Supported Features:

  • Network request recordings
  • Headers and cookies
  • Request timing
  • Response validation

cURL Commands

bash
noiv import curl_commands.txt --format curl

Example:

bash
# curl_commands.txt
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "email": "john@example.com"}'

curl -X GET https://api.example.com/users/123 \
  -H "Authorization: Bearer token123"

Interactive Import Mode

bash
noiv import postman_collection.json --interactive

Interactive Flow:

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                           NOIV Import Wizard                                                  ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

📂 Source: postman_collection.json
🔍 Detected Format: Postman Collection v2.1

📊 Import Summary:
   • 15 requests found
   • 3 folders detected
   • 5 environment variables
   • 8 test scripts

🎯 Import Options:

1. 📋 Request Selection:
   ✓ All requests (15)
   ○ Filter by folder
   ○ Select specific requests

2. 🌍 Environment Handling:
   ✓ Import all environments
   ○ Select specific environment
   ○ Skip environments

3. 🧪 Test Generation:
   ✓ Convert existing test scripts
   ✓ Generate additional test scenarios
   ○ Basic import only

4. 📁 Structure Organization:
   ✓ Preserve original folder structure
   ○ Flatten all requests
   ○ Group by HTTP method

Proceed with these settings? [Y/n]: Y

🚀 Importing collection...

✅ Processed folder: Authentication (3 requests)
✅ Processed folder: User Management (8 requests)  
✅ Processed folder: Admin Operations (4 requests)
✅ Converted 12 test scripts
✅ Generated 8 additional test scenarios
✅ Imported 2 environments

📝 Import complete! Generated: user_api_tests.yaml

Advanced Import Features

Environment Variable Mapping

bash
noiv import collection.json --interactive

Environment Mapping:

🌍 Environment Variable Mapping:

Postman Variables → NOIV Variables:
{{baseUrl}} → {{base_url}}
{{apiKey}} → {{api_key}}
{{userId}} → {{user_id}}
{{authToken}} → {{auth_token}}

Custom Mappings:
1. Keep original names
2. Use NOIV conventions (recommended)
3. Custom mapping

Choice [1-3]: 2

✅ Variables will be converted to NOIV naming conventions

Request Filtering and Selection

bash
noiv import large_collection.json --interactive

Request Selection:

📋 Request Selection (45 requests found):

Folders:
[ ] Authentication (5 requests)
    [x] Login User
    [x] Register User  
    [x] Refresh Token
    [ ] Logout User
    [ ] Password Reset

[x] User Management (12 requests)
    [x] All requests selected

[ ] Admin Operations (8 requests)
    [ ] All requests deselected

[x] Public API (20 requests)
    [x] All requests selected

Selected: 32/45 requests
Continue? [Y/n]: Y

Test Script Conversion

NOIV intelligently converts Postman test scripts to NOIV assertions:

Postman Test Script:

javascript
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response has user ID", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.id).to.be.a('string');
    pm.expect(jsonData.id).to.have.lengthOf.above(0);
});

pm.test("Email format is valid", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.email).to.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
});

// Set variable for next request
pm.globals.set("userId", pm.response.json().id);

Converted NOIV Test:

yaml
tests:
  - name: Get User Details
    request:
      method: GET
      path: /users/{{user_id}}
    expect:
      status: 200
      body:
        id: "{{user_id}}"
        email: "regex:^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$"
    assert:
      - jsonpath: "$.id"
        condition: "type"
        value: "string"
      - jsonpath: "$.id"
        condition: "length_gt"
        value: 0
    extract:
      userId: "$.id"

Integration Examples

Migrating from Postman

bash
# Step 1: Export Postman collection
# In Postman: File → Export → Collection v2.1

# Step 2: Import to NOIV
noiv import postman_collection.json \
  --environment \
  --preserve-structure \
  --output migrated_tests.yaml

# Step 3: Test the migration
noiv test migrated_tests.yaml --environment development

# Step 4: Enhance with NOIV features
noiv build migrated_tests.yaml --interactive

CI/CD Integration

yaml
# .github/workflows/import-and-test.yml
name: Import and Test API

on:
  push:
    paths:
      - 'api-docs/**'

jobs:
  import-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - name: Install NOIV
        run: pip install noiv
        
      - name: Import OpenAPI Spec
        run: |
          noiv import api-docs/openapi.yaml \
            --generate-tests \
            --output generated_tests.yaml
            
      - name: Run Generated Tests
        run: |
          noiv test generated_tests.yaml \
            --environment staging \
            --format junit \
            --output test-results.xml

Bulk Import Processing

bash
#!/bin/bash
# bulk_import.sh

# Import multiple collections
for collection in postman/*.json; do
    filename=$(basename "$collection" .json)
    echo "Importing $collection..."
    
    noiv import "$collection" \
      --output "tests/${filename}_tests.yaml" \
      --environment
done

# Combine all tests
noiv build --template e2e --output combined_tests.yaml

API Documentation Sync

bash
#!/bin/bash
# sync_api_docs.sh

# Download latest OpenAPI spec
curl -o latest_spec.yaml https://api.example.com/openapi.yaml

# Import and generate tests
noiv import latest_spec.yaml \
  --generate-tests \
  --include-examples \
  --output api_tests.yaml

# Run tests to validate API
noiv test api_tests.yaml --environment production

Format-Specific Features

Postman Collections

Variable Conversion:

  • Global variables → Environment variables
  • Collection variables → Test suite variables

Authentication:

  • Bearer Token → Authorization header
  • API Key → Custom header or query param
  • Basic Auth → Authorization header
  • OAuth 2.0 → Bearer token with refresh logic

Test Scripts:

  • pm.test()expect assertions
  • pm.expect()assert statements
  • pm.globals.set()extract variables
  • pm.environment.set() → Variable assignment

OpenAPI/Swagger

Schema Validation:

  • Request schemas → Request body validation
  • Response schemas → Response body expectations
  • Required fields → Validation assertions
  • Data types → Type checking

Parameter Handling:

  • Path parameters → URL templating
  • Query parameters → Query object
  • Header parameters → Headers object
  • Request body → Body object

Security Schemes:

  • API Key → Header/query authentication
  • HTTP Basic → Basic authentication
  • Bearer Token → Authorization header
  • OAuth 2.0 → Token-based authentication

Insomnia

Request Grouping:

  • Folders → Test groups
  • Sub-requests → Test dependencies
  • Environment switching → Environment configurations

Template Variables:

  • Base environment → Default environment
  • Sub-environments → Named environments

Best Practices

1. Review Imported Tests

bash
# Always review imported tests before running
noiv import collection.json --output review_tests.yaml
cat review_tests.yaml  # Review the content
noiv test review_tests.yaml --environment test  # Test in safe environment

2. Enhance After Import

bash
# Import basic structure
noiv import swagger.yaml --output base_tests.yaml

# Enhance with interactive builder
noiv build base_tests.yaml --interactive

# Add performance testing
noiv benchmark base_tests.yaml

3. Organize Imported Tests

bash
# Import with structure preservation
noiv import large_collection.json --preserve-structure --output full_tests.yaml

# Split into logical groups
noiv import large_collection.json --filter "auth.*" --output auth_tests.yaml
noiv import large_collection.json --filter "user.*" --output user_tests.yaml
noiv import large_collection.json --filter "admin.*" --output admin_tests.yaml

4. Version Control Integration

bash
# Track API changes
git add original_collection.json
git add imported_tests.yaml
git commit -m "Import Postman collection v2.1"

# Update when API changes
noiv import updated_collection.json --output imported_tests.yaml
git diff imported_tests.yaml  # Review changes

5. Environment Management

yaml
# Keep original environments for reference
environments:
  # Imported from Postman
  postman_dev:
    base_url: "{{baseUrl}}"
    api_key: "{{apiKey}}"
  
  # Enhanced NOIV environments
  development:
    base_url: "http://localhost:3000"
    api_key: "dev-key-123"
    timeout: 30
    
  staging:
    base_url: "https://staging-api.example.com"
    api_key: "{{STAGING_API_KEY}}"
    timeout: 60

Troubleshooting

Import Errors

bash
# Invalid format detection
noiv import unknown_file.json --format postman
# Output: Error: File is not a valid Postman collection

# Missing required fields
noiv import incomplete_swagger.yaml
# Output: Warning: OpenAPI spec missing required 'paths' field

Variable Resolution

bash
# Unresolved variables after import
noiv test imported_tests.yaml
# Output: Error: Variable '{{baseUrl}}' not defined

# Fix with variable override
noiv test imported_tests.yaml --variable baseUrl=https://api.example.com

Authentication Issues

bash
# Missing authentication after import
noiv test imported_tests.yaml
# Output: Error: 401 Unauthorized

# Add authentication
noiv build imported_tests.yaml --interactive
# Configure authentication in the builder

See Also

Released under the MIT License.