postman

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDocLinks(items []CollectionItem, baseDocURL string)

AddDocLinks appends a Markdown doc link to each leaf request's description.

func ApplyAuth

func ApplyAuth(col *Collection, authCfg *config.Auth) error

ApplyAuth sets the collection-level auth from config.

func ApplyCommonHeaders

func ApplyCommonHeaders(items []CollectionItem, headers []config.Header)

ApplyCommonHeaders injects the configured headers into every leaf request. If a header with the same key already exists, its value and disabled flag are updated. Otherwise the header is appended.

func ApplyFolderOverrides

func ApplyFolderOverrides(items []CollectionItem, overrides map[string]config.FolderOverride) error

ApplyFolderOverrides applies per-folder auth/script overrides. Matching is case-sensitive on the folder name.

func ApplyScripts

func ApplyScripts(col *Collection, scriptsCfg *config.Scripts)

ApplyScripts sets collection-level pre-request and test events from config.

func PropagateAuthInherit

func PropagateAuthInherit(items []CollectionItem, overrides map[string]config.FolderOverride)

PropagateAuthInherit clears the auth on every folder and leaf request so that they inherit authentication from their parent (collection or enclosing folder).

Rules:

  • Items whose auth type is "noauth" are left untouched – they explicitly opt out of authentication and should not be changed.
  • Items with nil auth are already inheriting; they are skipped.
  • Folders whose name appears as a key in overrides are skipped (only the folder itself; its children are still processed so they can inherit from the overridden folder).
  • For leaf requests, both CollectionItem.Auth and Request.Auth are cleared.

func SetBaseURL

func SetBaseURL(items []CollectionItem, baseURL string)

SetBaseURL replaces the host (and protocol/port) of every request URL with baseURL. If baseURL starts with "{{" it is treated as a Postman variable.

Types

type Auth

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

Auth holds Postman authentication configuration.

func BuildAuth

func BuildAuth(authType string, attrs []AuthAttribute) (*Auth, error)

BuildAuth constructs a postman.Auth from the given type and attributes. Attributes are placed under the matching type key.

type AuthAttribute

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

AuthAttribute is a key/value attribute for an auth method.

type Body

type Body struct {
	Mode     string `json:"mode,omitempty"`
	Raw      string `json:"raw,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
}

Body holds request body data.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a minimal Postman API client.

func NewClient

func NewClient(apiKey, workspaceID string) *Client

NewClient creates a new Postman API client.

func (*Client) CreateCollection

func (c *Client) CreateCollection(data *CollectionWrapper) error

CreateCollection creates a new collection in the workspace.

func (*Client) DeleteCollection

func (c *Client) DeleteCollection(id string) error

DeleteCollection deletes a collection by ID/UID. Errors are logged but not fatal.

func (*Client) GetCollection

func (c *Client) GetCollection(id string) (*CollectionWrapper, error)

GetCollection fetches a full collection by its ID or UID.

func (*Client) GetWorkspaceCollections

func (c *Client) GetWorkspaceCollections() (map[string]string, error)

GetWorkspaceCollections returns a map of collection name → collection ID for all collections in the configured workspace.

func (*Client) ImportOpenAPI

func (c *Client) ImportOpenAPI(spec map[string]any) (string, error)

ImportOpenAPI uploads an OpenAPI spec to Postman and returns the UID of the temporary collection that Postman generates.

func (*Client) UpdateCollection

func (c *Client) UpdateCollection(id string, data *CollectionWrapper) error

UpdateCollection replaces an existing collection with new data.

type Collection

type Collection struct {
	Info      Info             `json:"info"`
	Items     []CollectionItem `json:"item"`
	Auth      *Auth            `json:"auth,omitempty"`
	Events    []Event          `json:"event,omitempty"`
	Variables []Variable       `json:"variable,omitempty"`
}

Collection is a Postman Collection v2.1.

type CollectionItem

type CollectionItem struct {
	// Leaf request fields
	ID          string     `json:"id,omitempty"`
	Name        string     `json:"name,omitempty"`
	Description string     `json:"description,omitempty"`
	Request     *Request   `json:"request,omitempty"`
	Responses   []any      `json:"response,omitempty"`
	Events      []Event    `json:"event,omitempty"`
	Auth        *Auth      `json:"auth,omitempty"`
	Variables   []Variable `json:"variable,omitempty"`

	// Folder-only field: if non-nil, this item is a folder.
	Items *[]CollectionItem `json:"item,omitempty"`
}

CollectionItem is a union of Item (request leaf) and ItemGroup (folder). We distinguish them by the presence of the "item" key (folder) vs "request" key (leaf).

func FlattenSingleFolders

func FlattenSingleFolders(items []CollectionItem) []CollectionItem

FlattenSingleFolders unwraps any folder that contains exactly one request whose name matches the folder name, replacing the folder with the request.

func MergeItems

func MergeItems(old, new []CollectionItem) []CollectionItem

MergeItems merges a newly-generated collection's items into the existing collection's items, preserving manual customisations.

Rules:

  • Items matched by name: update request fields (url, method, body, headers, description) from new; keep auth and events (scripts) from old.
  • Items only in new: added as-is (new endpoints).
  • Items only in old: removed (spec is source of truth).
  • Folders are recursed into.

func SortItemsAlpha

func SortItemsAlpha(items []CollectionItem) []CollectionItem

SortItemsAlpha sorts items alphabetically by name at every level.

func (*CollectionItem) IsFolder

func (ci *CollectionItem) IsFolder() bool

IsFolder reports whether this CollectionItem is a folder (item-group).

type CollectionWrapper

type CollectionWrapper struct {
	Collection Collection `json:"collection"`
}

CollectionWrapper is the root envelope returned by the Postman API.

type Event

type Event struct {
	Listen   string `json:"listen"`
	Script   Script `json:"script"`
	Disabled bool   `json:"disabled,omitempty"`
}

Event is a Postman script event (prerequest or test).

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

Header is a single HTTP header.

type Info

type Info struct {
	PostmanID string `json:"_postman_id,omitempty"`
	Name      string `json:"name"`
	Schema    string `json:"schema"`
}

Info holds metadata about the collection.

type Request

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

Request represents an HTTP request.

type Script

type Script struct {
	Type string   `json:"type,omitempty"`
	Exec []string `json:"exec"`
	Name string   `json:"name,omitempty"`
}

Script holds a JavaScript snippet.

type URL

type URL struct {
	Raw      string     `json:"raw,omitempty"`
	Protocol string     `json:"protocol,omitempty"`
	Host     []string   `json:"host,omitempty"`
	Path     []string   `json:"path,omitempty"`
	Port     string     `json:"port,omitempty"`
	Query    []URLParam `json:"query,omitempty"`
	Variable []Variable `json:"variable,omitempty"`
}

URL holds the broken-down URL of a request.

type URLParam

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

URLParam is a query parameter.

type Variable

type Variable struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
	Type  string `json:"type,omitempty"`
	Name  string `json:"name,omitempty"`
}

Variable is a Postman variable.

Jump to

Keyboard shortcuts

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