Documentation
¶
Overview ¶
Package postman provides import and export functionality for Postman Collection v2.1.0 format.
Index ¶
- Constants
- type Auth
- type AuthAttribute
- type Body
- type BodyOptions
- type Cert
- type CertFile
- type Collection
- type Cookie
- type Description
- type Event
- type ExportOptions
- type ExportResult
- type File
- type FormDataPair
- type GraphQL
- type Header
- type ImportOptions
- type ImportResult
- type Info
- type Item
- type NameTracker
- type Proxy
- type Query
- type RawOptions
- type Request
- type RequestString
- type Response
- type Script
- type URL
- type URLEncodedPair
- type Variable
- type VariableConflict
Constants ¶
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 any `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 any `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 any `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 ¶
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 []any `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
VariableConflicts []VariableConflict
}
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 any `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 any `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 ¶
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 any `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 any `json:"protocolProfileBehavior,omitempty"`
Auth *Auth `json:"auth,omitempty"`
}
Item can be either a request item or a folder (item-group)
type NameTracker ¶ added in v0.2.10
type NameTracker struct {
// contains filtered or unexported fields
}
NameTracker tracks used names and provides unique names for duplicates
func NewNameTracker ¶ added in v0.2.10
func NewNameTracker() *NameTracker
NewNameTracker creates a new name tracker
func (*NameTracker) GetUniqueName ¶ added in v0.2.10
func (n *NameTracker) GetUniqueName(name string) string
GetUniqueName returns a unique name, appending _2, _3, etc. for duplicates
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
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 any `json:"responseTime,omitempty"` // Can be null, string, or number
Timings any `json:"timings,omitempty"`
Header any `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 any `json:"exec,omitempty"` // Can be []string or string
Src *URL `json:"src,omitempty"`
Name string `json:"name,omitempty"`
}
Script represents a JavaScript script
type URL ¶
type URL struct {
Raw string `json:"raw,omitempty"`
Protocol string `json:"protocol,omitempty"`
Host any `json:"host,omitempty"` // Can be string or []string
Path any `json:"path,omitempty"` // Can be string or []any
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) UnmarshalJSON ¶
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 any `json:"value,omitempty"`
Type string `json:"type,omitempty"` // "string", "boolean", "any", "number", "secret"
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