discover

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 14 Imported by: ? 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 discover finds the OpenAPI descriptions an API publishes, from an HTTPS URL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(reader io.Reader) ([]byte, error)

Read reads one document, refusing more than 32 MiB.

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

func Offers(ctx context.Context, transport http.RoundTripper, target Target) []Offer

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.

func Get

func Get(ctx context.Context, transport http.RoundTripper, target Target) ([]byte, Target, error)

Get reads the document at target in full, through Read, and returns it with the URL it was served from. It asks for the representation Offers judged.

func ParseTarget

func ParseTarget(raw string) (Target, error)

ParseTarget parses raw as a Target.

func (Target) String

func (t Target) String() string

func (Target) URL

func (t Target) URL() *url.URL

URL returns a copy of the target's URL.

Jump to

Keyboard shortcuts

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