postman

package
v0.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package postman provides import and export functionality for Postman Collection v2.1.0 format.

Index

Constants

View Source
const SchemaV21 = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"

SchemaV21 is the Postman Collection v2.1.0 schema URL

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Type     string          `json:"type"`
	NoAuth   interface{}     `json:"noauth,omitempty"`
	APIKey   []AuthAttribute `json:"apikey,omitempty"`
	AWSv4    []AuthAttribute `json:"awsv4,omitempty"`
	Basic    []AuthAttribute `json:"basic,omitempty"`
	Bearer   []AuthAttribute `json:"bearer,omitempty"`
	Digest   []AuthAttribute `json:"digest,omitempty"`
	EdgeGrid []AuthAttribute `json:"edgegrid,omitempty"`
	Hawk     []AuthAttribute `json:"hawk,omitempty"`
	NTLM     []AuthAttribute `json:"ntlm,omitempty"`
	OAuth1   []AuthAttribute `json:"oauth1,omitempty"`
	OAuth2   []AuthAttribute `json:"oauth2,omitempty"`
}

Auth represents authentication configuration

func (*Auth) GetAttribute

func (a *Auth) GetAttribute(attrs []AuthAttribute, key string) string

GetAttribute returns the value of an auth attribute by key

type AuthAttribute

type AuthAttribute struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value,omitempty"`
	Type  string      `json:"type,omitempty"`
}

AuthAttribute represents a key-value pair for authentication

type Body

type Body struct {
	Mode       string           `json:"mode,omitempty"`
	Raw        string           `json:"raw,omitempty"`
	GraphQL    *GraphQL         `json:"graphql,omitempty"`
	URLEncoded []URLEncodedPair `json:"urlencoded,omitempty"`
	FormData   []FormDataPair   `json:"formdata,omitempty"`
	File       *File            `json:"file,omitempty"`
	Options    *BodyOptions     `json:"options,omitempty"`
	Disabled   bool             `json:"disabled,omitempty"`
}

Body represents the request body

type BodyOptions

type BodyOptions struct {
	Raw *RawOptions `json:"raw,omitempty"`
}

BodyOptions contains additional body configuration

type Cert

type Cert struct {
	Name       string    `json:"name,omitempty"`
	Matches    []string  `json:"matches,omitempty"`
	Key        *CertFile `json:"key,omitempty"`
	Cert       *CertFile `json:"cert,omitempty"`
	Passphrase string    `json:"passphrase,omitempty"`
}

Cert represents an SSL certificate

type CertFile

type CertFile struct {
	Src string `json:"src,omitempty"`
}

CertFile represents a certificate file path

type Collection

type Collection struct {
	Info                    Info        `json:"info"`
	Item                    []Item      `json:"item"`
	Event                   []Event     `json:"event,omitempty"`
	Variable                []Variable  `json:"variable,omitempty"`
	Auth                    *Auth       `json:"auth,omitempty"`
	ProtocolProfileBehavior interface{} `json:"protocolProfileBehavior,omitempty"`
}

Collection represents a Postman Collection v2.1.0

func ExportToCollection

func ExportToCollection(httpFiles []string, opts ExportOptions) (*Collection, error)

ExportToCollection converts .http files to a Postman Collection struct

func NewCollection

func NewCollection(name string) *Collection

NewCollection creates a new empty Postman collection

type Cookie struct {
	Domain     string        `json:"domain"`
	Expires    string        `json:"expires,omitempty"`
	MaxAge     string        `json:"maxAge,omitempty"`
	HostOnly   bool          `json:"hostOnly,omitempty"`
	HTTPOnly   bool          `json:"httpOnly,omitempty"`
	Name       string        `json:"name,omitempty"`
	Path       string        `json:"path"`
	Secure     bool          `json:"secure,omitempty"`
	Session    bool          `json:"session,omitempty"`
	Value      string        `json:"value,omitempty"`
	Extensions []interface{} `json:"extensions,omitempty"`
}

Cookie represents an HTTP cookie

type Description

type Description struct {
	Content string `json:"content,omitempty"`
	Type    string `json:"type,omitempty"`
	Version string `json:"version,omitempty"`
}

Description can be a string or an object

func (*Description) MarshalJSON

func (d *Description) MarshalJSON() ([]byte, error)

MarshalJSON outputs description as a string if only content is set

func (*Description) UnmarshalJSON

func (d *Description) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both string and object description formats

type Event

