Documentation
¶
Overview ¶
Package oas holds the small, dependency-light helpers that the rules use to read an OpenAPI document as raw YAML nodes: safe accessors, JSONPath building, local $ref resolution and iterators over operations, parameters and schemas.
Nothing in this package reports violations; it only navigates documents. All accessors accept nil nodes and return zero values for them, so a check can chain lookups without testing every step.
Index ¶
- func Dig(n *yaml.Node, keys ...string) *yaml.Node
- func Empty(n *yaml.Node) bool
- func Entry(n *yaml.Node, key string) (*yaml.Node, *yaml.Node)
- func Get(n *yaml.Node, key string) *yaml.Node
- func Has(n *yaml.Node, key string) bool
- func HasType(schema *yaml.Node, want string) bool
- func Index(base string, i int) string
- func Int(n *yaml.Node) (int, bool)
- func IsClientOrServerError(code string) bool
- func IsMap(n *yaml.Node) bool
- func IsMethod(key string) bool
- func IsNull(n *yaml.Node) bool
- func IsOAS3(root *yaml.Node) bool
- func IsOAS31(root *yaml.Node) bool
- func IsScalar(n *yaml.Node) bool
- func IsSeq(n *yaml.Node) bool
- func IsSuccess(code string) bool
- func IsTrue(n *yaml.Node) bool
- func Items(n *yaml.Node) iter.Seq2[int, *yaml.Node]
- func Join(base string, key string) string
- func JoinAll(base string, keys ...string) string
- func Keys(n *yaml.Node) []string
- func Methods() []string
- func NodeAt(root *yaml.Node, path string) *yaml.Node
- func Number(n *yaml.Node) (float64, bool)
- func Operations(root *yaml.Node) iter.Seq[Operation]
- func Pairs(n *yaml.Node) iter.Seq2[*yaml.Node, *yaml.Node]
- func PathItems(root *yaml.Node) iter.Seq[PathItem]
- func Pointer(root *yaml.Node, ref string) *yaml.Node
- func Ref(n *yaml.Node) string
- func RefName(ref string) string
- func Resolve(root, n *yaml.Node) *yaml.Node
- func Schemas(root *yaml.Node) iter.Seq[Schema]
- func StringAt(n *yaml.Node, key string) string
- func Strings(n *yaml.Node) []string
- func Text(n *yaml.Node) string
- func Types(schema *yaml.Node) []string
- func UnderNegation(path string) bool
- func Unwrap(n *yaml.Node) *yaml.Node
- func Version(root *yaml.Node) string
- func Walk(n *yaml.Node, path string) iter.Seq[Node]
- type MediaType
- type Node
- type Operation
- type Parameter
- type PathItem
- type Response
- type Schema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClientOrServerError ¶
IsClientOrServerError reports whether the status code is 4xx or 5xx.
func Join ¶
Join appends key to the JSONPath base, using dot notation for plain identifiers and bracket notation for everything else.
func Methods ¶
func Methods() []string
Methods lists the HTTP methods that can appear in a path item, in the order the OpenAPI specification declares them.
func NodeAt ¶ added in v1.1.0
NodeAt returns the node that marks the location of a JSONPath produced by Join and Index: the key node for a mapping entry and the item itself for a sequence index. It returns nil when the path does not lead anywhere in root.
func Operations ¶
Operations iterates over every operation declared under paths in root.
func Pointer ¶
Pointer resolves a local JSON pointer such as "#/components/schemas/Pet" against root. It returns nil when the pointer is not local or does not exist.
func RefName ¶
RefName returns the last segment of a $ref, which is the component name for references into #/components.
func Resolve ¶
Resolve follows local $ref chains starting at n and returns the final target. A reference that cannot be resolved, or one that is not local, returns n.
func Schemas ¶
Schemas iterates over every schema in root: component schemas, parameter and header schemas, request and response media type schemas, and all nested schemas below them. Each schema node is reported once.
The walk records only a cheap trail for every schema; the JSONPath strings are rendered afterwards. A node that was already reported is not entered again, which also terminates cyclic aliases.
func Types ¶
Types returns the declared types of a schema. In OpenAPI 3.1 the type keyword may be a list; in 3.0 it is a single string.
func UnderNegation ¶ added in v1.1.0
UnderNegation reports whether the JSONPath of a schema is below a not, if, then or else keyword. Such schemas are constraint fragments (for example "not: {anyOf: [{type: 'null'}]}"), not descriptions of the data.
func Unwrap ¶
Unwrap removes the document wrapper from n and returns the content node. It returns nil for a nil node.
Types ¶
type MediaType ¶
type MediaType struct {
// Name is the media type key, such as application/json.
Name string
// Node is the media type object.
Node *yaml.Node
// Path is the JSONPath of the media type object.
Path string
}
MediaType is one entry of a content map.
type Node ¶
type Node struct {
// Key is the mapping key (or "[i]" index) the node was found under.
Key string
// Node is the YAML node.
Node *yaml.Node
// Path is the JSONPath of the node.
Path string
}
Node is a node of the document with the JSONPath it was found at.
type Operation ¶
type Operation struct {
// Route is the path template, such as /pets/{petId}.
Route string
// Method is the lower-case HTTP method.
Method string
// PathItem is the path item that holds the operation, with $ref resolved.
PathItem *yaml.Node
// Node is the operation object.
Node *yaml.Node
// Path is the JSONPath of the operation.
Path string
}
Operation is one operation of the document together with its location.
type Parameter ¶
type Parameter struct {
// Node is the parameter object with $ref resolved.
Node *yaml.Node
// Path is the JSONPath of the parameter entry.
Path string
// Entry is the item as written in the parameters list, which is the $ref
// object when the parameter is a reference. Report findings on it, because
// Node is shared by every operation that references the same component.
Entry *yaml.Node
// Inherited is true when the parameter comes from the path item.
Inherited bool
}
Parameter is a resolved parameter with its location.
func OwnParameters ¶
OwnParameters returns only the parameters declared on the operation itself.
func Parameters ¶
Parameters returns the parameters of an operation. Parameters declared at the path item are included unless the operation overrides them by name and location, as the specification requires.
type PathItem ¶
type PathItem struct {
// Route is the path template.
Route string
// KeyNode is the key node of the route.
KeyNode *yaml.Node
// Node is the path item with $ref resolved.
Node *yaml.Node
// Path is the JSONPath of the path item.
Path string
}
PathItem is one entry of the paths object.
type Response ¶
type Response struct {
// Code is the status code key, such as 200, 4XX or default.
Code string
// Node is the response object with $ref resolved.
Node *yaml.Node
// Path is the JSONPath of the response entry.
Path string
}
Response is one response of an operation.
type Schema ¶
type Schema struct {
// Node is the schema object. It is not $ref-resolved: a reference is
// reported as the node holding the $ref keyword.
Node *yaml.Node
// Path is the JSONPath of the schema.
Path string
// Component is the components.schemas key when the schema is a top-level
// component, and empty otherwise.
Component string
}
Schema is one schema object found while walking the document.