postman

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postman turns a Postman collection (v2.1, or v2.0 where the shapes coincide) and its environments into .http files and env files: folders become files, requests become named requests, variables become http-client.env.json, and the trivial forms of pm.test scripts become `# @assert` and `# @capture` lines.

The model below is hand-written from the collection format, on purpose: it reads only what the generator needs and tolerates the two shapes (string or object) the format allows for several fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LooksLikeCollection

func LooksLikeCollection(data []byte) bool

LooksLikeCollection reports whether a file is a Postman collection.

func LooksLikeEnvironment

func LooksLikeEnvironment(data []byte) bool

LooksLikeEnvironment reports whether a file is a Postman environment.

Types

type Auth

type Auth struct {
	Type   string      `json:"type"`
	Bearer []AuthParam `json:"bearer"`
	Basic  []AuthParam `json:"basic"`
	Apikey []AuthParam `json:"apikey"`
	Awsv4  []AuthParam `json:"awsv4"`
	Oauth2 []AuthParam `json:"oauth2"`
	Digest []AuthParam `json:"digest"`
}

Auth is an auth block on the collection, a folder or a request.

type AuthParam

type AuthParam struct {
	Key   string   `json:"key"`
	Value flexText `json:"value"`
}

AuthParam is one key/value of an auth block.

type Body

type Body struct {
	Mode       string       `json:"mode"` // raw, urlencoded, formdata, file, graphql
	Raw        string       `json:"raw"`
	Options    *BodyOptions `json:"options"`
	Urlencoded []FormField  `json:"urlencoded"`
	Formdata   []FormField  `json:"formdata"`
	File       *BodyFile    `json:"file"`
	Graphql    *GraphQL     `json:"graphql"`
	Disabled   bool         `json:"disabled"`
}

Body is the request body in one of Postman's modes.

type BodyFile

type BodyFile struct {
	Src string `json:"src"`
}

BodyFile is a whole-body file.

type BodyOptions

type BodyOptions struct {
	Raw struct {
		Language string `json:"language"`
	} `json:"raw"`
}

BodyOptions carries the raw body's language, which decides the content type when no header says.

type Collection

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

Collection is a Postman collection file.

type Environment

type Environment struct {
	Name   string     `json:"name"`
	Values []Variable `json:"values"`
	Scope  string     `json:"_postman_variable_scope"`
}

Environment is a Postman environment export.

type Event

type Event struct {
	Listen string `json:"listen"`
	Script Script `json:"script"`
}

Event is a script hook: listen is "prerequest" or "test".

type FormField

type FormField struct {
	Key         string   `json:"key"`
	Value       string   `json:"value"`
	Type        string   `json:"type"` // "text" or "file"
	Src         flexText `json:"src"`  // a path, or a list of paths, for a file field
	ContentType string   `json:"contentType"`
	Disabled    bool     `json:"disabled"`
}

FormField is one urlencoded or form-data field.

type GraphQL

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

GraphQL is a GraphQL body: the query and its variables as JSON text.

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

Header is one request header; Disabled ones are kept as comments.

type Info

type Info struct {
	Name        string   `json:"name"`
	Schema      string   `json:"schema"`
	Description flexText `json:"description"`
}

Info holds the collection's name and schema URL.

type Item

type Item struct {
	Name        string   `json:"name"`
	Description flexText `json:"description"`
	Item        []Item   `json:"item"`
	Request     *Request `json:"request"`
	Event       []Event  `json:"event"`
	Auth        *Auth    `json:"auth"`
}

Item is a request, or a folder when Item is non-empty (or Request nil).

func (Item) IsFolder

func (i Item) IsFolder() bool

IsFolder reports whether the item groups other items.

type Options

type Options struct {
	OutDir   string   // directory to write into
	EnvFiles []string // Postman environment exports, one environment each
	Force    bool     // overwrite existing files
}

Options controls generation.

type Query

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

Query is one query parameter of a URL object.

type Request

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

Request is the request of an item.

func (*Request) UnmarshalJSON

func (r *Request) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts the short form, a bare URL string, for a request.

type Result

type Result struct {
	Files          []string      `json:"files"`
	Requests       int           `json:"requests"`
	BaseURL        string        `json:"base_url,omitempty"`
	EnvFile        string        `json:"env_file,omitempty"`
	PrivateEnvFile string        `json:"private_env_file,omitempty"`
	Skipped        []string      `json:"skipped,omitempty"` // existing files kept (use --force)
	Unsupported    []Unsupported `json:"unsupported,omitempty"`
}

Result summarises what was generated. It has the shape of the OpenAPI importer's result plus what could not be translated.

func Import

func Import(collectionPath string, opts Options) (*Result, error)

Import reads a Postman collection and writes .http files, an env file per Postman environment given, and apic.yaml when the collection has a default auth.

type Script

type Script struct {
	Exec flexLines `json:"exec"`
}

Script holds the lines of a script.

type URL

type URL struct {
	Raw      string     `json:"raw"`
	Query    []Query    `json:"query"`
	Variable []Variable `json:"variable"`
}

URL is the request URL: the raw text, plus the parsed parts Postman keeps alongside it. Only Raw, Query and Variable are read.

func (*URL) UnmarshalJSON

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

UnmarshalJSON accepts a bare string for the URL.

type Unsupported

type Unsupported struct {
	Request string `json:"request"` // request id, or "collection"
	What    string `json:"what"`    // the script line, auth type or body mode
	Reason  string `json:"reason"`
}

Unsupported is one thing the collection had that the .http files cannot carry, with the request it belongs to and a one-line reason.

type Variable

type Variable struct {
	Key      string   `json:"key"`
	Value    flexText `json:"value"`
	Type     string   `json:"type"` // "secret" in environments marks a masked value
	Disabled bool     `json:"disabled"`
	Enabled  *bool    `json:"enabled"` // environment files use enabled instead of disabled
}

Variable is a collection, URL (path) or environment variable.

func (Variable) Active

func (v Variable) Active() bool

Active reports whether the variable is in effect.

Jump to

Keyboard shortcuts

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