type Event struct {
	ID       string  `json:"id,omitempty"`
	Listen   string  `json:"listen"` // "prerequest" or "test"
	Script   *Script `json:"script,omitempty"`
	Disabled bool    `json:"disabled,omitempty"`
}

Event represents a script event (prerequest or test)

type ExportOptions

type ExportOptions struct {
	// CollectionName is the name for the Postman collection
	CollectionName string
	// CollectionDescription is the description for the collection
	CollectionDescription string
	// IncludeVariables includes file variables as collection variables
	IncludeVariables bool
	// IncludeScripts includes pre-request and test scripts
	IncludeScripts bool
	// PrettyPrint outputs formatted JSON
	PrettyPrint bool
}

ExportOptions configures how .http files are exported

func DefaultExportOptions

func DefaultExportOptions() ExportOptions

DefaultExportOptions returns sensible defaults

type ExportResult

type ExportResult struct {
	RequestsCount  int
	VariablesCount int
	CollectionPath string
}

ExportResult contains information about the export

func Export

func Export(httpFiles []string, outputPath string, opts ExportOptions) (*ExportResult, error)

Export converts one or more .http files to a Postman collection

type File

type File struct {
	Src     interface{} `json:"src,omitempty"` // Can be string or null
	Content string      `json:"content,omitempty"`
}

File represents a file to upload

type FormDataPair

type FormDataPair struct {
	Key         string       `json:"key"`
	Value       string       `json:"value,omitempty"`
	Src         interface{}  `json:"src,omitempty"` // Can be string, []string, or null
	Disabled    bool         `json:"disabled,omitempty"`
	Type        string       `json:"type,omitempty"` // "text" or "file"
	ContentType string       `json:"contentType,omitempty"`
	Description *Description `json:"description,omitempty"`
}

FormDataPair represents a form-data field

type GraphQL

type GraphQL struct {
	Query     string `json:"query,omitempty"`
	Variables string `json:"variables,omitempty"`
}

GraphQL represents GraphQL request body

type Header struct {
	Key         string       `json:"key"`
	Value       string       `json:"value"`
	Disabled    bool         `json:"disabled,omitempty"`
	Description *Description `json:"description,omitempty"`
}

Header represents an HTTP header

type ImportOptions

type ImportOptions struct {
	// OutputDir is the directory where .http files will be created (multi-file mode)
	OutputDir string
	// OutputFile is the file path for single-file mode output
	OutputFile string
	// SingleFile creates a single .http file instead of one per folder
	SingleFile bool
	// IncludeVariables includes collection variables as file variables
	IncludeVariables bool
	// IncludeScripts includes pre-request and test scripts
	IncludeScripts bool
}

ImportOptions configures how collections are imported

func DefaultImportOptions

func DefaultImportOptions() ImportOptions

DefaultImportOptions returns sensible defaults

type ImportResult

type ImportResult struct {
	FilesCreated   []string
	RequestsCount  int
	FoldersCount   int
	VariablesCount int
	Errors         []string
}

ImportResult contains information about imported requests

func Import

func Import(collectionPath string, opts ImportOptions) (*ImportResult, error)

Import reads a Postman collection file and converts it to .http file(s)

func ImportCollection

func ImportCollection(collection *Collection, opts ImportOptions) (*ImportResult, error)

ImportCollection converts a parsed Postman collection to .http file(s)

type Info

type Info struct {
	Name        string       `json:"name"`
	PostmanID   string       `json:"_postman_id,omitempty"`
	Description *Description `json:"description,omitempty"`
	Version     interface{}  `json:"version,omitempty"`
	Schema      string       `json:"schema"`
}

Info contains metadata about the collection

type Item

type Item struct {
	// Common fields
	Name        string       `json:"name,omitempty"`
	Description *Description `json:"description,omitempty"`
	Variable    []Variable   `json:"variable,omitempty"`
	Event       []Event      `json:"event,omitempty"`

	// Folder (item-group) specific
	Item []Item `json:"item,omitempty"`

	// Request item specific
	ID                      string      `json:"id,omitempty"`
	Request                 *Request    `json:"request,omitempty"`
	Response                []Response  `json:"response,omitempty"`
	ProtocolProfileBehavior interface{} `json:"protocolProfileBehavior,omitempty"`
	Auth                    *Auth       `json:"auth,omitempty"`
}

Item can be either a request item or a folder (item-group)

func (*Item) IsFolder

func (i *Item) IsFolder() bool

