Documentation
¶
Overview ¶
Package discover finds the OpenAPI descriptions an API publishes, from an HTTPS URL.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Offer ¶
type Offer struct {
URL Target // where the description is, after redirects
Title string // the title of the link to it, when it has one
API *url.URL // the context of the link to it, the API it describes; nil when it is the target itself
}
Offer is one OpenAPI description an API publishes.
func Offers ¶
Offers requests target and what it links to, and returns each OpenAPI description found, in the order found.
When target is itself a description, that is the only offer. Otherwise Offers follows, breadth first and in listed order, every service-desc (RFC 8631 §4.2), api-catalog (RFC 9727 §3) and item (RFC 9727 §3.1) link in the Link header of each response and in the body of each 200 response that is a Linkset (RFC 9264 §4.2), starting with target's own and then its host's well-known API catalog (RFC 9727 §2). A response that is a description is an offer; one that is not is searched for more links, so a catalog's api-catalog links nest catalogs (RFC 9727 §4.3). When nothing is found, it tries openapi.json, then openapi.yaml, under target, the entry document names OAS §4.3 recommends, and the first that is a description is the only offer.
A response is a description when its status is 200 and either its media type is an OpenAPI one (REST API Media Types §2.1) or its first 64 KiB start an OpenAPI Object with a 3.x version; no more of a response is read. Offers makes at most 8 requests, none of them twice. A failed request is skipped, so the offers are what was found before ctx ended.
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target is an HTTPS URL without credentials or a fragment. It is the only kind of URL discovery requests, so the rule is checked once, here.