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 ¶
- func LooksLikeCollection(data []byte) bool
- func LooksLikeEnvironment(data []byte) bool
- type Auth
- type AuthParam
- type Body
- type BodyFile
- type BodyOptions
- type Collection
- type Environment
- type Event
- type FormField
- type GraphQL
- type Header
- type Info
- type Item
- type Options
- type Query
- type Request
- type Result
- type Script
- type URL
- type Unsupported
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LooksLikeCollection ¶
LooksLikeCollection reports whether a file is a Postman collection.
func LooksLikeEnvironment ¶
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 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 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 Header ¶
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).
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 ¶
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.
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 ¶
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.