IsFolder returns true if this item is a folder (contains sub-items)

type Proxy

type Proxy struct {
	Match    string `json:"match,omitempty"`
	Host     string `json:"host,omitempty"`
	Port     int    `json:"port,omitempty"`
	Tunnel   bool   `json:"tunnel,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
}

Proxy represents proxy configuration

type Query

type Query struct {
	Key         *string      `json:"key"`             // Can be null per Postman schema
	Value       *string      `json:"value,omitempty"` // Can be null per Postman schema
	Disabled    bool         `json:"disabled,omitempty"`
	Description *Description `json:"description,omitempty"`
}

Query represents a URL query parameter

func (*Query) GetKey

func (q *Query) GetKey() string

GetKey returns the key string or empty if nil

func (*Query) GetValue

func (q *Query) GetValue() string

GetValue returns the value string or empty if nil

type RawOptions

type RawOptions struct {
	Language string `json:"language,omitempty"`
}

RawOptions contains options for raw body mode

type Request

type Request struct {
	URL         *URL         `json:"url,omitempty"`
	Auth        *Auth        `json:"auth,omitempty"`
	Proxy       *Proxy       `json:"proxy,omitempty"`
	Certificate *Cert        `json:"certificate,omitempty"`
	Method      string       `json:"method,omitempty"`
	Description *Description `json:"description,omitempty"`
	Header      []Header     `json:"header,omitempty"`
	Body        *Body        `json:"body,omitempty"`
}

Request represents an HTTP request

type RequestString

type RequestString string

RequestString handles the case where request is just a string URL

type Response

type Response struct {
	ID              string      `json:"id,omitempty"`
	Name            string      `json:"name,omitempty"`
	OriginalRequest *Request    `json:"originalRequest,omitempty"`
	ResponseTime    interface{} `json:"responseTime,omitempty"` // Can be null, string, or number
	Timings         interface{} `json:"timings,omitempty"`
	Header          interface{} `json:"header,omitempty"` // Can be []Header, string, or null
	Cookie          []Cookie    `json:"cookie,omitempty"`
	Body            string      `json:"body,omitempty"`
	Status          string      `json:"status,omitempty"`
	Code            int         `json:"code,omitempty"`
}

Response represents a saved response

type Script

type Script struct {
	ID   string      `json:"id,omitempty"`
	Type string      `json:"type,omitempty"`
	Exec interface{} `json:"exec,omitempty"` // Can be []string or string
	Src  *URL        `json:"src,omitempty"`
	Name string      `json:"name,omitempty"`
}

Script represents a JavaScript script

func (*Script) GetExec

func (s *Script) GetExec() string

GetExec returns the script content as a single string

type URL

type URL struct {
	Raw      string      `json:"raw,omitempty"`
	Protocol string      `json:"protocol,omitempty"`
	Host     interface{} `json:"host,omitempty"` // Can be string or []string
	Path     interface{} `json:"path,omitempty"` // Can be string or []interface{}
	Port     string      `json:"port,omitempty"`
	Query    []Query     `json:"query,omitempty"`
	Hash     string      `json:"hash,omitempty"`
	Variable []Variable  `json:"variable,omitempty"`
}

URL represents a request URL

func (*URL) GetHost

func (u *URL) GetHost() string

GetHost returns the host as a string

func (*URL) GetPath

func (u *URL) GetPath() string

GetPath returns the path as a string

func (*URL) GetRaw

func (u *URL) GetRaw() string

GetRaw returns the raw URL string

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both string and object URL formats

type URLEncodedPair

type URLEncodedPair struct {
	Key         string       `json:"key"`
	Value       string       `json:"value,omitempty"`
	Disabled    bool         `json:"disabled,omitempty"`
	Description *Description `json:"description,omitempty"`
}

URLEncodedPair represents a URL-encoded form parameter

type Variable

type Variable struct {
	ID          string       `json:"id,omitempty"`
	Key         string       `json:"key,omitempty"`
	Value       interface{}  `json:"value,omitempty"`
	Type        string       `json:"type,omitempty"` // "string", "boolean", "any", "number"
	Name        string       `json:"name,omitempty"`
	Description *Description `json:"description,omitempty"`
	System      bool         `json:"system,omitempty"`
	Disabled    bool         `json:"disabled,omitempty"`
}

Variable represents a collection variable

func (*Variable) GetValue

func (v *Variable) GetValue() string

GetValue returns the variable value as a string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL